getInfo 1.29.0

This commit is contained in:
kyodev 2017-09-29 20:27:53 +02:00
parent 8ee9635bc3
commit 93be0f18e6
2 changed files with 108 additions and 60 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
version=1.28.0
date="28/09/2017"
version=1.29.0
date="29/09/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
script="getInfo"
@ -172,11 +172,13 @@ 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(){ # 28/09/2017
f__wget_test(){ # 29/09/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" || retourWget="$?"
if [ "$2" == "test" ] && [ "$?" == "0" ]; then return 0; else return 1; fi
wget -Sq --tries=1 --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"
@ -256,36 +258,41 @@ fi_batt(){ # 28/09/2017
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)"
cpu_bogomips="$(sed -n 's/^bogomips.*: \(.*\)$/\1/p' /proc/cpuinfo | head -n 1)"
cpu_flags="$(sed -n 's/^flags.*: \(.*\)$/\1/p;' /proc/cpuinfo | head -n 1)"
fi_cpu(){ # 29/09/2017
local cpu_addr cpu_bogomips cpu_flags memsys swappiness text
cpu_addr="$(sed -n 's/^address sizes.*: \(.*\)$/\1/p' /proc/cpuinfo | sed -n '1p')"
cpu_bogomips="$(sed -n 's/^bogomips.*: \(.*\)$/\1/p' /proc/cpuinfo | sed -n '1p')"
cpu_flags="$(sed -n 's/^flags.*: \(.*\)$/\1/p;' /proc/cpuinfo | sed -n '1p')"
memsys="$(free -ht)"
swappiness="$(cat /proc/sys/vm/swappiness)"
###
text="## processeur / mémoire \n\n"
text+='```\n'
figet_cpu
text+='```\n'
text+="CPU: $cpu \n"
text+="adressage: $cpu_addr \n"
text+="bogomips: $cpu_bogomips \n"
figet_memory
text+="\nmémoire Ram utilisée/totale: $memory \n\n"
text+="mémoire système: $memsys \n"
text+='```\n\n'
text+='```\n'
text+="flags cpu: \n"
text+='```\n'
text+="$cpu_flags \n"
text+='```\n\n'
figet_memory
text+='```\n'
text+="mémoire Ram utilisée/totale: $memory \n\n"
text+="mémoire système: $memsys \n\n"
text+="swappiness: $swappiness \n"
text+='```\n\n'
echo -e "$text" >> "$fileOutput"
}
fi_disk(){ # 26/09/2017
fi_disk(){ # 29/09/2017
local fstab resume idResume idSwap alert_uuidResume text
fstab="$(grep -vE '#|^$' /etc/fstab)"
resume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume)"
resume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume 2>/dev/null)"
# idResume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume | sed -En 's/^[^[:blank:]{1,}][^#{1,}].*UUID=(.*)$/\1/p')"
idResume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume | sed -En 's/.*UUID=([0-9a-Z-]*).*$/\1/p')"
idResume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume 2>/dev/null | sed -En 's/.*UUID=([0-9a-Z-]*).*$/\1/p')"
idSwap="$(grep -Ev '#|^$' /etc/fstab | sed -En 's/^UUID=([0-9a-Z-]*).*swap.*$/\1/p')"
if [ "$idSwap" ] && [ "$idResume" ] && [ "$idSwap" != "$idResume" ]; then
alert_uuidResume+="id swap : $idSwap \nid resume: $idResume\n"
@ -310,18 +317,22 @@ fi_disk(){ # 26/09/2017
text+='```\n'
text+="$disk_utilisation \n"
text+='```\n\n'
text+='``'"grep -vE '#|^$' /etc/fstab"'`` (fstab) \n' # fstab
text+='``'"grep -vE '#|^$' /etc/fstab"'`` (fstab) \n' # fstab
text+='```\n'
text+="$fstab \n"
text+='```\n\n'
text+='``'"lsblk -o NAME,FSTYPE,SIZE,LABEL,MOUNTPOINT,UUID,OWNER"'`` (disques) \n' # lsblk
text+='``'"lsblk -o NAME,FSTYPE,SIZE,LABEL,MOUNTPOINT,UUID,OWNER"'`` (disques) \n' # lsblk
text+='```\n'
text+="$disk_lsblk \n"
text+='```\n\n'
text+='``'"grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume"'`` (resume) \n' # resume
text+='``'"grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume"'`` (resume) \n' # resume
text+='```\n'
text+="$resume \n"
text+='```\n\n'
if [ "$resume" ]; then
text+="$resume \n"
else
text+="pas de fichier resume trouvé \n"
fi
text+='```\n\n'
if [ "$alert_uuidResume" ]; then
text+="$alert_uuidResume \n\n"
fi
@ -593,20 +604,27 @@ fi_reseau(){ # 25/09/2017
echo -e "$text" >> "$fileOutput"
}
fi_sources(){ # 25/09/2017
[ "$(which apt)" ] || return 0 # retour si pas d'apt ? et aptitude...????
local sources dateMaj apt autoremove paquetToRemove httpredir upgradable nbUpgradable dpkgArch paquetBiz text
fi_sources(){ # 29/09/2017
if [ -z "(which dpkg)" ]; then
f__info "le système n'est pas basé sur dpkg. les informations correspondantes ne peuvent "
"donc être ""extraites \n"
return 0
fi
local sources dateMaj nb_packages apt autoremove paquetToRemove httpredir upgradable nbUpgradable
local dpkgArch paquetBiz text
printf "."
sources="$(grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null | sed 's/ / /g; s/:/: /')"
dateMaj="$(date -r /var/cache/apt/archives/)"
sources="$(grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null)"
sources="$(sed 's/:deb/: deb/; s/ / /g' <<< $sources)"
dateMaj="$(date -r /var/cache/apt/pkgcache.bin)" # /var/lib/dpkg/
nb_packages="$(dpkg -l | grep -c '^ii')"
printf "."
apt="$(LC_ALL=C apt-get autoremove --simulate)"
autoremove="$(grep -c 'Remv' <<< $apt)"
paquetToRemove="$(grep 'Remv' <<< $apt | sed 's/Remv //; s/\[[0-9.-]*\]//' | tr '\n' ' ')"
printf "."
httpredir="$(grep 'httpredir' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null)"
httpredir="$(grep 'httpredir' <<< $sources)"
upgradable="$(LC_ALL=C apt list --upgradable 2>/dev/null | sed 's/Listing...//' | grep -v '^$')"
[ "$upgradable" ] && nbUpgradable="$(wc -l <<< "$upgradable")"
[ "$upgradable" ] && nbUpgradable="$(grep -c '' <<< "$upgradable")"
printf "."
dpkgArch="$(dpkg --print-architecture)"
paquetBiz="$(dpkg -l | grep -v '^i' | grep "$dpkgArch" | awk '{print $1, $2, $3}')"
@ -616,7 +634,8 @@ fi_sources(){ # 25/09/2017
text+='```\n'
text+="$sources \n"
text+='```\n\n'
text+="dernière mise à jour **apt: $dateMaj** \n\n"
text+="nombre de paquets installés: **$nb_packages** \n\n"
text+="dernière mise à jour apt: **$dateMaj** \n\n"
if [ "$autoremove" -ne 0 ] ; then
text+="**$autoremove paquet(s) installé(s) inutile(s)**, vous pouvez utiliser: "'`apt autoremove`'" \n"
text+="paquet(s) concerné(s): \n"
@ -625,7 +644,7 @@ fi_sources(){ # 25/09/2017
text+='```\n\n'
fi
if [ "$httpredir" ]; then
text+="url **httpredir,** ces urls sont obsolètes, préférer http://deb.debian.org/debian/ ou un miroir local\n"
text+="url **httpredir,** ces urls sont obsolètes, préférer http://deb.debian.org/debian/ ou un miroir local \n"
text+='```\n'
text+="$httpredir \n"
text+='```\n\n'
@ -755,15 +774,16 @@ fi_usb(){ # 25/09/2017
}
# informations batterie(s), assigne $batt_nb $batt_detail
figet_battery(){ # 28/09/2017
figet_battery(){ # 29/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
local batt_voltage batt_status batt_sn batt_cycle tempo batt_restant
batt_nb="$(ls /sys/class/power_supply/ | grep -c 'BAT')"
if [ "$batt_nb" -gt "0" ]; then
# extraction valeur
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): "
# extraction pour valeur de calcul ou selon type unité
if [ -e "$ibat/charge_full_design" ]; then
batt_unit=" mAh"
batt_capa_design="$(cat $ibat/charge_full_design 2>/dev/null)"
@ -779,39 +799,53 @@ figet_battery(){ # 28/09/2017
else
batt_capa_design="na"
fi
# mise en forme micro en milli
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}"
# extraction
batt_voltage="$(cat $ibat/voltage_min_design 2>/dev/null)"
batt_status="$(cat $ibat/status 2>/dev/null)"
batt_sn="$(cat $ibat/serial_number 2>/dev/null)"
batt_cycle="$(cat $ibat/cycle_count 2>/dev/null)"
# calculs
if [ "$batt_capa_design" != "na" ] && [ "$batt_capa_full" ]; then
batt_sante="$(awk '{printf "%.1f", $1/$2*100}' <<< "$batt_capa_full $batt_capa_design")"
fi
if [ "$batt_status" == "Full" ] || [ "$batt_status" == "Unknow" ]; then
batt_restant="totalement chargée"
elif [ "$batt_status" == "Discharging" ]; then # alt: [ "$batt_alim" == "0" ]
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) "
elif [ "$batt_status" == "Charging" ]; then # alt: [ "$batt_alim" == "0" ]
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
if [ "$batt_conso" != "0" ]; then
batt_restant+="(consommation en cours: $batt_conso $(sed 's/h//' <<< $batt_unit), "
batt_restant+="charge en cours: $(printf "%'d" $batt_capa_now) $batt_unit)"
fi
# mise en forme pour sortie, séparateur milliers
batt_capa_design="$(printf "%'d" $batt_capa_design)"
batt_capa_full="$(printf "%'d" $batt_capa_full)"
batt_conso="$(printf "%'d" $batt_conso)"
batt_voltage="$(awk '{printf "%.2f", $1/1000000}' <<< "$batt_voltage")" # µV en V
# sortie
batt_detail+="$(basename $ibat): "
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_detail+="$batt_voltage V "
[ "$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_capa_full" ] && batt_detail+="pleine charge effective: $batt_capa_full $batt_unit, "
[ "$batt_capa_design" != "na" ] && batt_detail+="pleine charge théorique: $batt_capa_design $batt_unit => "
[ "$batt_sante" ] && batt_detail+="$batt_sante % (indicateur santé) \n"
[ "$batt_restant" ] && batt_detail+="$batt_restant \n"
batt_detail+="\n"
done
@ -820,7 +854,7 @@ figet_battery(){ # 28/09/2017
fi
}
figet_cpu() { # thanks neofetch, assigne $cpu # 30/08/2017
figet_cpu() { # thanks neofetch, assigne $cpu # 29/09/2017
local speed_dir temp_dir speedMin speed speedMin speed temp cores
cpu="$(awk -F ': | @' '/model name|Processor/ {printf $2; exit}' /proc/cpuinfo)"
speed_dir="/sys/devices/system/cpu/cpu0/cpufreq"
@ -842,8 +876,8 @@ figet_cpu() { # thanks neofetch, assigne $cpu # 30/08/2017
temp="[${temp/${temp: -1}}.${temp: -1}°C]"
fi
# Show/hide hyperthreaded cores
cores="$(grep "^core id" /proc/cpuinfo | sort -u | wc -l)" # physique
coresT="$(grep -c "^processor" /proc/cpuinfo)" # logique
cores="$(grep "^core id" /proc/cpuinfo | sort -u | grep -c '')" # physique
coresT="$(grep -c "^processor" /proc/cpuinfo)" # logique
# Fix for speeds under 1ghz
if [[ -z "${speed:1}" ]]; then speed="0.${speed}"; else speed="${speed:0:1}.${speed:1}"; fi
if [[ -z "${speedMin:1}" ]]; then speedMin="0.${speedMin}"; else speedMin="${speedMin:0:1}.${speedMin:1}"; fi
@ -862,7 +896,7 @@ figet_cpu() { # thanks neofetch, assigne $cpu # 30/08/2017
cpu="${cpu//Core}"
cpu="${cpu//with Radeon * Graphics}"
# Add cpu cores to output
cpu="${cpu/@/(${cores})(${coresT}) @}"
cpu="${cpu/@/(${cores})phys. (${coresT})logi. @}"
}
figet_de() { # thanks neofetch, assigne $de
@ -1313,7 +1347,7 @@ fscript_update(){ # 06/09/2017
PATH='/usr/sbin:/usr/bin:/sbin:/bin'; TERM=xterm ; IFS=$' \t\n'
export PATH TERM IFS
urlScript="https://frama.link/getinfo"
f__wget_test "$urlNotice" test || urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/$script"
f__wget_test "$urlScript" "test" || urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/$script"
urlNotice="https://frama.link/doc-getinfo"
f__wget_test "$urlNotice" test || urlNotice="https://kyodev.frama.io/kyopages/scripts/getInfo/"
fileOutput="getInfo_rapport.md"

View File

@ -6,6 +6,20 @@
* placer ln dans /usr/local/bin au lieu de /usr/bin ?
* hasher les cmds pour gain temps exécution?
* prévoir exécution en root (terminal)
* option erreur pour f__info
* réorganiser en famille à afficher avec option de choix possible
## 1.29.0 29/09/2017
* f__wget_test: correction code retour lors "test"
* fi_sources:
* révision
* nb de packages installés
* mieux date dernier apt update
* figet_cpu, remplacement wc -l par grep -c
* plus de dépendances wc
* figet_battery: voltage, conso si 0
* fi_disk, correction si pas de fichier resume (absence normale?)
## 1.28.0 28/09/2017