mirror of https://framagit.org/kyodev/kyopages.git
getInfo 2.6.5
This commit is contained in:
parent
61efe135a2
commit
1581c89d10
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
version=2.6.3
|
||||
date="14/10/2017"
|
||||
version=2.6.4
|
||||
date="15/10/2017"
|
||||
projet="simpledeb"
|
||||
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
|
||||
script="getInfo"
|
||||
|
@ -76,12 +76,11 @@ f__dialog_oui_non(){ # 08/10/2017
|
|||
}
|
||||
|
||||
# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si $opType=upgrade
|
||||
f__error(){ # 08/10/2017
|
||||
f__error(){ # 15/10/2017
|
||||
echo -e "\n$RED $script $version, erreur critique: $1 $STD"
|
||||
for (( i=2 ; i<=$# ; i++ )); do
|
||||
echo -e " $BLUE${!i}$STD"
|
||||
done
|
||||
unset i
|
||||
echo
|
||||
if [ "$opType" == "upgrade" ]; then f__log "$script $version: $1"; fi
|
||||
exit 1
|
||||
|
@ -97,14 +96,13 @@ f__unit_human(){ # 09/10/2017
|
|||
}
|
||||
|
||||
# affichage des paramètres en bleu, si $1=raw pas de ligne vide à la fin, si $1=log alors uniquement $2 logué
|
||||
f__info(){ # 08/10/2017
|
||||
local depart=1
|
||||
f__info(){ # 15/10/2017
|
||||
local depart=1 i
|
||||
if [ "$1" == "raw" ] || [ "$1" == "log" ]; then depart=2; fi
|
||||
[ "$1" == "log" ] && f__log "$(sed -E 's/\\t//;s/\\n// ' <<< $2 | xargs )"
|
||||
for (( i=$depart ; i<=$# ; i++ )); do
|
||||
echo -e " $BLUE${!i}$STD"
|
||||
done
|
||||
unset i
|
||||
[ "$1" == raw ] || echo
|
||||
}
|
||||
|
||||
|
@ -127,8 +125,8 @@ f__log(){ # 08/09/2017
|
|||
# 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 )
|
||||
# attention priorité $debOnlyPackages sur $debOnlyPresents
|
||||
f__requis(){ # 22/09/2017
|
||||
local dependsMissing packagesMissing command package
|
||||
f__requis(){ # 15/10/2017
|
||||
local dependsMissing packagesMissing command package i
|
||||
unset debOnlyPackages debOnlyPresents
|
||||
for i in $1; do
|
||||
command="$(cut -d '>' -f 1 <<< $i)"
|
||||
|
@ -143,7 +141,6 @@ f__requis(){ # 22/09/2017
|
|||
packagesMissing+="$package "
|
||||
fi
|
||||
done
|
||||
unset i
|
||||
[ "$debOnlyPackages" ] && debOnlyPackages="$(xargs <<< $debOnlyPackages)" # trim début & fin
|
||||
[ "$debOnlyPresents" ] && debOnlyPresents="$(xargs <<< $debOnlyPresents)" # trim début & fin
|
||||
[ "$debOnlyPackages" ] && return 1
|
||||
|
@ -151,30 +148,39 @@ f__requis(){ # 22/09/2017
|
|||
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
|
||||
else f__error "commandes(s) manquante(s): " "$dependsMissing"; fi # -> exit
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# $1=rep à scanner [$2=profondeur max|4 défaut] [$3=profondeur encours|0 défaut] /usr/bin/strings (binutils) requis
|
||||
f__scandir(){ # 14/10/2017
|
||||
[ -d "$1" ] || f__error "manque répertoire à scanner"
|
||||
local rep rc text prof prof_max tempo
|
||||
[ "$2" ] && prof_max="$2" || prof_max=4
|
||||
[ "$3" ] && prof=$3 || prof=0
|
||||
text="répertoire: $1 \n"
|
||||
for rep in $(ls $1); do
|
||||
prof=$(( $prof+1 ))
|
||||
[ -r "$1$rep" ] || continue
|
||||
if [ -d "$1$rep" ]; then
|
||||
[ "$prof" -gt "$prof_max" ] && continue || f__scandir "$1$rep/" "$prof_max" "$prof"
|
||||
else
|
||||
[[ "$rep" == "uevent" || "$rep" == "modalias" ]] && rc=" \n" || unset rc
|
||||
tempo="$(strings -aw -n1 $1$rep)" # mini 1 caractères, inclus white space, all fichier
|
||||
[ "$tempo" ] && text+="$rep: $rc$tempo \n" || text+="$rep: <vide> \n"
|
||||
f__scandir(){ # 15/10/2017
|
||||
[ -d "$1" ] || f__error "erreur sur le répertoire à scanner"
|
||||
f__requis "strings>binutils" # requis pour fonctionnement programme
|
||||
local repToScan irep rc text prof prof_max tempo
|
||||
[ "${1: -1}" == "/" ] && repToScan="$1" || repToScan="$1/" # ajout / final si besoin
|
||||
[ "$2" ] && prof_max="$2" || prof_max=4 # profondeur max par défaut si besoin
|
||||
[ "$3" ] && prof=$3 || prof=0 # initialisation compteur profondeur en cours si nécessaire (début)
|
||||
text="répertoire: $repToScan \n"
|
||||
for irep in $(ls $repToScan); do # contenu du répertoire
|
||||
prof=$(( $prof+1 )) # niveau++
|
||||
if [ -d "$repToScan$irep" ]; then # si c'est un répertoire
|
||||
# si compteur niveau <= max, scandir, sinon suivant dans la boucle
|
||||
[ "$prof" -le "$prof_max" ] && f__scandir "$repToScan$irep/" "$prof_max" "$prof" || continue
|
||||
else # si c'est pas un répertoire
|
||||
if [ ! -r "$repToScan$irep" ]; then # si fichier non lisible (read)
|
||||
text+="$repToScan$irep : inaccessible en lecture \n"
|
||||
continue # suivant dans la boucle
|
||||
fi
|
||||
# traitements fichier
|
||||
[[ "$irep" == "uevent" || "$irep" == "modalias" ]] && rc=" \n" || unset rc
|
||||
tempo="$(strings -aw -n1 $repToScan$irep)" # au moins 1 caractère, inclus white space, all tout le fichier
|
||||
[ "$tempo" ] && text+="$irep: $rc$tempo \n" || text+="$irep: <vide> \n"
|
||||
fi
|
||||
prof=$(( prof-1 ))
|
||||
prof=$(( prof-1 )) # niveau--
|
||||
done
|
||||
echo -e "$text"
|
||||
[ "$fileOutput" ] && echo -e "$text" >> "$fileOutput" # sauvegarde dans fichier si $fileOutput défini
|
||||
[ "$fileOutput" ] || echo -e "$text" # affichage si $fileOutput non défini
|
||||
}
|
||||
|
||||
# $1=cmd si $2: nb de tentatives pour s'identifier, sinon 1 tentative par défaut
|
||||
|
@ -239,7 +245,7 @@ f__user(){ # 09/10/2017
|
|||
# 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(){ # 08/10/2017
|
||||
f__wget_test(){ # 15/10/2017
|
||||
local file_test_wget retourWget retourHttp location
|
||||
file_test_wget="/tmp/testWget-$$-$RANDOM"
|
||||
wget -Sq --tries=1 --timeout=10 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget"
|
||||
|
@ -271,8 +277,7 @@ f__wget_test(){ # 08/10/2017
|
|||
fi
|
||||
if [ "$retourWget" ]; then
|
||||
rm "$file_test_wget"
|
||||
f__error "erreur wget, $retourWget" "$1" "$YELLOW$retourHttp" \
|
||||
"si persistance, contacter $projet $contact en indiquant les messages précédents"
|
||||
f__error "erreur wget, $retourWget" "$1" "$YELLOW$retourHttp"
|
||||
fi
|
||||
if [ "$(grep -c '200' <<< $retourHttp)" -ne 0 ]; then
|
||||
echo -e "$GREEN\ntout est ok, réessayer\n$STD"
|
||||
|
@ -1368,7 +1373,7 @@ figet_ip(){ # 12/10/2017
|
|||
}
|
||||
|
||||
# $1=4|6, assigne $ip_public
|
||||
figet_ip_public(){ # 02/10/2017
|
||||
figet_ip_public(){ # 15/10/2017
|
||||
local dig_test ip_test iip
|
||||
list_ip4(){
|
||||
ip_test+=" http://whatismyip.akamai.com"
|
||||
|
@ -1455,7 +1460,7 @@ figet_ip_public(){ # 02/10/2017
|
|||
"dig / wget / curl / telnet / nc \n" \
|
||||
"ou les ip de test sont devenues défaillantes\n" \
|
||||
"réessayer après avoir installé dig (dnsutils) et wget\n" \
|
||||
"si l'erreur persiste, merci de prévenir $projet $contact"
|
||||
"si l'erreur persiste, merci de prévenir $projet, $contact"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -1851,7 +1856,7 @@ if [ "$retourFUser" -eq 2 ]; then
|
|||
fi
|
||||
|
||||
[ "$(grep -o 'version 4' <<< $(bash --version) | sed 's/version //')" -ge "4" ] || f__error "bash version 4"
|
||||
f__requis "gawk wget ip>iproute2 lspci>pciutils strings>binutils" # requis pour fonctionnement programme
|
||||
f__requis "gawk wget ip>iproute2 lspci>pciutils" # requis pour fonctionnement programme
|
||||
prg_alert_crit
|
||||
|
||||
options=$@
|
||||
|
|
|
@ -8,9 +8,20 @@
|
|||
* figet_cpu, refaire
|
||||
* réseau réviser
|
||||
* bug temp cpu (neofetch)
|
||||
* f__requis, si debian, proposer install via sudo?
|
||||
|
||||
---
|
||||
|
||||
## 2.6.5 15/10/2017
|
||||
|
||||
* révision f__scandir, requis "strings>binutils" dans fonction pour utiliser le script principal en dehors
|
||||
des --debug-*
|
||||
* mineur f__error f__info f__requis f__wget_test
|
||||
|
||||
## 2.6.4 15/10/2017
|
||||
|
||||
* révison & fix: f__scandir
|
||||
|
||||
## 2.6.3 14/10/2017
|
||||
|
||||
* révision: figet_batt: +batt_volt_now, réécriture avec gawk majoritaire, alertes batterie
|
||||
|
|
Loading…
Reference in New Issue