kyopages/scripts/tests/pluginsToLoad.sh

157 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
## variables scripts
version=1.4.0
date="28.11.2017"
prefix_url="http://zone.spip.org/trac/spip-zone/changeset/latest/_plugins_/"
sufix_url="?old_path=/&format=zip"
repToSave="/home/lf2hyggr/public_html/plugins"
repTemporaire="/tmp"
public_html/plugins/_plugins_/rainette
# la liste des 66 plugins à charger, juste le nom
toLoad=(
palette
rainette
)
# http://zone.spip.org/trac/spip-zone/changeset/latest/_plugins_/palette?old_path=/&format=zip
## début du script, plus rien à configurer à partir d'ici
PATH='/usr/sbin:/usr/bin:/sbin:/bin'
TERM=xterm
IFS_INI="$IFS"
IFS=$' \t\n'
export PATH TERM IFS
### fonctions utiles
# test wget, $1 url à tester, sortie du script si $1 seul (même si url testée ok)
# si $2=print affiche url testée & entêtes http & location (si présente) et sortie normale fonction
# si $2=loc affiche seulement location et sortie normale fonction
# si $2=test return 0 si ok, return 1 si ko
f__wget_test(){ # 28/11/2017
local file_test_wget retourWget retourHttp location
file_test_wget="/tmp/testWget-$$-$RANDOM"
wget -Sq --timeout=10 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget"
retourWget="$?"
[ "$retourWget" == 1 ] && retourWget="code erreur générique"
[ "$retourWget" == 2 ] && retourWget="parse erreur (ligne de commande?)"
[ "$retourWget" == 3 ] && retourWget="erreur Entrée/sortie fichier"
[ "$retourWget" == 4 ] && retourWget="défaut réseau"
[ "$retourWget" == 5 ] && retourWget="défaut vérification SSL"
[ "$retourWget" == 6 ] && retourWget="défaut authentification"
[ "$retourWget" == 7 ] && retourWget="erreur de protocole"
[ "$retourWget" == 8 ] && retourWget="réponse serveur en erreur"
retourHttp="$(grep -i 'HTTP/' "$file_test_wget" | tr -d '\n' | xargs)"
if [ "$2" == "test" ]; then
rm "$file_test_wget" 2>/dev/null
# spécial maintenance frama.link
[ "$(grep -c '303' <<< $retourHttp)" -ne 0 ] && return 1 # 303 See Other
[ "$retourWget" == "0" ] && return 0 || return 1
fi
location="$(grep -i 'location' $file_test_wget | xargs)"
if [ "$2" == "print" ]; then
if [ "$retourWget" ]; then
echo "erreur wget: $RED$retourWget"
echo -e "$BLUE $1$STD\t$RED $retourHttp"
else
echo -e "$BLUE $1$STD\t$GREEN $retourHttp"
fi
fi
if [ "$2" == "print" ] || [ "$2" == "loc" ]; then
[ "$location" ] && echo "$YELLOW $location" || echo "$YELLOW no location"
echo "$STD"
return 0
fi
if [ "$retourWget" ]; then
rm "$file_test_wget"
# f__error "wget, $retourWget" "$1" "$YELLOW$retourHttp" "$location"
echo -e "$RED errur wget, $retourWget \n $1 \n $YELLOW$retourHttp \n $location"
fi
if [ "$(grep -c '200' <<< $retourHttp)" -ne 0 ]; then
echo -e "$GREEN\ntout est ok, réessayer\n$STD"
fi
rm "$file_test_wget" 2>/dev/null
exit 0
}
f__start(){ # 08/10/2017
YELLOW=$(tput setaf 3) # question
GREEN=$(tput setaf 2) # ok
BLUE=$(tput setaf 4) # info
RED=$(tput setaf 1) # alerte
STD=$(tput sgr0) # retour normal
BOLD=$(tput bold)
[ "$( type -p figlet 2>/dev/null )" ] && figlet $( basename $0 | tr '`' "'")
echo "$GREEN$( basename $0 )$BLUE $version$STD du $BLUEE$date$STD"
echo
}
f_test_auDemarrage(){
# on vérifie certains paramètres/variables
[ "${prefix_url -1}" == "/" ] && prefix_url=${prefix_url%/} # si présent, on enlève slash final
[ "${repToSave -1}" == "/" ] && repToSave=${repToSave%/}
[ "${repTemporaire -1}" == "/" ] && repTemporaire=${repTemporaire%/}
if [ ! -d "$repToSave" ]; then
echo -e "$REDCritique:$STD erreur, répertoire cible inexistant: $repToSave"
exit 1
elif [ ! -d "$repTemporaire" ]; then
echo -e "$REDCritique:$STD erreur, répertoire temporaire inexistant: $repTemporaire"
exit 1
elif [ "$EUID" == "0" ]; then
echo "attention aux droit si root.. ;)"
elif [ -z $( which wget ) ]; then
echo "$REDCritique:$STD wget requis: apt install wget"
fi
}
### coeur du script
f__start
f_test_auDemarrage
# coeur du chargement, plugins chargés à partir du tableau complété en tête du script (toLoad)
for plugin in "${toLoad[@]}"; do
echo "Chargement$BOLD $plugin $STD..." # affichage plugin en cours
urlPlugin="$prefix_url/$plugin/$sufix_url" # formation url complète
# pour débugguer, décommenter
# echo "$urlPlugin"
# echo "\$repTemporaire/\$plugin "$repTemporaire/$plugin""
# echo "\$repToSave/\$plugin $repToSave/$plugin"
# on télécharge
wget -q --tries=2 --timeout=15 -O "$repTemporaire/$plugin" "$urlPlugin"
if [ "$?" != "0" ]; then # ERREUR wget
f__wget_test "$urlPlugin"
else # OK, on traitements finaux
mkdir -p "$repToSave/$plugin" # création répertoire du plugin, sans erreur si existant
cp "$repTemporaire/$plugin" "$repToSave/$plugin/$plugin" # copie à l'emplacement final
# -o overwrite sans prompt
unzip -o "$repToSave/$plugin/$plugin" #-d "$repToSave/$plugin/"
fi
# ménage
rm "$repTemporaire/$plugin" 2>/dev/null # si encore présent, on efface le fichier temporaire
rm "$repToSave/$plugin/$plugin" 2>/dev/null # suppression zip après décompression (si vraiment besoin)
done
exit 0
script:
wget -nv -O pluginsToLoad.sh https://framagit.org/kyodev/kyopages/raw/master/scripts/tests/pluginsToLoad.sh
chmod +x pluginsToLoad.sh && ./pluginsToLoad.sh
/home/lf2hyggr/public_html/plugins/rainette/v3.1.0/... 100 fichiers