This commit is contained in:
kyodev 2017-08-30 22:44:39 +02:00
parent 2100e86bb1
commit b9c61bade4
2 changed files with 46 additions and 40 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
version=1.4.0 version=1.5.0
date="30/08/2017" date="30/08/2017"
projet="simpledeb" projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/" contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
@ -57,43 +57,43 @@ f__log(){ # v08/2017
# si $2=debOnly et si paquets manquants: return 1 et $debOnlyPackages ( $1=liste paquets ) # si $2=debOnly et si paquets manquants: return 1 et $debOnlyPackages ( $1=liste paquets )
# si $2=debOnly et si paquets présent: return 0 et $debOnlyPresents ( $1=liste paquets ) # si $2=debOnly et si paquets présent: return 0 et $debOnlyPresents ( $1=liste paquets )
# attention priorité $debOnlyPackages sur $debOnlyPresents # attention priorité $debOnlyPackages sur $debOnlyPresents
f__requis(){ # v17/08/2017-3 f__requis(){ # v30/08/2017-3
local dependsMissing packagesMissing local dependsMissing packagesMissing command package
unset debOnlyPackages debOnlyPresents unset debOnlyPackages debOnlyPresents
for i in $1; do for i in $1; do
local command="$(cut -d '>' -f 1 <<< $i)" command="$(cut -d '>' -f 1 <<< $i)"
local package="$(cut -d '>' -f 2 <<< $i)" package="$(cut -d '>' -f 2 <<< $i)"
if [ "$2" == "debOnly" ]; then if [ "$2" == "debOnly" ]; then
if [ "$(which dpkg)" ]; then # package only et debian if [ "$(which dpkg)" ]; then # package only et debian
LC_ALL=C dpkg --get-selections | grep -qE "^$package[[:space:]]+install" \ LC_ALL=C dpkg --get-selections | grep -qE "^$package[[:space:]]+install" \
&& debOnlyPresents+="$package " || debOnlyPackages+="$package " && debOnlyPresents+="$package " || debOnlyPackages+="$package "
else f__error "dpkg n'est pas disponible sur ce système"; fi else f__error "dpkg n'est pas disponible sur ce système"; fi
elif [ -z "$(which $command)" ]; then elif [ -z "$(which $command)" ]; then
dependsMissing+="$command " dependsMissing+="$command "
packagesMissing+="$package " packagesMissing+="$package "
fi
done
[ "$debOnlyPackages" ] && debOnlyPackages="$(xargs <<< $debOnlyPackages)" # trim début & fin
[ "$debOnlyPresents" ] && debOnlyPresents="$(xargs <<< $debOnlyPresents)" # trim début & fin
[ "$debOnlyPackages" ] && return 1
[ "$debOnlyPresents" ] && return 0
if [ "$dependsMissing" ]; then
if [ -e /etc/debian_version ]; then f__error "paquet(s) manquant(s): " " $dependsMissing" \
" vous devriez exécuter:$GREEN apt install $packagesMissing"
else f__error "commandes(s) manquante(s): " "$dependsMissing"; fi
fi fi
} done
[ "$debOnlyPackages" ] && debOnlyPackages="$(xargs <<< $debOnlyPackages)" # trim début & fin
[ "$debOnlyPresents" ] && debOnlyPresents="$(xargs <<< $debOnlyPresents)" # trim début & fin
[ "$debOnlyPackages" ] && return 1
[ "$debOnlyPresents" ] && return 0
if [ "$dependsMissing" ]; then
if [ -e /etc/debian_version ]; then f__error "paquet(s) manquant(s): " " $dependsMissing" \
" vous devriez exécuter:$GREEN apt install $packagesMissing"
else f__error "commandes(s) manquante(s): " "$dependsMissing"; fi
fi
}
# user ayant initié la session graphique, assigne $user_ # user ayant initié la session graphique, assigne $user_
# return 1 sur échec identification user, return 2 sur absence home/ # return 1 sur échec identification user, return 2 sur absence home/
# gestion variable environnement user avec: USER_INSTALL=user script # gestion variable environnement user avec: USER_INSTALL=user script
f__user(){ # v21/08/2017-4 f__user(){ # v30/08/2017-4
if [ "$USER_INSTALL" ]; then # user_ via variable environnement, moyen d'injecter root if [ "$USER_INSTALL" ]; then # user_ via variable environnement, moyen d'injecter root
user_="$USER_INSTALL"; user_="$USER_INSTALL";
return 0 return 0
fi fi
local user_id test local user_id test root_login
local root_login="$(grep ':0:' /etc/passwd | cut -d':' -f1)" || local root_login="root" root_login="$(grep ':0:' /etc/passwd | cut -d':' -f1)" || root_login="root"
if [ "$SUDO_UID" ]; then if [ "$SUDO_UID" ]; then
user_id="$SUDO_UID"; user_id="$SUDO_UID";
elif grep -qEo '[0-9]+' <<< "$XDG_RUNTIME_DIR" ; then elif grep -qEo '[0-9]+' <<< "$XDG_RUNTIME_DIR" ; then
@ -120,9 +120,10 @@ f__user(){ # v21/08/2017-4
# test wget, $1 url à tester, sortie script, sur erreur ou retour à la normale # test wget, $1 url à tester, sortie script, sur erreur ou retour à la normale
# si $2=print affiche url testée & entêtes http & location (si présente) et sortie normale fonction # si $2=print affiche url testée & entêtes http & location (si présente) et sortie normale fonction
f__wget_test(){ #v28/08/2017 f__wget_test(){ # v30/08/2017
local file_test_wget="/tmp/testWget-$RANDOM" local file_test_wget retourWget retourHttp location
wget -Sq --tries=1 --timeout=10 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget" || local retourWget="$?" file_test_wget="/tmp/testWget-$RANDOM"
wget -Sq --tries=1 --timeout=10 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget" || retourWget="$?"
[ "$retourWget" == 1 ] && retourWget="code erreur générique" [ "$retourWget" == 1 ] && retourWget="code erreur générique"
[ "$retourWget" == 2 ] && retourWget="parse erreur (ligne de commande?)" [ "$retourWget" == 2 ] && retourWget="parse erreur (ligne de commande?)"
[ "$retourWget" == 3 ] && retourWget="erreur Entrée/sortie fichier" [ "$retourWget" == 3 ] && retourWget="erreur Entrée/sortie fichier"
@ -131,8 +132,8 @@ f__wget_test(){ #v28/08/2017
[ "$retourWget" == 6 ] && retourWget="défaut authentification" [ "$retourWget" == 6 ] && retourWget="défaut authentification"
[ "$retourWget" == 7 ] && retourWget="erreur de protocole" [ "$retourWget" == 7 ] && retourWget="erreur de protocole"
[ "$retourWget" == 8 ] && retourWget="réponse serveur en erreur" [ "$retourWget" == 8 ] && retourWget="réponse serveur en erreur"
local retourHttp="$(grep -i 'HTTP/' "$file_test_wget" | tr -d '\n' | xargs)" retourHttp="$(grep -i 'HTTP/' "$file_test_wget" | tr -d '\n' | xargs)"
local location="$(grep -i 'location' $file_test_wget | xargs)" location="$(grep -i 'location' $file_test_wget | xargs)"
if [ "$2" == "print" ] && [ -z "$retourWget" ]; then if [ "$2" == "print" ] && [ -z "$retourWget" ]; then
echo -e "\n$1" echo -e "\n$1"
echo "$GREEN$retourHttp$COLOR" echo "$GREEN$retourHttp$COLOR"
@ -224,8 +225,7 @@ fgi_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # v18/08/2017
} }
unset ip_public unset ip_public
local dig_test local dig_test ip_test
local ip_test
if [ "$1" == "IPv4" ]; then if [ "$1" == "IPv4" ]; then
list_ip4_dig list_ip4_dig
list_ip4 list_ip4
@ -277,11 +277,12 @@ fgi_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # v18/08/2017
} }
# inscription dans tache upgrade en anacron hebdomadaire, via cron horaire, $1=upgrade|install|remove # inscription dans tache upgrade en anacron hebdomadaire, via cron horaire, $1=upgrade|install|remove
fscript_cronAnacron(){ # v27/08/2017 fscript_cronAnacron(){ # v30/08/2017
local dirAnacron dirSpool fileAnacron
[ "$(type -t fscript_cronAnacron_special)" ] && fscript_cronAnacron_special # test, si fonction spécifique, appel [ "$(type -t fscript_cronAnacron_special)" ] && fscript_cronAnacron_special # test, si fonction spécifique, appel
local dirAnacron="/home/$user_/.config/anacron" dirAnacron="/home/$user_/.config/anacron"
local dirSpool="$dirAnacron/spool" dirSpool="$dirAnacron/spool"
local fileAnacron="$dirAnacron/$script.anacrontab" fileAnacron="$dirAnacron/$script.anacrontab"
[ $EUID -eq 0 ] && sed -i "/$script.anacrontab/d" /etc/crontab [ $EUID -eq 0 ] && sed -i "/$script.anacrontab/d" /etc/crontab
case "$1" in case "$1" in
install | upgrade ) install | upgrade )

View File

@ -2,6 +2,11 @@
## 1.5.0 30/08/2017
* révision f__requis, f__user, f__wget_test, fscript_cronAnacron
* révision déclaration local
## 1.4.0 30/08/2017 ## 1.4.0 30/08/2017
* révision conditions d'utilisations, fscript_install, fscript_remove(), fscript_update * révision conditions d'utilisations, fscript_install, fscript_remove(), fscript_update