kyopages/scripts/getFirefox

326 lines
12 KiB
Plaintext
Raw Normal View History

2017-06-10 01:16:49 +02:00
#!/bin/bash
2017-06-11 09:43:59 +02:00
version="0.3.0beta"
2017-06-10 10:58:34 +02:00
projet="Kyodev"
contact="https://framagit.org/kyodev/kyopages/issues"
2017-06-10 10:49:56 +02:00
date="10/06/2017"
2017-06-10 01:16:49 +02:00
script="getFirefox"
2017-06-11 09:43:59 +02:00
##### license LPRAB/WTFPL
2017-06-10 01:16:49 +02:00
# auteurs: kyodev
2017-06-10 10:58:34 +02:00
# contibuteurs: -
2017-06-10 01:16:49 +02:00
#####
#### définition couleurs -----------------------------------------------
YELLOW=`printf "\033[0;33m"` # ?
GREEN=`printf "\033[0;32m"` # ok
BLUE=`printf "\033[0;34m"` # info
COLOR=`printf "\033[0m"` # standard
RED=`printf "\033[0;31m"` # alerte
#### entete ============================================================
clear
echo "$BLUE"
cat << 'EOF'
_ _____ _ __
__ _ ___| |_| ___(_)_ __ ___ / _| _____ __
/ _' |/ _ \ __| |_ | | '__/ _ \ |_ / _ \ \/ /
| (_| | __/ |_| _| | | | | __/ _| (_) > <
\__, |\___|\__|_| |_|_| \___|_| \___/_/\_\
|___/
EOF
2017-06-11 09:43:59 +02:00
echo -e "$YELLOW pour Debian, version $version - $date\n$COLOR"
2017-06-10 01:16:49 +02:00
#### fonctions diverses ================================================
# sortie sur erreur
f_error() { # affichage paramètre 1 en rouge pour le premier, les suivants optionnels en bleu, sortie du script
echo -e "\n$RED Erreur critique: $1 $COLOR"
for (( i=2 ; i<=$# ; i++ )); do echo " $BLUE${!i}"; done
echo "$COLOR"
exit 1
}
# affichage information
f_info() { # tous les paramètres en ligne en couleur bleue, accepte \n, ligne vide à la fin
echo -e " $BLUE $@ $COLOR\n"
}
#debian? return 0 else 1
f_debian(){
if [ -f /etc/debian_version ]; then return 0; else return 1; fi
}
# root? return 0 else 1
f_root(){
if [ $EUID -eq 0 ]; then return 0; else return 1; fi
}
# script en /bin? return 0 si bin, 1 si local
f_scriptBin(){
# echo egrep: "-$(echo $0 | grep -Eo '\.\/')-"
if [ "$(echo $0 | grep -Eo '\.\/')" != "./" ]; then return 0; else return 1; fi
}
2017-06-11 09:43:59 +02:00
# user ayant démarré la session graphique; $userHome
f_userHome(){
userHome=$(echo $XAUTHORITY | sed -E 's/(.*)\.Xauthority/\1/')
}
2017-06-10 01:16:49 +02:00
#### fonctions script ==================================================
# version Firefox en ligne, $verLatest, $verEsr, $user_agent, $urlOnline, si $1="quiet", pas d'affichage
user_agent="Mozilla/5.0 (X11; Linux $architecture; rv:45.0) Gecko/ Firefox"
f_versionFF(){
urlOnline="https://www.mozilla.org/en-US/firefox/notes/"
verLatest=$(wget --no-check-certificate --tries=1 --timeout=15 --user-agent=$user_agent -nv -qO - $urlOnline | \
grep -Eo 'data-latest-firefox="[0-9\.]+"' | grep -Eo '[0-9\.]+')
verEsr=$(wget --no-check-certificate --tries=1 --timeout=15 --user-agent=$user_agent -nv -qO - $urlOnline | \
grep -Eo 'data-esr-versions="[0-9 \.]+"' | grep -Eo ' [0-9\.]+' | grep -Eo '[0-9\.]+')
if [ "$1" != "quiet" ]; then f_info "Version Firefox en ligne: $verLatest\n Version esr: $verEsr"; fi
}
2017-06-11 09:43:59 +02:00
2017-06-10 01:16:49 +02:00
# ascii art godzilla
f_godzilla(){
cat << 'EOF'
_.-~-.
7'' Q..\
_7 (_
_7 _/ _q. /
_7 . ___ /VVvv-'_ .
7/ / /~- \_\\ '-._ .-' / //
./ ( /-~-/||'=.__ '::. '-~'' { ___ / // ./{
V V-~-~| || __''_ ':::. ''~-~.___.-'' _/ // / {_ / { /
VV/-~-~-|/ \ .'__'. '. ':: _ _ _ ''.
/ /~~~~||VVV/ / \ ) \ _ __ ___ ___ ___(_) | | __ _ .::'
/ (~-~-~\\.-' / \' \::::. | '_ ' _ \ / _ \_ / | | |/ _' | :::'
/..\ /..\__/ ' '::: | | | | | | (_) / /| | | | (_| | ::'
vVVv vVVv ': |_| |_| |_|\___/___|_|_|_|\__,_| ''
EOF
}
# affichage help
f_help(){
printf $BLUE
cat << 'EOF'
2017-06-11 09:43:59 +02:00
----------------------------------------------------------------------
2017-06-10 01:16:49 +02:00
./getFirefox : installation du script dans le système
2017-06-11 09:43:59 +02:00
getFirefox +latest : installation Firefox Release
getFirefox -latest : désinstallation Firefox Release
getFirefox version : version en ligne Firefox Release & ESR
----
getFirefox +aurora : installation de Firefox Developer Edition
getFirefox -aurora : désinstallation Firefox Developer Edition
getFirefox +nightly : installation de Firefox Nightly
getFirefox -nightly : désinstallation Firefox Nightly
getFirefox +esr : installation de Firefox ESR
getFirefox -esr : désinstallation Firefox ESR
----
getFirefox sysremove : désinstallation du script du système
2017-06-10 01:16:49 +02:00
EOF
2017-06-11 09:43:59 +02:00
printf $COLOR; cat << 'EOF'
----------------------------------------------------------------------
2017-06-10 01:16:49 +02:00
Ce script doit être exécuté avec les droits ROOT.
2017-06-11 09:43:59 +02:00
FERMER et DESINSTALLER un Firefox existant avant d'installer un
nouveau canal
Il désinstallera le paquet Debian firefox-esr si présent.
2017-06-10 01:16:49 +02:00
Ce script devrait fonctionner sur Ubuntu.
2017-06-11 09:43:59 +02:00
----------------------------------------------------------------------
2017-06-10 01:16:49 +02:00
EOF
printf $COLOR
}
# install du script dans le système
f_sysinstall(){
if ! f_root ; then f_error "vous devez être ROOT pour installer ce script dans le système"; fi
# installation dans /opt
mkdir -p /opt/bin/
cp -d "$0" /opt/bin/
ln -s /opt/bin/$script /usr/local/bin/$script &>/dev/null
2017-06-10 10:58:34 +02:00
rm "$0" &>/dev/null
2017-06-10 01:16:49 +02:00
f_info "$GREEN$script est installé dans le système.\n$BLUE appel du script par$GREEN $script$BLUE (sans ./)"
exit 0
}
# suppression du script dans le système
f_sysremove(){
if ! f_root ; then f_error "vous devez être ROOT pour supprimer ce script dans le système"; fi
# suppression de /opt
rm /opt/bin/"$script" &>/dev/null
unlink /usr/local/bin/"$script" &>/dev/null
f_info "$GREEN$script est supprimé du système.\n"
}
2017-06-11 09:43:59 +02:00
# sauvegarde profil
f_sauveProfil(){
f_userHome
cp -a "$userHome".mozilla/firefox/ "$userHome".mozilla/"$(date -u +%Y%m%d-%H%M%S)"/
}
2017-06-10 01:16:49 +02:00
# install firefox
f_install(){
2017-06-10 10:49:56 +02:00
2017-06-10 01:16:49 +02:00
if ! f_root ; then f_error "vous devez être ROOT pour installer Firefox en tant que ROOT"; fi
# debian? sinon dehors / utile? /
if ! f_debian ; then f_error "désolé, vous n'utilisez pas Debian :( adieu o/"; fi
2017-06-11 09:43:59 +02:00
printf $RED; f_godzilla; printf $COLOR
2017-06-10 01:16:49 +02:00
# on vire 'firefox-esr' si installé
2017-06-10 10:49:56 +02:00
if [ "$( dpkg-query -l firefox-esr &>/dev/null | grep -Eo ^ii)" == "ii" ]; then apt-get remove firefox-esr; fi
2017-06-10 01:16:49 +02:00
f_versionFF "quiet"
# architecture > $architecture (version release)
if [ "$(dpkg --print-architecture)" = "amd64" ]; then architecture='linux64'; else architecture='linux'; fi
# calcul $file, $url, affichage version pendant l'install
file="firefox-$product.$architecture.tar.bz2"
2017-06-11 09:43:59 +02:00
if [ "$product" == "latest" ]; then
f_info "installation Firefox-$product, version $verLatest"
url="https://download.mozilla.org/?product=firefox-$product&os=$architecture&lang=fr"
elif [ "$product" == "esr" ]; then
f_info "installation Firefox-$product, version $verEsr"
url="https://download.mozilla.org/?product=firefox-$product-latest&os=$architecture&lang=fr"
else
f_info "installation Firefox-$product"
url="https://download.mozilla.org/?product=firefox-$product-latest-l10n-ssl&os=linux&lang=fr"
fi
2017-06-10 01:16:49 +02:00
# dossier temporaire de travail, création $dirTemp
dirTemp="/tmp/$script/"
mkdir -p "$dirTemp"
# chargement
f_info "téléchargement..."
2017-06-10 10:49:56 +02:00
wget -c --user-agent="$user_agent" -O "$dirTemp$file" "$url"
2017-06-10 01:16:49 +02:00
# gestion erreur wget / à peaufiner? /
if [ "$?" != "0" ]; then
f_error "problème au chargement, connexion défaillante?" \
"Si persistance, merci de prévenir $projet" \
"$contact"
fi
# décompression archive
f_info "décompression...."
tar -xaf "$dirTemp$file" -C "$dirTemp"
f_info "installation...."
2017-06-10 10:49:56 +02:00
2017-06-11 09:43:59 +02:00
#sauvegarde du profil
f_sauveProfil
2017-06-10 01:16:49 +02:00
# install lanceur
f_lanceur(){
rm -f /usr/share/applications/firefox-"$product".desktop
cat << "EOF" >> /usr/share/applications/firefox-"$product".desktop
#!/usr/bin/env xdg-open
[Desktop Entry]
EOF
2017-06-10 10:49:56 +02:00
echo -e "Name=Firefox $product\nName[fr]=Firefox $product" >> /usr/share/applications/firefox-"$product".desktop
echo -e "X-GNOME-FullName=Firefox-$product Web Browser\nX-GNOME-FullName[fr]=Firefox-$product Navigateur Web" >> /usr/share/applications/firefox-"$product".desktop
echo -e "StartupWMClass=Firefox-$product" >> /usr/share/applications/firefox-"$product".desktop
echo -e "Exec=/opt/firefox-$product/firefox %u" >> /usr/share/applications/firefox-"$product".desktop
echo -e "Icon=/opt/firefox-$product/browser/icons/mozicon128.png" >> /usr/share/applications/firefox-"$product".desktop
cat << "EOF" >> /usr/share/applications/firefox-"$product".desktop
2017-06-10 01:16:49 +02:00
Comment=Browse the World Wide Web
Comment[fr]=Naviguer sur Internet
GenericName=Web Browser
GenericName[fr]=Navigateur Web
Terminal=false
X-MultipleArgs=false
Type=Application
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;
StartupNotify=true
EOF
}
f_lanceur
# on déplace le répertoire firefox en /opt
rm -rf /opt/firefox-"$product"/
mkdir -p /opt/firefox-"$product"/
mv -f "$dirTemp"firefox/* /opt/firefox-"$product"/
# lien pixmap
ln -sf /opt/firefox-"$product"/browser/chrome/icons/default/default48.png /usr/share/pixmaps/firefox-"$product".png
2017-06-11 09:43:59 +02:00
# # alternatives
# update-alternatives --quiet --install /usr/bin/firefox-"$product" x-www-browser /opt/firefox-"$product"/firefox 100
2017-06-10 01:16:49 +02:00
2017-06-11 09:43:59 +02:00
# test sans alternatives, et avec liens dans /usr/bin pour latest en tant que firefox
if [ "$product" == "latest" ]; then ln -sf /opt/firefox-"$product"/firefox /usr/bin/firefox; fi
2017-06-10 01:16:49 +02:00
#ménage
rm -rf "$dirTemp"
# the end
f_info "$GREEN""Firefox-$product est installé.\n"
2017-06-11 09:43:59 +02:00
if [ $product == "nightly" ]; then f_info "pour savoir comment participer au développement: https://nightly.mozfr.org/participer/"; fi
2017-06-10 01:16:49 +02:00
}
2017-06-11 09:43:59 +02:00
# désinstallation de firefox
2017-06-10 01:16:49 +02:00
f_remove(){
2017-06-10 10:49:56 +02:00
if ! f_root ; then f_error "vous devez être ROOT pour désinstaller"; fi
# on supprime le répertoire firefox en /opt
rm -rf /opt/firefox-"$product"/
# on supprime le lanceur
rm -f /usr/share/applications/firefox-"$product".desktop
# lien pixmap
unlink /usr/share/pixmaps/firefox-"$product".png &>/dev/null
# alternatives
update-alternatives --quiet --remove x-www-browser /opt/firefox/firefox-"$product"
# the end
f_info "$GREEN""Firefox-$product est désinstallé.\n"
2017-06-10 01:16:49 +02:00
}
#### traitements arguments =============================================
2017-06-11 09:43:59 +02:00
if [ "$#" -gt 1 ]; then cmd="help" && f_info "$RED trop d'arguments"
elif [ "$1" == "version" ]; then cmd="version"
elif [ "$1" == "+latest" ]; then cmd="install"; product='latest'
elif [ "$1" == "-latest" ]; then cmd="remove"; product='latest'
elif [ "$1" == "+esr" ]; then cmd="install"; product='esr'
elif [ "$1" == "-esr" ]; then cmd="remove"; product='esr'
elif [ "$1" == "+aurora" ]; then cmd="install"; product='aurora'
elif [ "$1" == "-aurora" ]; then cmd="remove"; product='aurora'
elif [ "$1" == "+nightly" ]; then cmd="install"; product='nightly'
elif [ "$1" == "-nightly" ]; then cmd="remove"; product='nightly'
elif [ "$1" == "sysremove" ]; then cmd="sysremove"
2017-06-10 01:16:49 +02:00
else cmd="help"
fi
2017-06-11 09:43:59 +02:00
#### installation du script si pas dans le système =====================
2017-06-10 10:58:34 +02:00
if ! f_scriptBin ; then f_sysinstall; fi
2017-06-10 01:16:49 +02:00
2017-06-11 09:43:59 +02:00
#### désinstallation du script =========================================
if [ "$cmd" == "sysremove" ]; then f_sysremove; fi
2017-06-10 01:16:49 +02:00
#### help ==============================================================
if [ "$cmd" == "help" ]; then f_help; fi
2017-06-11 09:43:59 +02:00
#### version en ligne ==================================================
2017-06-10 01:16:49 +02:00
if [ "$cmd" == "version" ]; then f_versionFF; fi
#### installation ======================================================
if [ "$cmd" == "install" ]; then f_install; fi
2017-06-11 09:43:59 +02:00
#### désinstallation ===================================================
if [ "$cmd" == "remove" ]; then f_remove; fi
2017-06-10 01:16:49 +02:00
exit 0