This commit is contained in:
kyodev 2017-07-19 23:55:15 +02:00
parent 252eb6d82c
commit 412cb93146
2 changed files with 143 additions and 97 deletions

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
version=0.4.2 version=0.5.0
date="18/07/2017" date="19/07/2017"
projet="Kyodev" projet="Kyodev"
contact="https://framagit.org/kyodev/kyopages/issues" contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues"
script="getFirefox" script="getFirefox"
urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/getFirefox" urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/getFirefox"
urlNotice="https://kyodev.frama.io/kyopages/scripts/getFirefox/" urlNotice="https://kyodev.frama.io/kyopages/scripts/getFirefox/"
@ -26,7 +26,7 @@ YELLOW=`printf "\033[0;33m"` # ?
#### entete ============================================================ #### entete ============================================================
clear clear
echo "$BLUE" printf "$BLUE"
cat << 'EOF' cat << 'EOF'
_ _____ _ __ _ _____ _ __
__ _ ___| |_| ___(_)_ __ ___ / _| _____ __ __ _ ___| |_| ___(_)_ __ ___ / _| _____ __
@ -60,7 +60,7 @@ f__architecture(){
esac 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: # sortie script sur erreur, gestion variable environnement pour personnaliser l'user avec:
# USER_INSTALL=user script # USER_INSTALL=user script
f__user(){ f__user(){
@ -103,7 +103,6 @@ f__testArchive(){
file -b "$1" | grep 'bzip2 compressed data' &>/dev/null && archive_detect="bzip2" || return 1 file -b "$1" | grep 'bzip2 compressed data' &>/dev/null && archive_detect="bzip2" || return 1
} }
# sortie sur erreur, log $1 si upgrade # sortie sur erreur, log $1 si upgrade
f__error() { #affichage $1 en rouge, $1++ optionnels en bleu, sortie du script, 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" 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 if [ $EUID -eq 0 ]; then return 0; else return 1; fi
} }
#### fonctions script ================================================== #### fonctions script ==================================================
# install du script dans le système # install du script dans le système
@ -239,53 +239,61 @@ cat << 'EOF'
---------------------------------------------------------------------- ----------------------------------------------------------------------
./getFirefox : installation du script dans le système ./getFirefox : installation du script dans le système
getFirefox +latest : installation Firefox Release getFirefox +latest : installation de Firefox Release
getFirefox +aurora : installation de Firefox Developer Edition getFirefox +beta : installation de Firefox Beta
getFirefox +nightly : installation de Firefox Nightly getFirefox +nightly : installation de Firefox Nightly
getFirefox +esr : installation de Firefox ESR getFirefox +esr : installation de Firefox ESR
---- ----
getFirefox -latest : désinstallation Firefox Release getFirefox -latest : désinstallation Firefox Release
getFirefox -aurora : désinstallation Firefox Developer Edition getFirefox -beta : désinstallation Firefox Beta
getFirefox -nightly : désinstallation Firefox Nightly getFirefox -nightly : désinstallation Firefox Nightly
getFirefox -esr : désinstallation Firefox ESR getFirefox -esr : désinstallation Firefox ESR
---- ----
getFirefox version : version en ligne Firefox Release & ESR getFirefox version : version en ligne Firefox Release & ESR
getFirefox upgrade : mise à jour forcée du script 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 EOF
printf "$COLOR" printf "$COLOR"
cat << 'EOF' cat << 'EOF'
---------------------------------------------------------------------- ----------------------------------------------------------------------
Ce script doit être exécuté avec les droits ROOT pour Ce script doit être exécuté avec les droits ROOT pour
les installations et les désinstallations. 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. Il désinstallera le *paquet Debian* firefox-esr si présent.
---------------------------------------------------------------------- ----------------------------------------------------------------------
EOF EOF
} }
# sauvegarde profil # version Firefox en ligne, $verLatest, $verEsr, $versionInstall, $urlOnline, si $1="quiet", pas d'affichage version en ligne
ffx_sauveProfil(){ ffx_versionFF(){
cp -a "/home/$user_".mozilla/firefox/ "/home/$user_".mozilla/"$(date -u +%Y%m%d-%H%M%S)"/ urlOnline="https://www.mozilla.org/en-US/firefox/notes/"
#revoir en fonction des canaux installés 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 # création lanceur.desktop
ffx_lanceur(){ ffx_lanceur_desktop(){
rm -f /usr/share/applications/firefox-"$product".desktop rm -f /usr/share/applications/firefox-"$product".desktop
cat << "EOF" >> /usr/share/applications/firefox-"$product".desktop cat << "EOF" >> /usr/share/applications/firefox-"$product".desktop
#!/usr/bin/env xdg-open #!/usr/bin/env xdg-open
[Desktop Entry] [Desktop Entry]
EOF EOF
echo -e "Name=Firefox $product\nName[fr]=Firefox $product" >> /usr/share/applications/firefox-"$product".desktop echo "Name=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 "Name[fr]=Firefox $product" >> /usr/share/applications/firefox-"$product".desktop
echo -e "StartupWMClass=Firefox-$product" >> /usr/share/applications/firefox-"$product".desktop echo "X-GNOME-FullName=Firefox-$product Web Browser" >> /usr/share/applications/firefox-"$product".desktop
echo -e "Exec=/opt/firefox-$product/firefox %u" >> /usr/share/applications/firefox-"$product".desktop echo "X-GNOME-FullName[fr]=Firefox-$product Navigateur Web" >> /usr/share/applications/firefox-"$product".desktop
echo -e "Icon=/opt/firefox-$product/browser/icons/mozicon128.png" >> /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 cat << "EOF" >> /usr/share/applications/firefox-"$product".desktop
Comment=Browse the World Wide Web Comment=Browse the World Wide Web
Comment[fr]=Naviguer sur Internet Comment[fr]=Naviguer sur Internet
@ -300,83 +308,97 @@ StartupNotify=true
EOF EOF
} }
# version Firefox en ligne, $verLatest, $verEsr, $versionInstall, $urlOnline, si $1="quiet", pas d'affichage version en ligne # sauvegarde profil, uniquement si profil default et latest ou esr
ffx_versionFF(){ ffx_profileCopy(){
urlOnline="https://www.mozilla.org/en-US/firefox/notes/" if [ "$product" != "latest" ] && [ "$product" != "esr" ]; then return 0; fi
stockUrlOnline="$(wget -q --tries=2 --timeout=15 --user-agent=$user_agent -O - $urlOnline)" profilDefault="$(grep -r '\.default' /home/$user_/.mozilla/firefox/profiles.ini | sed 's/Path=//')"
verLatest="$(echo $stockUrlOnline | grep -Eo 'data-latest-firefox="[0-9\.]+"' | grep -Eo '[0-9\.]+')" if [ $profilDefault ] && [ ! -d "/home/$user_/.mozilla/firefox/latest" ] || [ ! -d "/home/$user_/.mozilla/firefox/esr" ]; then
verEsr="$(echo $stockUrlOnline | grep -Eo 'data-esr-versions="[0-9\.]+"' | grep -Eo '[0-9\.]+')" cp -R "/home/$user_/.mozilla/firefox/$profilDefault"/* "/home/$user_/.mozilla/firefox/$product/"
versionInstall="-" fi
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
} }
# install firefox, $1 canal à installer # traitement de profile.ini
ffx_install(){ ffx_profileIni(){
# f__root || f__error "vous devez être ROOT pour installer Firefox" fileProfil="/home/$user_/.mozilla/firefox/profiles.ini"
ffx_godzilla #si profil existant, sortir
f__info "installation Firefox-$product" if [ "$(grep -rc 'Name=$product' $fileProfil)" != 0 ]; then return; fi
#ffx_versionFF "quiet" #comptage profils existants
f__architecture 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 # calcul url téléchargement, assigne $recup_url
file="firefox-$product.$architecture.tar.bz2" ffx_recup_url(){
if [ "$product" == "latest" ]; then recup_url="https://download.mozilla.org/?product=firefox-$product&os=$architecture&lang=fr" if [ "$product" == "latest" ]; then
elif [ "$product" == "esr" ]; then recup_url="https://download.mozilla.org/?product=firefox-$product-latest&os=$architecture&lang=fr" recup_url="https://download.mozilla.org/?product=firefox-$product&os=$architecture&lang=fr"
else recup_url="https://download.mozilla.org/?product=firefox-$product-latest-l10n-ssl&os=linux&lang=fr" ;fi 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 # dossier temporaire de travail, création $dirTemp
# dirTemp="/tmp/$script-$RANDOM/" dirTemp="/tmp/$script-$RANDOM/"
dirTemp="/tmp/getFirefox-12201/"
mkdir -p "$dirTemp" mkdir -p "$dirTemp"
# chargement
f__info "téléchargement..." f__info "téléchargement..."
# wget -q -c --show-progress --tries=2 --timeout=15 --user-agent="$user_agent" -O "$dirTemp$file" "$recup_url" file="firefox-$product.$architecture.tar.bz2"
# if [ "$?" != "0" ]; then f__testWget "$recup_url"; fi 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" 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" tar -xaf "$dirTemp$file" -C "$dirTemp"
f__info "installation...." f__info "installation..."
exit # on déplace le répertoire firefox dans le répertoire installation
rm -rf "$dirInstall$product"/ # effacement éventuel répertoire existant: "vraie" install
# on déplace le répertoire firefox en /opt mkdir -p "$dirInstall$product"/
rm -rf /opt/firefox-"$product"/ mv -f "$dirTemp"firefox/* "$dirInstall$product"/
mkdir -p /opt/firefox-"$product"/ chown -R "$user_": "$dirInstall$product"/
mv -f "$dirTemp"firefox/* /opt/firefox-"$product"/ chmod -R g+wrs,a+r "$dirInstall$product"/
#ménage
rm -rf "$dirTemp" 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 ln -sf "$dirInstall$product"/browser/chrome/icons/default/default48.png /usr/share/pixmaps/firefox-"$product".png
ffx_sauveProfil
# préparer profile.ini
#ffx_profile
# install lanceur
ffx_lanceur
# lien pixmap # lien dans /usr/bin pour latest en tant que firefox
ln -sf /opt/firefox-"$product"/browser/chrome/icons/default/default48.png /usr/share/pixmaps/firefox-"$product".png 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? # # alternatives, trop intrusif pour plusieurs versions simultanées?
# update-alternatives --quiet --install /usr/bin/firefox-"$product" x-www-browser /opt/firefox-"$product"/firefox 100 # update-alternatives --quiet --install /usr/bin/firefox-"$product" x-www-browser "$dirInstall$product"/firefox 100
f__info "$GREEN""Firefox-$product installé."
#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
} }
# désinstallation de firefox # désinstallation de firefox
@ -387,12 +409,20 @@ ffx_remove(){
f__info "$GREEN" "Firefox-$product n'est pas installé." f__info "$GREEN" "Firefox-$product n'est pas installé."
return 0 return 0
fi fi
# suppression du répertoire firefox en /opt # suppression du répertoire firefox
if [ -d "/opt/firefox-$product/" ]; then rm -rf "/opt/firefox-$product/"; fi if [ -d "$dirInstall$product/" ]; then rm -rf "$dirInstall$product/"; fi
# suppression du lanceur 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 rm -f /usr/share/applications/firefox-"$product".desktop
# suppression lien pixmap rm -f /usr/bin/firefox-"$product"
unlink /usr/share/pixmaps/firefox-"$product".png &>/dev/null
# 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 # suppression alternatives si existantes
if update-alternatives --display x-www-browser &>/dev/null; then 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" 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__architecture || f__error "Architecture non supportée"
f__user f__user
f__requis "wget" "logger" "file" "tar" f__requis "wget" "logger" "file" "tar"
dirInstall="/opt/usr/share/firefox-"
# installation du script si pas dans le système # installation du script si pas dans le système
dirname "$0" | grep 'bin' &>/dev/null || fscript_install 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" \ [ "$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 case "$1" in
"sysremove" ) "sysremove" )
@ -425,11 +460,10 @@ case "$1" in
opType="upgrade" opType="upgrade"
fscript_version fscript_version
fscript_dl ;; # upgrade script si maj possible fscript_dl ;; # upgrade script si maj possible
+latest | +esr | +aurora | +nightly ) +latest | +esr | +beta | +nightly )
f__error "script en cours de refonte, installations non permise aujourd'hui"
product="$(echo $1 | sed 's/+//')" product="$(echo $1 | sed 's/+//')"
ffx_install ;; # installation plugin ffx_install ;; # installation plugin
-latest | -esr | -aurora | -nightly ) -latest | -esr | -beta | -nightly )
product="$(echo $1 | sed 's/-//')" product="$(echo $1 | sed 's/-//')"
ffx_remove ;; # désinstallation plugin ffx_remove ;; # désinstallation plugin
"manuel" ) "manuel" )

View File

@ -2,15 +2,27 @@
## todo ## todo
* install manuelle archive * installation manuelle archive
* téléchargement archive * téléchargement archive
* version enligne autre que esr et release * 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 ## 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 paramètres
* révision traitement script * révision traitement script
* révision remove * révision remove