kyopages/scripts/tests/diag_getThunderbird

154 lines
5.2 KiB
Bash
Executable File

#!/bin/bash
version=5/12/2017
# si $1=all affichage complet
f__affichage(){ # 5/12/2017
# définition couleurs
YELLOW="$(printf "\033[0;33m")" # ?
GREEN="$(printf "\033[0;32m")" # ok
BLUE="$(printf "\033[0;34m")" # info
RED="$(printf "\033[0;31m")" # alerte
COLOR="$(printf "\033[0m")" # standard
STD="$(printf "\033[0m")" # standard
[ "$1" == all ] || return
clear
printf "$YELLOW"
[ "$(which figlet)" ] && figlet -w120 "$(basename $0)" || echo -e "\t\t\t$(basename $0)"
echo -e "$GREEN\t\t\tversion $version$COLOR\n"
}
f_help(){ # 25/12/2017
f__affichage all
printf $BLUE
cat << 'EOF'
----------------------------------------------------------------------
=== versions Thunderbird ===
latest: x.y.z beta: x.y.z
pour chaque architecture linux ou linux64 (32 ou 64 bits):
==========================================================
canal: url récup canal HTTP/1.1 302 Found HTTP/1.1 200 OK
Location: url réelle de l'archive du canal si redirection
----------------------------------------------------------------------
liens de téléchargement manuels:
latest : https://www.mozilla.org/fr/thunderbird/
latest : https://www.mozilla.org/en-US/thunderbird/all/
beta : https://www.mozilla.org/fr/thunderbird/channel/
beta : https://www.mozilla.org/en-US/thunderbird/beta/all/
EOF
printf $COLOR
exit
}
# test wget, $1=url à tester, sortie du script (même si url testée ok) avec affichage erreur ou ok
# si $2=print affiche url testée & entêtes http & location, return 0
# si $2=loc affiche seulement location, return 0
# si $2=test return 0 si ok, return 1 si KO
f__wget_test(){ # 11/12/2017
local file_test_wget retourWget retourHttp location
file_test_wget="/tmp/testWget-$$-$RANDOM"
wget -Sq --timeout=5 --tries=2 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget"
retourWget="$?"
[ "$retourWget" == 1 ] && retourWget="1: code erreur générique"
[ "$retourWget" == 2 ] && retourWget="2: parse erreur (ligne de commande?)"
[ "$retourWget" == 3 ] && retourWget="3: erreur Entrée/sortie fichier"
[ "$retourWget" == 4 ] && retourWget="4: défaut réseau"
[ "$retourWget" == 5 ] && retourWget="5: défaut vérification SSL"
[ "$retourWget" == 6 ] && retourWget="6: défaut authentification"
[ "$retourWget" == 7 ] && retourWget="7: erreur de protocole"
[ "$retourWget" == 8 ] && retourWget="8: réponse serveur en erreur"
retourHttp=$( grep -i 'HTTP/' "$file_test_wget" | tr -d '\n' | xargs )
location=$( grep -i 'location' $file_test_wget | xargs )
if [ "$2" == "test" ]; then
rm "$file_test_wget" 2>/dev/null
# spécial maintenance frama.link, pas de redirection sur page status framalink
[ "$( grep -c '303' <<< $retourHttp )" -ne 0 ] && return 1 # 303 See Other
[ "$retourWget" == "0" ] && return 0 || return 1
fi
if [ "$2" == "print" ]; then
if [ "$retourWget" != "0" ]; then
echo "erreur wget: $RED$retourWget"
echo -e "$BLUE $1$STD\t$RED $retourHttp"
else
echo -e "$BLUE $1$STD\t$GREEN $retourHttp"
fi
echo "$STD"
fi
if [ "$2" == "print" ] || [ "$2" == "loc" ]; then
[ "$location" ] && echo -n "$YELLOW $location" || echo -n "$YELLOW no location"
echo "$STD"
rm "$file_test_wget" 2>/dev/null
return 0
fi
if [ "$retourWget" != "0" ]; then
rm "$file_test_wget" 2>/dev/null
# f__error "wget, $retourWget" "$1" "$YELLOW$retourHttp" "$location"
echo -e "$RED erreur wget, $retourWget \n $1 \n $YELLOW$retourHttp \n $location$STD" # pour les diags
return 1
fi
if [ "$(grep -c '200' <<< $retourHttp)" -ne 0 ]; then
echo -e "$GREEN\ntout est ok, réessayer$STD\n"
fi
rm "$file_test_wget" 2>/dev/null
exit 0
}
test_url_dl_thunderbird(){ # 5/12/2017
local recup_url fu_archi
for fu_archi in linux linux64; do
echo " Architecture: $fu_archi"
echo " ====================="
for canal in latest beta; do
[ "$canal" == "beta" ] && prefixe="$canal-"
recup_url="https://download.mozilla.org/?product=thunderbird-$prefixe""latest&os=$fu_archi&lang=fr"
printf " $canal":
f__wget_test "$recup_url" print
done
done
}
# assigne $verLatest, $verBeta
test_version_thunderbird(){ # 5/12/2017
local recup_url prefixe verOnline verTbOnline
echo -e "\n === versions Thunderbird ==="
for canal in latest beta; do
# version online
[ "$canal" == "beta" ] && prefixe="$canal-"
recup_url="https://download.mozilla.org/?product=thunderbird-$prefixe""latest&os=$fu_archi&lang=fr"
verOnline="$( sed -E 's#.*thunderbird/releases/(.*)/linux-.*$#\1#' <<< $( f__wget_test $recup_url loc ) )"
verTbOnline+="$( printf "%-7s: %-12s" $canal $verOnline )"
done
[ "$verTbOnline" ] || verTbOnline="$RED""aucune(s)"
echo -e " $GREEN$verTbOnline$COLOR"
}
# start
user_agent="Mozilla/5.0 Firefox"
f__affichage
[ "$1" == "-h" ] && f_help
fu_archi="linux64"
test_version_thunderbird
echo
test_url_dl_thunderbird
echo
#nouveaux formats?:
#https://download.mozilla.org/?product=thunderbird-52.5.2-SSL&os=linux64&lang=fr
#https://download.mozilla.org/?product=thunderbird-58.0b2-SSL&os=linux64&lang=fr
exit
autres liens
https://releases.mozilla.org/pub/thunderbird/releases/latest/
https://releases.mozilla.org/pub/thunderbird/releases/latest-beta/
https://releases.mozilla.org/pub/thunderbird/nightly/latest-comm-central-l10n/