#!/bin/bash version="0.3.0beta" projet="Kyodev" contact="https://framagit.org/kyodev/kyopages/issues" date="10/06/2017" script="getFirefox" ##### license LPRAB/WTFPL # auteurs: kyodev # contibuteurs: - ##### #### 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 echo -e "$YELLOW pour Debian, version $version - $date\n$COLOR" #### 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 } # user ayant démarré la session graphique; $userHome f_userHome(){ userHome=$(echo $XAUTHORITY | sed -E 's/(.*)\.Xauthority/\1/') } #### 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 } # 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' ---------------------------------------------------------------------- ./getFirefox : installation du script dans le système 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 EOF printf $COLOR; cat << 'EOF' ---------------------------------------------------------------------- Ce script doit être exécuté avec les droits ROOT. FERMER et DESINSTALLER un Firefox existant avant d'installer un nouveau canal Il désinstallera le paquet Debian firefox-esr si présent. Ce script devrait fonctionner sur Ubuntu. ---------------------------------------------------------------------- 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 rm "$0" &>/dev/null 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" } # sauvegarde profil f_sauveProfil(){ f_userHome cp -a "$userHome".mozilla/firefox/ "$userHome".mozilla/"$(date -u +%Y%m%d-%H%M%S)"/ } # install firefox f_install(){ 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 printf $RED; f_godzilla; printf $COLOR # on vire 'firefox-esr' si installé if [ "$( dpkg-query -l firefox-esr &>/dev/null | grep -Eo ^ii)" == "ii" ]; then apt-get remove firefox-esr; fi 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" 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 # dossier temporaire de travail, création $dirTemp dirTemp="/tmp/$script/" mkdir -p "$dirTemp" # chargement f_info "téléchargement..." wget -c --user-agent="$user_agent" -O "$dirTemp$file" "$url" # 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...." #sauvegarde du profil f_sauveProfil # 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 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 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 # # alternatives # update-alternatives --quiet --install /usr/bin/firefox-"$product" x-www-browser /opt/firefox-"$product"/firefox 100 # 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 #ménage rm -rf "$dirTemp" # the end f_info "$GREEN""Firefox-$product est installé.\n" if [ $product == "nightly" ]; then f_info "pour savoir comment participer au développement: https://nightly.mozfr.org/participer/"; fi } # désinstallation de firefox f_remove(){ 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" } #### traitements arguments ============================================= 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" else cmd="help" fi #### installation du script si pas dans le système ===================== if ! f_scriptBin ; then f_sysinstall; fi #### désinstallation du script ========================================= if [ "$cmd" == "sysremove" ]; then f_sysremove; fi #### help ============================================================== if [ "$cmd" == "help" ]; then f_help; fi #### version en ligne ================================================== if [ "$cmd" == "version" ]; then f_versionFF; fi #### installation ====================================================== if [ "$cmd" == "install" ]; then f_install; fi #### désinstallation =================================================== if [ "$cmd" == "remove" ]; then f_remove; fi exit 0