getInfo 1.28.0

This commit is contained in:
kyodev 2017-09-28 20:47:34 +02:00
parent 433af7cdca
commit 8ee9635bc3
2 changed files with 128 additions and 36 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
version=1.27.0
date="27/09/2017"
version=1.28.0
date="28/09/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
script="getInfo"
@ -172,9 +172,9 @@ f__user(){ # 30/08/2017-4
# 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(){ # 25/09/2017
f__wget_test(){ # 28/09/2017
local file_test_wget retourWget retourHttp location
file_test_wget="/tmp/testWget-$RANDOM"
file_test_wget="/tmp/testWget-$$-$RANDOM"
wget -Sq --tries=1 --timeout=10 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget" || retourWget="$?"
if [ "$2" == "test" ] && [ "$?" == "0" ]; then return 0; else return 1; fi
[ "$retourWget" == 1 ] && retourWget="code erreur générique"
@ -240,6 +240,22 @@ EOF
echo -e "$COLOR\n plus d'infos: $GREEN$urlNotice$COLOR\n"
}
# [$1=debug]
fi_batt(){ # 28/09/2017
[ "$batt_nb" ] || figet_battery # appel figet_battery si pas déjà fait par fi_systeme
[ "$batt_nb" ] || return 0
text="## batterie(s) \n\n"
text+='```\n'
text+="$batt_detail \n"
text+='```\n\n'
if [ "$1" == "debug" ]; then
text+='```\n'
text+="$(cat /sys/class/power_supply/BAT?/uevent) \n"
text+='```\n'
fi
echo -e "$text" >> "$fileOutput"
}
fi_cpu(){ # 30/08/2017
local cpu_addr cpu_bogomips cpu_flags memsys text
cpu_addr="$(sed -n 's/^address sizes.*: \(.*\)$/\1/p' /proc/cpuinfo | head -n 1)"
@ -659,8 +675,8 @@ fi_system_analyse(){ # 25/09/2017
echo -e "$text" >> "$fileOutput"
}
fi_systeme(){ # 26/09/2017
local mbr description uname bootImage xorg shells lastboot uptime text
fi_systeme(){ # 28/09/2017
local mbr description uname bootImage xorg shells lastboot uptime text pluriel
[ -d /sys/firmware/efi ] && mbr="**EFI**" || mbr="**Legacy (mbr)**"
[ -x "/usr/bin/lsb_release" ] && description="$(lsb_release -ds)" #dépend de apt install lsb-release, sur debian, en standard, juste : lsb-base
uname="$(uname -rmo)"
@ -711,7 +727,11 @@ fi_systeme(){ # 26/09/2017
figet_disk
text+="$part_fix_tot \n"
figet_battery
text+="batteries(s): $battery \n" # batteries(s): 100% [Full]
if [ "$batt_detail" ]; then
[ "$batt_nb" -gt "1" ] && pluriel="(s)"
text+="$batt_nb batterie$pluriel présente$pluriel: \n"
text+="$(sed -nE 's/^BAT(.*)$/ BAT\1/p' <<< $batt_detail) \n"
fi
text+="dernier boot: $lastboot, uptime: $uptime \n"
text+='```\n\n'
echo -e "$text" >> "$fileOutput"
@ -734,16 +754,70 @@ fi_usb(){ # 25/09/2017
echo -e "$text" >> "$fileOutput"
}
figet_battery() { # thanks neofetch, assigne $battery # 23/09/2017
local capacity status
for bat in "/sys/class/power_supply/BAT"*; do
capacity="$(< "${bat}/capacity")"
status="$(< "${bat}/status")"
battery+="${capacity}% [${status}]"
done
unset bat
return
[[ "$battery_state" ]] && battery+=" En charge"
# informations batterie(s), assigne $batt_nb $batt_detail
figet_battery(){ # 28/09/2017
local batt_alim batt_unit batt_capa_design batt_capa_full batt_capa_now batt_conso
local batt_sn batt_cycle tempo batt_restant
batt_nb="$(ls /sys/class/power_supply/ | grep -c 'BAT')"
if [ "$batt_nb" -gt "0" ]; then
batt_alim="$(cat /sys/class/power_supply/AC0/online)"
unset batt_detail
for ibat in /sys/class/power_supply/BAT*; do
batt_detail+="$(basename $ibat): "
if [ -e "$ibat/charge_full_design" ]; then
batt_unit=" mAh"
batt_capa_design="$(cat $ibat/charge_full_design 2>/dev/null)"
batt_capa_full="$(cat $ibat/charge_full 2>/dev/null)"
batt_capa_now="$(cat $ibat/charge_now 2>/dev/null)"
batt_conso="$(cat $ibat/current_now 2>/dev/null)"
elif [ -e "$ibat/energy_full_design" ]; then
batt_unit=" mWh"
batt_capa_design="$(cat $ibat/energy_full_design 2>/dev/null)"
batt_capa_full="$(cat $ibat/energy_full 2>/dev/null)"
batt_capa_now="$(cat $ibat/energy_now 2>/dev/null)"
batt_conso="$(cat $ibat/power_now 2>/dev/null)"
else
batt_capa_design="na"
fi
batt_capa_design="${batt_capa_design%000}"
batt_capa_full="${batt_capa_full%000}"
batt_capa_now="${batt_capa_now%000}"
batt_conso="${batt_conso%000}"
batt_sn="$(cat $ibat/serial_number 2>/dev/null)"
batt_cycle="$(cat $ibat/cycle_count 2>/dev/null)"
batt_detail+="$(cat $ibat/manufacturer 2>/dev/null) "
batt_detail+="$(cat $ibat/model_name 2>/dev/null) "
batt_detail+="$(cat $ibat/technology 2>/dev/null) "
batt_detail+="$batt_capa_design $batt_unit "
[ "$batt_batt_sn" ] && batt_detail+="n° série:$batt_sn \n"
[ "$batt_cycle" != "0" ] && batt_detail+="$batt_cycle cycles \n" || batt_detail+="\n"
if [ "$batt_capa_design" != "na" ] && [ "$batt_capa_full" ]; then
batt_detail+="pleine charge théorique: $batt_capa_design $batt_unit, "
batt_detail+="pleine charge effective $batt_capa_full $batt_unit "
batt_sante="$(awk '{printf "%.1f", $1/$2*100}' <<< "$batt_capa_full $batt_capa_design")"
batt_detail+="$batt_sante % (indicateur santé) \n"
fi
if [ "$batt_capa_now" ] && [ "$batt_capa_full" ] && [ "$batt_capa_now" == "$batt_capa_full" ]; then
batt_restant="totalement chargée "
elif [ "$batt_capa_now" ] && [ "$batt_conso" ] && [ "$batt_capa_full" ]; then
if [ "$batt_alim" == "0" ]; then
batt_restant="en décharge, reste approximativement: "
# tempo="$(echo "scale=2;$batt_capa_now*0.9/$batt_conso" | bc)"
tempo="$(awk '{print $1*0.9/$2}' <<< "$batt_capa_now $batt_conso")"
batt_restant+="$(awk '{printf "%d h %02d mn \n", $1, $1*60%60}' <<< $tempo) "
else
batt_restant="en charge, reste approximativement: "
tempo="$(awk '{print ($1-$2)/$3}' <<< "$batt_capa_full $batt_capa_now $batt_conso")"
batt_restant+="$(awk '{printf "%d h %02d mn \n", $1, $1*60%60}' <<< $tempo) "
fi
fi
[ "$batt_conso" ] && batt_restant+="(consommation en cours: $batt_conso $(sed 's/h//' <<< $batt_unit))"
[ "$batt_restant" ] && batt_detail+="$batt_restant \n"
batt_detail+="\n"
done
unset ibat
batt_detail="$(echo -e $batt_detail)"
fi
}
figet_cpu() { # thanks neofetch, assigne $cpu # 30/08/2017
@ -809,7 +883,7 @@ figet_de() { # thanks neofetch, assigne $de
# assigne $disk_lsblk $disk_utilisation $disk_detail $disk_hotplug $disk_fix $part_fix
# $part_hotplug $part_fix_tot $disk_ata $disk_usb $disk_mmc $disk_nvme
figet_disk(){ # 26/09/2017
figet_disk(){ # 28/09/2017
disk_lsblk="$(lsblk -o NAME,FSTYPE,SIZE,LABEL,MOUNTPOINT,UUID,OWNER)"
disk_utilisation="$(df -h --output=source,target,fstype,size,used,avail,pcent --exclude=tmpfs --exclude=devtmpfs | grep -Ev 'devpts|none|proc|sys|tmpfs|udev')"
# détails disques et séquences disques fixes et amovibles, $disk_detail, $disk_fix, $disk_hotplug
@ -826,9 +900,11 @@ figet_disk(){ # 26/09/2017
disk_detail="$(echo -e $disk_detail)"
unset idisk
# séquences partitions fixes, $part_fix, $(printf '/dev/%s ' $part_fix), "sda1 sda2 sda3"
part_fix="$(lsblk -o KNAME,MOUNTPOINT $(printf '/dev/%s ' $disk_fix) | grep '/' | awk '{print $1}' | tr '\n' ' ')"
part_fix="$(lsblk -o KNAME,MOUNTPOINT $(printf '/dev/%s ' $disk_fix) 2>/dev/null | grep '/')"
part_fix="$(awk '{print $1}' <<< $part_fix | tr '\n' ' ')"
# séquences partitions amovibles, $part_hotplug
part_hotplug="$(lsblk -o KNAME,MOUNTPOINT $(printf '/dev/%s ' $disk_hotplug) | grep '/' | awk '{print $1}' | tr '\n' ' ')"
part_hotplug="$(lsblk -o KNAME,MOUNTPOINT $(printf '/dev/%s ' $disk_hotplug) 2>/dev/null | grep '/')"
part_hotplug="$(awk '{print $1}' <<< $part_hotplug | tr '\n' ' ')"
[ "$disk_fix" ] || disk_fix="-"
[ "$part_fix" ] || part_fix="-"
[ "$disk_hotplug" ] || disk_hotplug="-"
@ -1233,12 +1309,6 @@ fscript_update(){ # 06/09/2017
f__info "log" "$script mis à jour en version $versionScript"
}
testuser(){ # 08/2017
f__user && retourFUser=0 || retourFUser="$?"
[ "$retourFUser" -eq 1 ] && f__error "user indéterminé, pour contourner, lancer le script avec:\n USER_INSTALL=user $0 \n"
[ "$retourFUser" -eq 2 ] && f__error "user détecté, mais pas de home: /home/$user_"
}
# initialisation
PATH='/usr/sbin:/usr/bin:/sbin:/bin'; TERM=xterm ; IFS=$' \t\n'
export PATH TERM IFS
@ -1251,23 +1321,31 @@ fileLogs="/var/log/sdeb_$script.log"
fileDev="/opt/bin/fileDev"
f__affichage
f__user && retourFUser=0 || retourFUser="$?"
[ "$retourFUser" -eq 1 ] && f__error "user indéterminé, pour contourner, lancer le script avec:\n USER_INSTALL=user $0 \n"
if [ "$retourFUser" -eq 2 ]; then
[ "$EUID" == 0 ] && user_="root" || f__error "user détecté, mais pas de home: /home/$user_"
f__info "user root"
fi
[ "$(grep -o 'version 4' <<< "$(bash --version)" | awk '{print $2}')" -ge "4" ] || f__error "bash version 4"
f__requis "awk>gawk wget ip>iproute2" # requis pour fonctionnement programme
prg_1(){ # début
rm "$fileOutput" &>/dev/null
touch "$fileOutput"
# rm "$fileOutput" &>/dev/null
# touch "$fileOutput"
echo > "$fileOutput"
chown $user_: "$fileOutput"
hote="$(uname -n)"
dateRapport="$(date +"%d %b %Y %H:%M %z")"
echo -e "# $script sur $hote \n" > "$fileOutput"
echo -e "Rapport du $dateRapport -- [$script $version]($urlNotice) \n" >> "$fileOutput"
}
prg_t(){ # traitements principaux
prg_2(){ # traitements principaux
printf " ."
fi_systeme; printf "."
fi_cpu; printf "."
fi_gpu; printf "."
fi_batt; printf "."
fi_localisation; printf "."
fi_sources; printf "."
fi_disk; printf "."
@ -1291,18 +1369,18 @@ options=$@
# traitement option
for j in $options; do
case $j in
debug )
--debug-paste )
optDebug="debug"
;; # si debug, retour json de pastery.net
-t* )
pasteDuration="$(sed -En 's/-t([0-9]+)/\1/p' <<< $i)"
pasteDuration="$(sed -En 's/-t([0-9]+)/\1/p' <<< $j)"
;; # durée de conservation standard du paste en jours
esac
done
unset j
[ "$pasteDuration" ] || pasteDuration=7 # durée de conservation standard du paste en jours
# purge option des options
options="$(sed -E 's/debug[ ]*//g; s/-t[0-9]+//g' <<< $options | xargs)"
options="$(sed -E 's/--debug-paste//g; s/-t[0-9]+//g' <<< $options | xargs)"
# traitement action
[ "$options" == "" ] && options="info"
for j in $options; do
@ -1312,6 +1390,16 @@ for j in $options; do
prg_2
prg_3
exit ;; # programme
--batt )
prg_1
fi_batt
prg_3
exit ;; # debug battery
--debug-batt )
prg_1
fi_batt "debug"
prg_3
exit ;; # debug battery
-d | --dmesg )
prg_1
fi_dmesg "dmesg"
@ -1343,15 +1431,12 @@ for j in $options; do
fi_ssid
exit ;; # affiche configurations ssid, root requis
-i | --install )
testuser
fscript_install
exit ;; # installation du script dans le système
-r | --remove )
testuser
fscript_remove
exit ;; # suppression du script dans le système
-u | --upgrade )
testuser
opType="upgrade"
fscript_update
exit ;; # upgrade script si maj possible

View File

@ -5,8 +5,15 @@
* placer ln dans /usr/local/bin au lieu de /usr/bin ?
* hasher les cmds pour gain temps exécution?
* utilité figet_battery ou à refaire
* prévoir exécution en root (terminal)
## 1.28.0 28/09/2017
* suppression figet_battery neofetch
* nouveau figet_battery
* fix mineur figet_disk
* retour en f_user "général"
* f__wget_test, nouveau nommage fichier temp
## 1.27.0 27/09/2017