getInfo 2.25.0

This commit is contained in:
kyodev 2017-11-06 13:25:09 +01:00
parent 3c790b4ad5
commit f35eba1353
2 changed files with 94 additions and 48 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
version=2.24.0
version=2.25.0
date="06/11/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
@ -272,13 +272,11 @@ f__wcv(){ # 04/11/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(){ # 17/10/2017
f__wget_test(){ # 06/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="$?"
[ "$2" == "test" ] && rm "$file_test_wget"
[ "$2" == "test" ] && [ "$retourWget" == "0" ] && return 0 || return 1
[ "$retourWget" == 1 ] && retourWget="code erreur générique"
[ "$retourWget" == 2 ] && retourWget="parse erreur (ligne de commande?)"
[ "$retourWget" == 3 ] && retourWget="erreur Entrée/sortie fichier"
@ -288,6 +286,12 @@ f__wget_test(){ # 17/10/2017
[ "$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
@ -309,7 +313,7 @@ f__wget_test(){ # 17/10/2017
if [ "$(grep -c '200' <<< $retourHttp)" -ne 0 ]; then
echo -e "$GREEN\ntout est ok, réessayer\n$STD"
fi
rm "$file_test_wget"
rm "$file_test_wget" 2>/dev/null
exit 0
}
@ -354,7 +358,7 @@ f_display_scandir(){ # 21/10/2017
echo -e "$text" >> "$fileOutput" # flush fonction
}
f_help(){ # 28/10/2017
f_help(){ # 06/11/2017
printf "$BLUE"
cat << 'EOF'
./getInfo : exécution normale, rapport markdown de la configuration
@ -371,10 +375,11 @@ cat << 'EOF'
-tn : durée du paste de n jour(s)
-us : upgrade spécial du script (pas de mise à jour auto, maj du script en place)
--ip : affiche ip publique (ipv4/ipv6), infos confidentielles, pas de rapport markdown
--mac : affiche les adresses Mac, infos confidentielles, pas de rapport markdown
--ssid : affiche configurations ssid, infos confidentielles, pas de rapport markdown,
root et NetworkManager requis
--ip : affiche ip publique (ipv4/ipv6), infos confidentielles, pas de rapport markdown
--mac : affiche les adresses Mac, infos confidentielles, pas de rapport markdown
--serial : affiche n° série disques, batterie et chassis
--ssid : affiche configurations ssid, infos confidentielles, pas de rapport markdown,
root et NetworkManager requis
-i, --install : installation du script dans le système, root requis
-r, --remove : suppression du script dans le système, root requis
@ -1192,6 +1197,28 @@ fi_reseau(){ # 31/10/2017
unset text
}
fi_serial(){ # 06/11/2017
local text file="/tmp/$$-$RANDOM-fi_serial" chassis_serial
[ "$fg_nb_disk" ] || figet_disk
[ "$fg_nb_batt" ] || figet_batt
f__sudo "cat /sys/class/dmi/id/chassis_serial 2>/dev/null > $file ; \
chown $user_: $file"
chassis_serial="$(cat $file 2>/dev/null)"
rm "$file"
###
text="$BOLD\n N° SÉRIE \n\n$STD"
[ "$" ] && text+="$GREEN * Disques: \n"
text+="$BLUE$fg_disk_serial \n\n$STD"
[ "$" ] && text+="$GREEN * Batteries \n"
text+="$BLUE$fg_batt_serial \n\n$STD"
if [ "$chassis_serial" ]; then
[ "$" ] && text+="$GREEN * Chassis \n"
text+="$BLUE$chassis_serial \n\n$STD"
fi
echo -e "$text"
unset text
}
fi_sources(){ # 31/10/2017
[ "$(f__cmd_exist dpkg)" ] || return 0
local sources dateMaj nb_packages apt text pluriel
@ -1265,7 +1292,7 @@ fi_sources(){ # 31/10/2017
unset text
}
fi_ssid(){ # 27/10/2017
fi_ssid(){ # 06/11/2017
[ "$(f__cmd_exist nmcli)" ] || f__error "NetworkManager requis"
local nm_ssid file="/tmp/$$-$RANDOM-fi_ssid" text
# nm_ssid="$(grep -Ev '#|^[[:space:]]*$' /etc/NetworkManager/system-connections/*)"
@ -1273,20 +1300,17 @@ fi_ssid(){ # 27/10/2017
f__sudo "grep -Ev '#|^[[:space:]]*$' /etc/NetworkManager/system-connections/* > $file ; \
chown $user_: $file"
if [ "$?" != "0" ]; then
f__info "\n la consultation des connections NetworkManager$RED a échoué$BLUE (droits root requis, échec authentification?)" \
"vous pouvez relancer le script$RED en root:$GREEN./getInfo --ssid$STD ou$GREEN getInfo --ssid$BLUE (script installé)"
text+="la consultation des connections NetworkManager a échoué, relancer avec les droits root \n"
echo -e "$text" >> "$fileOutput"
return 0
f__info "\n la consultation des connections NetworkManager$RED a échoué$BLUE (droits root requis, échec authentification?)"
return 1
fi
nm_ssid="$(< $file)"
nm_ssid="$(cat $file 2>/dev/null)"
rm "$file"
###
f__info "la$RED clé du réseau wifi étant visible$STD, aucun rapport n'a été créé"
text="## configuration(s) ssid networkmanager \n\n"
text+="$GREEN""grep -Ev '#|^[[:space:]]*$' /etc/NetworkManager/system-connections/*$STD \n\n"
text="$BOLD configuration(s) ssid networkmanager \n\n"
text+="$GREEN""grep -Ehv '#|^[[:space:]]*$' /etc/NetworkManager/system-connections/*$STD \n\n"
text+="$nm_ssid \n\n"
printf "$text" >> "$fileOutput"
echo -e "$text"
unset text
}
@ -1411,10 +1435,10 @@ fi_vrms(){ # 03/11/2017
unset text
}
# informations batterie(s), assigne $fg_nb_batt $fg_batt
# informations batterie(s), assigne $fg_nb_batt $fg_batt $fg_batt_serial
figet_batt(){ #v2 06/11/2017
local batt_detail batt_nb batt_unit batt_capa_design batt_capa_full batt_capa_now batt_conso
local batt_volt_min batt_volt_now batt_status batt_cycle batt_sn alert_batt_alarm
local batt_volt_min batt_volt_now batt_status batt_cycle alert_batt_alarm
local batt_sante batt_restant tempo batRep ibat uevent
if [ ! -d /sys/class/power_supply ]; then # anciennes interfaces ou inconnu
[ -d /proc/acpi/battery ] && batt_detail="ancienne interface ACPI non gérée (obsolète)"
@ -1452,7 +1476,7 @@ figet_batt(){ #v2 06/11/2017
batt_volt_now="$(gawk -F '=' '/POWER_SUPPLY_VOLTAGE_NOW=/ {printf "%.2f", $2/1000000}' <<< $uevent)" # V
batt_status="$(gawk -F '=' '/POWER_SUPPLY_STATUS=/ {print $2}' <<< $uevent)"
batt_cycle="$(gawk -F '=' '/POWER_SUPPLY_CYCLE_COUNT=/ {print $2}' <<< $uevent)"
batt_sn="$(gawk -F '=' '/POWER_SUPPLY_SERIAL_NUMBER=/ {sub(/^ | $|0/,"",$2); print $2}' <<< $uevent)"
fg_batt_serial="$(gawk -F '=' '/POWER_SUPPLY_SERIAL_NUMBER=/ {sub(/^ | $|0/,"",$2); print $2}' <<< $uevent)"
alert_batt_alarm="$(cat $batRep/$ibat/alarm 2>/dev/null)"
[ "$alert_batt_alarm" == "0" ] && unset alert_batt_alarm || alert_batt_alarm="$ibat: $alert_batt_alarm"
# calculs
@ -1475,31 +1499,37 @@ figet_batt(){ #v2 06/11/2017
batt_capa_now="$(printf "%'d" $batt_capa_now)"
fi
# sortie
# ligne 1 && n° série
batt_detail+="$ibat: $(cat $batRep/$ibat/manufacturer 2>/dev/null) "
batt_detail+="($(cat $batRep/$ibat/model_name 2>/dev/null)) $(cat $batRep/$ibat/technology 2>/dev/null), "
batt_detail+="$batt_capa_design$batt_unit - $batt_volt_min""V / $batt_volt_now""V (mini/actuel) "
[ "$(xargs <<< $batt_sn)" ] && batt_detail+="n° série: $batt_sn"
[ "$batt_cycle" != "0" ] && batt_detail+="$batt_cycle cycles"$'\n' || batt_detail+=$'\n' #ln 1fin
batt_detail+="$batt_capa_design$batt_unit - $batt_volt_min""V / $batt_volt_now""V (mini/actuel)"
[ "$(xargs <<< $fg_batt_serial)" ] && fg_batt_serial="$batt_detail, n° série: $fg_batt_serial" || fg_batt_serial="n/a"
[ "$batt_cycle" != "0" ] && batt_detail+=", $batt_cycle cycles "$'\n' || batt_detail+=" "$'\n' #ln 1fin
# ligne 2
[ "$batt_capa_full" ] && batt_detail+="pleine charge effective: $batt_capa_full$batt_unit, "
batt_detail+="pleine charge théorique: $batt_capa_design$batt_unit => "
if [[ "$batt_conso" != "0" && "$batt_conso" != "0.00" ]]; then # conso éventuelle
batt_restant+="(consommation en cours: $batt_conso$(sed 's/h//' <<< $batt_unit), "
batt_restant+="charge actuelle: $batt_capa_now$batt_unit)"
fi
[ "$batt_sante" ] && batt_detail+="$batt_sante% (indicateur)"$'\n' #ln 2fin
[ "$batt_restant" ] && batt_detail+="$batt_restant"$'\n' #ln 3fin
[ "$batt_sante" ] && batt_detail+="$batt_sante% (indicateur) "$'\n' #ln 2fin
# ligne 3
[ "$batt_restant" ] && batt_detail+="$batt_restant "$'\n' #ln 3fin
# alertes batterie
# ligne 4 éventuelle (alarme batterie)
[ "$alert_batt_alarm" ] && batt_detail+="**batterie en alarme** $alert_batt_alarm "$'\n' #[ln 4]
# lignes 5 alertes
if [ "$batt_capa_design" == "$batt_capa_full" ] && [ "$batt_volt_min" == "$batt_volt_now" ]; then
batt_detail+="les pleines charges et les voltages sont incohérents, batterie "
batt_detail+="mal gérée ou batterie HS?"$'\n' #[ln 5]
batt_detail+="mal gérée ou batterie HS? "$'\n' #[ln 5]
fi
if [ "$(awk '{printf "%d", $1}' <<< $batt_sante)" -lt 50 ] && [[ "$batt_status" == "Full" || "$batt_status" == "Unknown" ]]; then
batt_detail+="batterie très mal chargée (moins de 50%): mauvais état?"$'\n' #[ln 5]
batt_detail+="batterie très mal chargée (moins de 50%): mauvais état? "$'\n' #[ln 5]
fi
done
fg_nb_batt="$batt_nb"
[ "$batt_detail" ] && fg_batt=${batt_detail::-1} # suppression dernier $'\n'
[ "$(xargs <<< $fg_batt_serial)" ] || fg_batt_serial+="n/a"
}
# assigne $fg_cpu (3 lignes description cpu), fg_nb_threads, $fg_cpu_arch, $fg_uarch
@ -1716,32 +1746,37 @@ figet_de(){ # thanks neofetch, assigne $fg_de #30/10/2017
fg_de="${fg_de^}" # car 1 en majuscule
}
# $fg_nb_disk : nb disk fixe & amovible, $fg_disk_table : tableau sommaire
# $fg_nb_disk : nb disk fixe & amovible, $fg_disk_table : tableau sommaire, fg_disk_serial
# $fg_disk_fixe : liste devices block fixes, $fg_disk_amov : liste devices block amovibles
# $fg_disk_part_fix_tot : espace des partitions fixes montées
# $fg_disk_ata, $fg_disk_usb, $fg_disk_mmc, $fg_disk_nvme : liste disk ata, usb...
# $fg_disk_part_fixe_m, $fg_disk_part_amov_m : liste partitions montées, fixes ou amovibles
# $fg_disk_part_swap : liste partitions swap
# $fg_disk_part_fixe_nm, $fg_disk_part_amov_nm : liste partitions non montées, fixes ou amovibles
figet_disk(){ #v2 31/10/2017
local size type vendor_model serial_rev list_id idisk lsblk
figet_disk(){ #v2 06/11/2017
local size type list_id idisk lsblk vendor model rev serial
unset fg_disk_fixe fg_disk_amov
# $fg_disk_table: tableau sommaire des disques
# disk taille type vendeur modèle n° série révision
# sda 149,1G Fixe ATA Hitachi HTS54321 090620FB02015CD5N3XA C40C
fg_disk_table="$(printf '%-5s %-8s %-6s %-24s %-26s' "disk" "taille" "type" "vendeur modèle" " n° série révision")"$'\n'
# bug printf: caractères accentués diminuent 1 caractère sur arguments suivants, ajouter autant d'espaces
fg_disk_table="$(printf '%-5s %-8s %-6s %-10s %-18s %-6s' "disk" "taille" "type" "vendeur" "modèle" " rév.")"$'\n'
fg_disk_serial="$(printf '%-5s %-10s %-18s %-6s %-24s %s' "disk" "vendeur" "modèle " " rév." " n° série")"$'\n'
for idisk in $(grep -v 'loop' <<< $(ls /sys/block/)); do
size="$( lsblk -no SIZE -d /dev/$idisk | xargs )" #149,1G
type="$( sed -n '2p' <<< $(lsblk -no HOTPLUG /dev/$idisk) | xargs )" # 0 \n 0 \n ...
[ "$type" == "0" ] && type="Fixe" || type="Amov"
vendor_model="$( lsblk -no VENDOR,MODEL /dev/$idisk | xargs )" # sda ATA Hitachi HTS54321 \n \n \n ...
if [ -z "$vendor_model" ]; then
vendor_model=" na na"
vendor_model="$(ls -l /dev/disk/by-id/ | gawk ' !/-part/ && !/wwn-/ {print $9,$11}' | xargs )"
vendor_model="$(sed -E 's/.*-(.*)_[0-9]+.*$/\1/;s/_/ /g' <<< $vendor_model)"
vendor="$( lsblk -no VENDOR /dev/$idisk | xargs )"
model="$( lsblk -no MODEL /dev/$idisk | xargs )"
serial="$( lsblk -no SERIAL /dev/$idisk | xargs )"
if [[ -z "$vendor" || -z "$model" ]]; then # tentative extraction valeur via /dev/disk/by-id/
vendor="n/a"
vendor="$(ls -l /dev/disk/by-id/ | gawk ' !/-part/ && !/wwn-/ {print $9,$11}' | xargs )"
vendor="$(sed -E 's/.*-(.*)_[0-9]+.*$/\1/;s/_/ /g' <<< $vendor)"
fg_disk_table+="$(printf '%-5s %-8s %-6s %s' "$idisk" "$size" "$type" "$vendor")"$'\n'
fg_disk_serial+="$(printf '%-5s %s %s' "$idisk" "$vendor" "$serial")"$'\n'
else
rev="$( lsblk -no REV /dev/$idisk | xargs )"
fg_disk_table+="$(printf '%-5s %-8s %-6s %-10s %-18s %-6s' "$idisk" "$size" "$type" "$vendor" "$model" "$rev")"$'\n'
fg_disk_serial+="$(printf '%-5s %-10s %-18s %-6s %-24s %s' "$idisk" "$vendor" "$model" "$rev" "$serial")"$'\n'
fi
serial_rev="$( lsblk -no SERIAL,REV /dev/$idisk | xargs )" # 090620FB02015CD5N3XA C40C \n \n \n ...
fg_disk_table+="$(printf '%-5s %-8s %-6s %-24s %-26s' "$idisk" "$size" "$type" "$vendor_model" "$serial_rev")"$'\n'
# liste disques fixes ou amovibles
if [ "$(lsblk -no HOTPLUG /dev/$idisk | xargs | cut -d' ' -f2)" == "0" ]; then
fg_disk_fixe+="$idisk " # "sda sdb ..."
@ -1883,7 +1918,7 @@ figet_dmi(){ #v2 06/11/2017
for idmi in bios_vendor bios_version bios_date; do
tempo=$(cat /sys/class/dmi/id/$idmi 2>/dev/null)
tempo=$(sed 's/x.xx*//; s/To be filled by O\.E\.M\.//g' <<< $tempo | xargs)
bios+="$tempo "
bios+="$tempo"
done
[ "$product" ] && fg_dmi=$(printf "%s: %s " "prod." "$product")$'\n'
[[ "$board" && "$indic1" != "$indic2" ]] && fg_dmi+=$(printf "%s: %s " "board" "$board")$'\n'
@ -2627,7 +2662,7 @@ fileInstall="/opt/bin/$script"
urlScript="https://frama.link/getInfo"
urlNotice="https://frama.link/doc-getInfo"
# test sur frama.link ok, sinon fallback sur framagit
if [[ "$options" =~ all|-d|-h|-c ]]; then
if [[ "$options" =~ all|-d|-h|-c|-v ]]; then
if ! f__wget_test "$urlScript" "test"; then
urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/$script"
urlNotice="https://kyodev.frama.io/kyopages/scripts/getInfo/"
@ -2648,7 +2683,6 @@ for j in $options; do
-t | --test )
prg_1 "$*"
fi_batt
prg_3
exit ;; # test seulement
-c* | all )
[ "$j" == "-c" ] && exec $0 "menu"
@ -2722,6 +2756,9 @@ for j in $options; do
figet_ip
f__info "fg_mac:\n$GREEN$fg_mac_tp"
exit ;; # affiche adresses mac
--serial )
fi_serial
exit ;; # affiche n° série
--ssid )
fi_ssid
exit ;; # affiche configurations ssid, root requis

View File

@ -1,8 +1,17 @@
# changelog getInfo
* f__wcv
* f__wcv, f__wget_test
## 2.25.0 06/11/2017
* nouveau: n° série comme option, batterie, disk & chassis (si root)
* révision: plus d'extraction de n° série en standard (confidentialité) dans batterie & disk
* révision: affichage figet_disk, figet_batt
* révision: affichage ssid
* révision: f__wget_test, maintenance frama.link
* fix: ssid, pas de rapport markdown
## 2.24.0 06/11/2017
* nouveau: type de chassis selon smbios janvier 2017