From 412cb93146286379ff27995df3ebf8d5bf827f62 Mon Sep 17 00:00:00 2001 From: kyodev Date: Wed, 19 Jul 2017 23:55:15 +0200 Subject: [PATCH] 0.5.0 --- scripts/getFirefox | 222 ++++++++++++++++++-------------- scripts/getFirefox_changelog.md | 18 ++- 2 files changed, 143 insertions(+), 97 deletions(-) diff --git a/scripts/getFirefox b/scripts/getFirefox index 3825961..b507bba 100755 --- a/scripts/getFirefox +++ b/scripts/getFirefox @@ -1,9 +1,9 @@ #!/bin/bash -version=0.4.2 -date="18/07/2017" +version=0.5.0 +date="19/07/2017" projet="Kyodev" -contact="https://framagit.org/kyodev/kyopages/issues" +contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues" script="getFirefox" urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/getFirefox" urlNotice="https://kyodev.frama.io/kyopages/scripts/getFirefox/" @@ -26,7 +26,7 @@ YELLOW=`printf "\033[0;33m"` # ? #### entete ============================================================ clear -echo "$BLUE" +printf "$BLUE" cat << 'EOF' _ _____ _ __ __ _ ___| |_| ___(_)_ __ ___ / _| _____ __ @@ -60,7 +60,7 @@ f__architecture(){ esac } - # user ayant initié la session graphique, assigne $user_, testé avec mate, gnome + # user ayant initié la session graphique, assigne $user_ # sortie script sur erreur, gestion variable environnement pour personnaliser l'user avec: # USER_INSTALL=user script f__user(){ @@ -103,7 +103,6 @@ f__testArchive(){ file -b "$1" | grep 'bzip2 compressed data' &>/dev/null && archive_detect="bzip2" || return 1 } - # sortie sur erreur, log $1 si upgrade f__error() { #affichage $1 en rouge, $1++ optionnels en bleu, sortie du script, log $1 si upgrade echo -e "\n$RED Erreur critique: $1 $COLOR" @@ -125,6 +124,7 @@ f__root(){ if [ $EUID -eq 0 ]; then return 0; else return 1; fi } + #### fonctions script ================================================== # install du script dans le système @@ -239,53 +239,61 @@ cat << 'EOF' ---------------------------------------------------------------------- ./getFirefox : installation du script dans le système - getFirefox +latest : installation Firefox Release - getFirefox +aurora : installation de Firefox Developer Edition + getFirefox +latest : installation de Firefox Release + getFirefox +beta : installation de Firefox Beta getFirefox +nightly : installation de Firefox Nightly getFirefox +esr : installation de Firefox ESR ---- - getFirefox -latest : désinstallation Firefox Release - getFirefox -aurora : désinstallation Firefox Developer Edition + getFirefox -latest : désinstallation Firefox Release + getFirefox -beta : désinstallation Firefox Beta getFirefox -nightly : désinstallation Firefox Nightly getFirefox -esr : désinstallation Firefox ESR ---- getFirefox version : version en ligne Firefox Release & ESR getFirefox upgrade : mise à jour forcée du script ---- - getFirefox sysremove : désinstallation du script du système + getFirefox sysremove: désinstallation du script du système EOF printf "$COLOR" cat << 'EOF' ---------------------------------------------------------------------- Ce script doit être exécuté avec les droits ROOT pour les installations et les désinstallations. - FERMER et DESINSTALLER un Firefox existant avant d'installer un - nouveau canal Il désinstallera le *paquet Debian* firefox-esr si présent. ---------------------------------------------------------------------- EOF } - # sauvegarde profil -ffx_sauveProfil(){ - cp -a "/home/$user_".mozilla/firefox/ "/home/$user_".mozilla/"$(date -u +%Y%m%d-%H%M%S)"/ -#revoir en fonction des canaux installés - + # version Firefox en ligne, $verLatest, $verEsr, $versionInstall, $urlOnline, si $1="quiet", pas d'affichage version en ligne +ffx_versionFF(){ + urlOnline="https://www.mozilla.org/en-US/firefox/notes/" + stockUrlOnline="$(wget -q --tries=2 --timeout=15 --user-agent=$user_agent -O - $urlOnline)" + verLatest="$(echo $stockUrlOnline | grep -Eo 'data-latest-firefox="[0-9\.]+"' | grep -Eo '[0-9\.]+')" + verEsr="$(echo $stockUrlOnline | grep -Eo 'data-esr-versions="[0-9\.]+"' | grep -Eo '[0-9\.]+')" + for product in latest esr beta nightly; do + if [ -x "$dirInstall$product/firefox" ]; then + versionInstall+="\n $product: $($dirInstall$product/firefox -v | grep -Eo '[0-9].*')" + fi + done + f__info "Firefox installé(s): $versionInstall" + f__info "Version Firefox en ligne:\n Release: $verLatest\n ESR: $verEsr" } - # création lanceur -ffx_lanceur(){ + # création lanceur.desktop +ffx_lanceur_desktop(){ 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 +echo "Name=Firefox $product" >> /usr/share/applications/firefox-"$product".desktop +echo "Name[fr]=Firefox $product" >> /usr/share/applications/firefox-"$product".desktop +echo "X-GNOME-FullName=Firefox-$product Web Browser" >> /usr/share/applications/firefox-"$product".desktop +echo "X-GNOME-FullName[fr]=Firefox-$product Navigateur Web" >> /usr/share/applications/firefox-"$product".desktop +echo "StartupWMClass=Firefox-$product" >> /usr/share/applications/firefox-"$product".desktop +echo "Exec=/usr/bin/firefox-$product %u" >> /usr/share/applications/firefox-"$product".desktop +echo "Icon=$dirInstall$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 @@ -300,83 +308,97 @@ StartupNotify=true EOF } - # version Firefox en ligne, $verLatest, $verEsr, $versionInstall, $urlOnline, si $1="quiet", pas d'affichage version en ligne -ffx_versionFF(){ - urlOnline="https://www.mozilla.org/en-US/firefox/notes/" - stockUrlOnline="$(wget -q --tries=2 --timeout=15 --user-agent=$user_agent -O - $urlOnline)" - verLatest="$(echo $stockUrlOnline | grep -Eo 'data-latest-firefox="[0-9\.]+"' | grep -Eo '[0-9\.]+')" - verEsr="$(echo $stockUrlOnline | grep -Eo 'data-esr-versions="[0-9\.]+"' | grep -Eo '[0-9\.]+')" - versionInstall="-" - if [ -x /opt/firefox-latest/firefox ]; then versionInstall+="\n Release: $(/opt/firefox-latest/firefox -v | grep -Eo '[0-9].*')"; fi - if [ -x /opt/firefox-esr/firefox ]; then versionInstall+="\n ESR: $(/opt/firefox-esr/firefox -v | grep -Eo '[0-9].*')"; fi - if [ -x /opt/firefox-aurora/firefox ]; then versionInstall+="\n Aurora: $(/opt/firefox-aurora/firefox -v | grep -Eo '[0-9].*')"; fi - if [ -x /opt/firefox-nightly/firefox ]; then versionInstall+="\n Nightly: $(/opt/firefox-nightly/firefox -v | grep -Eo '[0-9].*')"; fi - if [ "$1" != "quiet" ]; then f__info "Firefox installé(s): $versionInstall"; fi - if [ "$1" != "quiet" ]; then f__info "Version Firefox en ligne:\n Release: $verLatest\n ESR: $verEsr"; fi + # sauvegarde profil, uniquement si profil default et latest ou esr +ffx_profileCopy(){ + if [ "$product" != "latest" ] && [ "$product" != "esr" ]; then return 0; fi + profilDefault="$(grep -r '\.default' /home/$user_/.mozilla/firefox/profiles.ini | sed 's/Path=//')" + if [ $profilDefault ] && [ ! -d "/home/$user_/.mozilla/firefox/latest" ] || [ ! -d "/home/$user_/.mozilla/firefox/esr" ]; then + cp -R "/home/$user_/.mozilla/firefox/$profilDefault"/* "/home/$user_/.mozilla/firefox/$product/" + fi } - # install firefox, $1 canal à installer -ffx_install(){ -# f__root || f__error "vous devez être ROOT pour installer Firefox" - ffx_godzilla -f__info "installation Firefox-$product" -#ffx_versionFF "quiet" - f__architecture + # traitement de profile.ini +ffx_profileIni(){ + fileProfil="/home/$user_/.mozilla/firefox/profiles.ini" + #si profil existant, sortir + if [ "$(grep -rc 'Name=$product' $fileProfil)" != 0 ]; then return; fi + #comptage profils existants + nbProfiles="$(grep -rEc '\[Profile[0-9]+\]' $fileProfil)" + #création profil + echo "" >> "$fileProfil" + echo "[Profile$nbProfiles]" >> "$fileProfil" + echo "Name=$product" >> "$fileProfil" + echo "IsRelative=1" >> "$fileProfil" + echo "Path=$product" >> "$fileProfil" + #si existant et latest, supprimer Default=1 et attribuer à latest, dans profile.ini + if [ "$product" == "latest" ] || [ "$product" == "esr" ]; then + sed -i 's/Default=1//' "$fileProfil" + echo "Default=1" >> "$fileProfil" + else echo "" >> "$fileProfil"; fi +return +} - # calcul $file, $recup_url, affichage version pendant l'install - file="firefox-$product.$architecture.tar.bz2" - if [ "$product" == "latest" ]; then recup_url="https://download.mozilla.org/?product=firefox-$product&os=$architecture&lang=fr" - elif [ "$product" == "esr" ]; then recup_url="https://download.mozilla.org/?product=firefox-$product-latest&os=$architecture&lang=fr" - else recup_url="https://download.mozilla.org/?product=firefox-$product-latest-l10n-ssl&os=linux&lang=fr" ;fi + # calcul url téléchargement, assigne $recup_url +ffx_recup_url(){ + if [ "$product" == "latest" ]; then + recup_url="https://download.mozilla.org/?product=firefox-$product&os=$architecture&lang=fr" + elif [ "$product" == "esr" ]; then + recup_url="https://download.mozilla.org/?product=firefox-$product-latest&os=$architecture&lang=fr" + elif [ "$product" == "beta" ]; then + recup_url="https://download.mozilla.org/?product=firefox-beta-latest&os=$architecture&lang=fr" + elif [ "$product" == "nightly" ]; then + recup_url="https://download.mozilla.org/?product=firefox-$product-latest-l10n-ssl&os=linux&lang=fr" ;fi +} + + # install firefox +ffx_install(){ + f__root || f__error "vous devez être ROOT pour installer Firefox" + ffx_godzilla + f__info "installation Firefox-$product" # dossier temporaire de travail, création $dirTemp -# dirTemp="/tmp/$script-$RANDOM/" -dirTemp="/tmp/getFirefox-12201/" + dirTemp="/tmp/$script-$RANDOM/" mkdir -p "$dirTemp" - # chargement f__info "téléchargement..." -# wget -q -c --show-progress --tries=2 --timeout=15 --user-agent="$user_agent" -O "$dirTemp$file" "$recup_url" -# if [ "$?" != "0" ]; then f__testWget "$recup_url"; fi + file="firefox-$product.$architecture.tar.bz2" + ffx_recup_url + wget -q -c --show-progress --tries=2 --timeout=15 --user-agent="$user_agent" -O "$dirTemp$file" "$recup_url" + if [ "$?" != "0" ]; then f__testWget "$recup_url"; fi f__testArchive "$dirTemp$file" || f__error "Le fichier $dirTemp$file n'est pas une archive tar.gz valide" - # décompression archive - f__info "décompression...." + f__info "décompression..." tar -xaf "$dirTemp$file" -C "$dirTemp" - f__info "installation...." -exit - - # 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"/ - #ménage + f__info "installation..." + # on déplace le répertoire firefox dans le répertoire installation + rm -rf "$dirInstall$product"/ # effacement éventuel répertoire existant: "vraie" install + mkdir -p "$dirInstall$product"/ + mv -f "$dirTemp"firefox/* "$dirInstall$product"/ + chown -R "$user_": "$dirInstall$product"/ + chmod -R g+wrs,a+r "$dirInstall$product"/ rm -rf "$dirTemp" + mkdir -p "/home/$user_/.mozilla/firefox/$product" + ffx_profileCopy + chown -R "$user_": "/home/$user_/.mozilla/firefox/$product/" + chmod g-rx,o-rx "/home/$user_/.mozilla/firefox/$product/" + ffx_profileIni + ffx_lanceur_desktop + # lanceur dans /usr/bin + echo "#!/bin/sh" >> /usr/bin/firefox-"$product" + echo "exec $dirInstall$product/firefox -P $product" "$@" >> /usr/bin/firefox-"$product" + chmod a+x /usr/bin/firefox-"$product" - #sauvegarde du profil - ffx_sauveProfil -# préparer profile.ini -#ffx_profile - # install lanceur - ffx_lanceur + ln -sf "$dirInstall$product"/browser/chrome/icons/default/default48.png /usr/share/pixmaps/firefox-"$product".png - # lien pixmap - ln -sf /opt/firefox-"$product"/browser/chrome/icons/default/default48.png /usr/share/pixmaps/firefox-"$product".png + # lien dans /usr/bin pour latest en tant que firefox + if [ "$product" == "latest" ]; then ln -sf "/usr/bin/firefox-latest" "/usr/bin/firefox" + elif [ "$product" == "esr" ]; then ln -sf "/usr/bin/firefox-esr" "/usr/bin/firefox"; fi # # alternatives, trop intrusif pour plusieurs versions simultanées? -# update-alternatives --quiet --install /usr/bin/firefox-"$product" x-www-browser /opt/firefox-"$product"/firefox 100 - -#grep -Ec '\[Profile' ~/.mozilla/firefox/profiles.ini -> 2 -#firefox -P nightly - - # 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 - - # the end - f__info "$GREEN Firefox-$product installé." - if [ $product == "nightly" ]; then f__info "pour savoir comment participer au développement:\nhttps://nightly.mozfr.org/participer/"; fi +# update-alternatives --quiet --install /usr/bin/firefox-"$product" x-www-browser "$dirInstall$product"/firefox 100 + f__info "$GREEN""Firefox-$product installé." } # désinstallation de firefox @@ -387,12 +409,20 @@ ffx_remove(){ f__info "$GREEN" "Firefox-$product n'est pas installé." return 0 fi - # suppression du répertoire firefox en /opt - if [ -d "/opt/firefox-$product/" ]; then rm -rf "/opt/firefox-$product/"; fi - # suppression du lanceur + # suppression du répertoire firefox + if [ -d "$dirInstall$product/" ]; then rm -rf "$dirInstall$product/"; fi + if [ -d "/opt/firefox-$product" ]; then rm -rf "/opt/firefox-$product/"; fi # ancien répertoire éventuel + if [ -d "$dirInstall$product/" ]; then rm -rf "$dirInstall$product/"; fi + # suppression lanceurs rm -f /usr/share/applications/firefox-"$product".desktop - # suppression lien pixmap - unlink /usr/share/pixmaps/firefox-"$product".png &>/dev/null + rm -f /usr/bin/firefox-"$product" + + # suppression des liens + unlink "/usr/share/pixmaps/firefox-$product.png" &>/dev/null + if [ "$product" == "latest" ]; then unlink "/usr/bin/firefox" &>/dev/null + elif [ "$product" == "esr" ]; then unlink "/usr/bin/firefox" &>/dev/null; fi + unlink "/usr/bin/firefox-$product" &>/dev/null + # suppression alternatives si existantes if update-alternatives --display x-www-browser &>/dev/null; then update-alternatives --display x-www-browser | grep firefox-"$product" &>/dev/null && update-alternatives --quiet --remove x-www-browser /opt/firefox/firefox-"$product" @@ -407,12 +437,17 @@ ffx_remove(){ f__architecture || f__error "Architecture non supportée" f__user f__requis "wget" "logger" "file" "tar" +dirInstall="/opt/usr/share/firefox-" # installation du script si pas dans le système dirname "$0" | grep 'bin' &>/dev/null || fscript_install - + # détection droits inappropriés sur le script [ "$1" != "sysremove" ] && [ -e "/opt/bin/$script" ] && ls -l "/opt/bin/$script" | grep 'root' &>/dev/null && f__error "bug sécu 01" \ - "veuillez désinstaller le script et le réinstaller" "voir: $urlNotice#supprimer-le-script" + "veuillez désinstaller le script et le réinstaller" "voir: $urlNotice#messages-avertissement" + #detection ancien repertoire install +ls -ld /opt/firefox-* &>/dev/null && f__info "$RED""Ancien répertoire d'installation détecté" \ + "Il faudrait désinstaller et réinstaller pour être à jour" "version(s) détectée(s):" \ + "$(ls -ld /opt/firefox-* | sed -E 's/.*firefox-(.*)/ \1/')" case "$1" in "sysremove" ) @@ -425,11 +460,10 @@ case "$1" in opType="upgrade" fscript_version fscript_dl ;; # upgrade script si maj possible - +latest | +esr | +aurora | +nightly ) -f__error "script en cours de refonte, installations non permise aujourd'hui" + +latest | +esr | +beta | +nightly ) product="$(echo $1 | sed 's/+//')" ffx_install ;; # installation plugin - -latest | -esr | -aurora | -nightly ) + -latest | -esr | -beta | -nightly ) product="$(echo $1 | sed 's/-//')" ffx_remove ;; # désinstallation plugin "manuel" ) diff --git a/scripts/getFirefox_changelog.md b/scripts/getFirefox_changelog.md index 8d10d54..af735a2 100644 --- a/scripts/getFirefox_changelog.md +++ b/scripts/getFirefox_changelog.md @@ -2,15 +2,27 @@ ## todo -* install manuelle archive +* installation manuelle archive * téléchargement archive * version enligne autre que esr et release -* révision install +* plus d'architecture? (arm)? +* voir alternatives par ordre croissant, latest ou esr sinon beta sinon nightly +* récupérer icône aurora pour beta? +## 0.5.0 19/07/17 + +* copie du profil default pour utilisation par latest +* remplacement aurora par beta +* révision install +* changement répertoire installation /opt/usr/share/firefox- au lieu de /opt/firefox- + plus en accord avec fhs +* détection utilisation ancien répertoire +* script remove gère ancien ou nouveau répertoire +* détection et infor mauvais répertoire install ## 0.4.2 18/07/17 -* fix bug: product, version esr en ligne +* fix bug: version esr en ligne * révision traitement paramètres * révision traitement script * révision remove