getInfo 1.30.0

This commit is contained in:
kyodev 2017-10-01 06:09:57 +02:00
parent 93be0f18e6
commit da1b78b485
2 changed files with 67 additions and 58 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
version=1.29.0
date="29/09/2017"
version=1.30.0
date="30/09/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
script="getInfo"
@ -158,9 +158,9 @@ f__user(){ # 30/08/2017-4
if [ "$SUDO_USER" ] && [ "$SUDO_USER" != "$root_login" ]; then
user_="$SUDO_USER";
elif grep -qv 'root' <<< "$(who)"; then
user_="$(grep -v 'root' <<< $(who) | head -n1 | cut -d ' ' -f1)";
user_="$(grep -v 'root' <<< $(who) | head -n1 | cut -d ' ' -f1)"; # grep -v 'root' <<< $(who) | awk 'FNR==1{print $1}'
elif grep -q 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab; then
user_="$(grep 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | head -n1 | cut -d' ' -f2)";
user_="$(grep 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | head -n1 | cut -d' ' -f2)"; # grep 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | awk 'FNR==1{print $2}
fi
fi
if [ -z "$user_" ]; then return 1; fi
@ -291,7 +291,6 @@ 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 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 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
@ -375,18 +374,15 @@ fi_dmesg(){ # root only, si $1=dmesg rapport dmesg only # 27/09/2017
echo -e "$text" >> "$fileOutput"
}
fi_gpu(){ # 25/09/2017
fi_gpu(){ # 30/09/2017
local slotGraphCards graphCards openGl resolutions logXorg text
# graphCards="$(lspci -nnk | grep -iEA 3 'vga|display|3d')"
# graphCards="$(lspci -nnv | grep -iEA 13 '^[0-9]+.*vga|display|3d')"
slotGraphCards="$(lspci | grep -iE 'vga|display|3d' | sed -En 's/^([0-9.:]+).*$/\1/gp')"
for i in $slotGraphCards; do
graphCards+='```\n'
graphCards+="$(lspci -s $i -nnv)\n"
graphCards+='```\n'
graphCards+="$(lspci -s $i -nnv)"$'\n'
done
unset i
graphCards="$(echo -e "$graphCards")"
[ "$(which glxinfo)" ] && openGl="$(glxinfo | grep 'OpenGL version')"
resolutions="$(xrandr --query | grep '^ *[0-9]' | head -n 10)"
logXorg="$(grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)' /var/log/Xorg.*.log /home/$user_/.local/share/xorg/Xorg.*.log 2>/dev/null)"
@ -399,7 +395,9 @@ fi_gpu(){ # 25/09/2017
figet_resolution
text+="**résolution: $resolution** \n\n"
text+='``'"lspci -nnv | grep -iEA 13 'vga|display|3d'"'`` \n'
text+="$graphCards \n\n"
text+='```\n'
text+="$graphCards \n"
text+='```\n\n'
if [ "$openGl" ]; then
text+='``'"glxinfo | grep 'OpenGL version'"'`` \n'
text+='```\n'
@ -515,30 +513,30 @@ fi_nonFree(){ # 25/09/2017
echo -e "$text" >> "$fileOutput"
}
fi_reseau(){ # 25/09/2017
fi_reseau(){ # 30/09/2017
local slotNetCards netCards ip_a iwconfig interfaces route resolv text liste_canaux_wifi
# netCards="$(lspci -nnk | grep -iEA 5 'network|ethernet')"
# netCards="$(lspci -nnv | grep -iEA 15 'network|ethernet')"
slotNetCards="$(lspci | grep -iE 'network|ethernet' | sed -En 's/^([0-9.:]+).*$/\1/gp')"
for i in $slotNetCards; do
netCards+='```\n'
netCards+="$(lspci -s $i -nnv)\n"
netCards+='```\n'
netCards+="$(lspci -s $i -nnv)"$'\n'
done
unset i
netCards="$(echo -e "$netCards")"
ip_a="$(ip a | sed '/inet6.*scope global/d; /link\/ether/d; /valid_lft/d')" # filtre sur inet6 & scope global & adr MAC & bail?
if [ "$(which iwlist)" ]; then #paquet wireless-tools requis
iwconfig="$(iwconfig 2>&1 | grep -v 'no wireless extensions' | grep -v '^$')"
fi
interfaces="$(sed '/^#/d;s/^wpa-psk [[:graph:]]\+/wpa-psk <WPA key removed>/;/^$/d;s/\(.*\)/\1 /' /etc/network/interfaces)"
interfaces="$(grep -Evr '#|^$' /etc/network/interfaces* 2>/dev/null)"
interfaces="$(sed -E 's/wpa-psk [[:graph:]]+/wpa-psk <WPA key removed>/; s/:/: /' <<< $interfaces )"
route="$(ip route show)"
resolv="$(grep -vE '#|^$' /etc/resolv.conf)"
netmgrpaths=("/usr/sbin/NetworkManager" "/usr/sbin/wicd" "/usr/sbin/connmand") # thanks wireless-info
netmgrnames=("NetworkManager" "Wicd" "ConnMan") # thanks wireless-info
for i in "${!netmgrpaths[@]}"; do
if [ -f "${netmgrpaths[$i]}" ]; then netmgrinst+="${netmgrnames[$i]}"; fi
if [ "$(ps -ef | grep -c ${netmgrpaths[$i]})" -ge 2 ]; then netmgrrun+="$(ps -ef | grep -o "${netmgrpaths[$i]}.*$" | head -n 1)"; fi
if [ "$(ps -ef | grep -c ${netmgrpaths[$i]})" -ge 2 ]; then
netmgrrun+="$(ps -ef | grep -o "${netmgrpaths[$i]}.*$" | head -n 1)"
fi
done
unset i
text="## réseau \n\n"
@ -563,7 +561,9 @@ fi_reseau(){ # 25/09/2017
text+='```\n\n'
text+="* l'IP publique peut être connue avec: "'`./getInfo --ip` ou `getInfo --ip` (script installé) \n\n'
text+='``'"lspci -nnv | grep -iEA 15 'network|ethernet"'`` \n'
text+="$netCards \n\n"
text+='```\n'
text+="$netCards \n"
text+='```\n\n'
text+="**ip address** (ipv6 lien local, pas d'adresses MAC) \n"
text+='```\n'
text+="$ip_a \n"
@ -574,7 +574,7 @@ fi_reseau(){ # 25/09/2017
text+="$iwconfig \n"
text+='```\n\n'
fi
text+='``cat /etc/network/interfaces`` \n'
text+='``'"grep -Evr '#|^$' /etc/network/interfaces*"'`` \n'
text+='```\n'
text+="$interfaces \n"
text+='```\n\n'
@ -604,14 +604,14 @@ fi_reseau(){ # 25/09/2017
echo -e "$text" >> "$fileOutput"
}
fi_sources(){ # 29/09/2017
fi_sources(){ # 30/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
local paquetBiz text
printf "."
sources="$(grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null)"
sources="$(sed 's/:deb/: deb/; s/ / /g' <<< $sources)"
@ -624,13 +624,12 @@ fi_sources(){ # 29/09/2017
printf "."
httpredir="$(grep 'httpredir' <<< $sources)"
upgradable="$(LC_ALL=C apt list --upgradable 2>/dev/null | sed 's/Listing...//' | grep -v '^$')"
[ "$upgradable" ] && nbUpgradable="$(grep -c '' <<< "$upgradable")"
[ "$upgradable" ] && nbUpgradable="$(grep -c '.' <<< "$upgradable")"
printf "."
dpkgArch="$(dpkg --print-architecture)"
paquetBiz="$(dpkg -l | grep -v '^i' | grep "$dpkgArch" | awk '{print $1, $2, $3}')"
paquetBiz="$(dpkg -l | grep -v '^i' | awk '{print $1, $2, $3}')"
###
text+="## sources list \n\n"
text+='``'"grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null"'`` \n'
text+='``'"grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null"'`` \n'
text+='```\n'
text+="$sources \n"
text+='```\n\n'
@ -694,21 +693,20 @@ fi_system_analyse(){ # 25/09/2017
echo -e "$text" >> "$fileOutput"
}
fi_systeme(){ # 28/09/2017
fi_systeme(){ # 30/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)"
bootImage="$(sed 's/root=[^ ]*//;s/[ ]\+/, /g' /proc/cmdline)"
initDaemon="$(ps -p1)" #? ps -ax | awk '$1==1' ou ps -p1 | awk '$1==1'
initDaemon="$(ps -p1 | awk 'FNR==2 {print $4}')" #? ps -ax | awk '$1==1' ou ps -p1 | awk '$1==1'
xorg="$XDG_SESSION_TYPE"
if [ -z "$xorg" ]; then
[ "$(ps -ef | grep -c 'wayland')" -gt 1 ] && xorg="wayland" || xorg="indéterminé"
fi
shells="$(grep -v "^#" /etc/shells | sed 's/\/bin\///' | tr '\n' ' ')"
lastboot="$(last -R -n 1 --time-format iso reboot | head -n 1 | grep -o '[0-9:T+-]*' | sed 's/T/ /')"
uptime="$(uptime -p)"
uptime="$(sed 's/up/depuis/; s/week/semaine/; s/weeks/semaines/; s/days/jours/; s/day/jour/; s/hour[s]*/h/; s/minute[s]*/mn/' <<< $uptime)"
lastboot="$(last -n 1 --time-format iso reboot | awk 'FNR==1 {sub(/T/," ",$5);print $5}')"
uptime="$(uptime -p | sed 's/up/depuis/; s/week/semaine/; s/weeks/semaines/; s/days/jours/; s/day/jour/; s/hour[s]*/h/; s/minute[s]*/mn/')"
###
text="## système \n\n"
text+="| | | \n"
@ -726,13 +724,7 @@ fi_systeme(){ # 28/09/2017
[ "$description" ] && text+="description: $description \n"
text+="uname: $uname \n"
text+="$bootImage \n"
if grep -qi systemd <<< "$initDaemon"; then
text+="démon d'initialisation: systemd \n"
else
text+="démon d'initialisation: **non systemd** \n"
# ps ax | awk '$1=="1"{print $5}') affiche le 1er process daemon init, normalement /sbin/init
text+="$(sed -En 's/^.* (\/.*$)/\1/p' <<< $(ls -l $(ps ax | awk '$1=="1"{print $5}'))) \n"
fi
text+="démon d'initialisation: $initDaemon \n"
figet_resolution
text+="résolution: $resolution \n"
text+="serveur d'affichage: $xorg \n"
@ -774,7 +766,7 @@ fi_usb(){ # 25/09/2017
}
# informations batterie(s), assigne $batt_nb $batt_detail
figet_battery(){ # 29/09/2017
figet_battery(){ # 30/09/2017
local batt_alim batt_unit batt_capa_design batt_capa_full batt_capa_now batt_conso
local batt_voltage batt_status batt_sn batt_cycle tempo batt_restant
batt_nb="$(ls /sys/class/power_supply/ | grep -c 'BAT')"
@ -841,20 +833,19 @@ figet_battery(){ # 29/09/2017
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"
[ "$batt_batt_sn" ] && batt_detail+="n° série:$batt_sn"$'\n'
[ "$batt_cycle" != "0" ] && batt_detail+="$batt_cycle cycles"$'\n' || batt_detail+=$'\n'
[ "$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"
[ "$batt_sante" ] && batt_detail+="$batt_sante % (indicateur santé)"$'\n'
[ "$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 # 29/09/2017
figet_cpu() { # thanks neofetch, assigne $cpu # 30/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"
@ -876,7 +867,7 @@ figet_cpu() { # thanks neofetch, assigne $cpu # 29/09/2017
temp="[${temp/${temp: -1}}.${temp: -1}°C]"
fi
# Show/hide hyperthreaded cores
cores="$(grep "^core id" /proc/cpuinfo | sort -u | grep -c '')" # physique
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
@ -917,21 +908,21 @@ 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(){ # 28/09/2017
figet_disk(){ # 30/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
unset disk_hotplug disk_fix part_fix part_hotplug
disk_detail="disque: vendeur modèle n° serie révision\n"
disk_detail="disque: vendeur modèle n° serie révision"$'\n'
for idisk in $(grep -v 'loop' <<< $(ls /sys/block/)); do
disk_detail+="$idisk: $(sed -n '2p' <<< "$(lsblk -o VENDOR,MODEL,SERIAL,REV /dev/$idisk)") \n"
disk_detail+="$idisk: $(sed -n '2p' <<< "$(lsblk -o VENDOR,MODEL,SERIAL,REV /dev/$idisk)")"$'\n'
if [ "$(sed -n '2p' <<< $(lsblk -o HOTPLUG /dev/$idisk) | xargs)" == "1" ]; then
disk_hotplug+="$idisk "
else
disk_fix+="$idisk " # "sda sdb sdc"
fi
done
disk_detail="$(echo -e $disk_detail)"
#echo "$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) 2>/dev/null | grep '/')"
@ -947,10 +938,14 @@ figet_disk(){ # 28/09/2017
part_fix_tot="espace disque des partitions fixes montées (total, utilisé, dispo): "
part_fix_tot+="$(df -h --total --output=size,used,avail $(printf '/dev/%s ' $part_fix) | tail -n-1 | xargs)"
part_fix_tot="$(sed 's/G/Go/g; s/M/Mo/g; s/K/ko/g' <<< $part_fix_tot)"
disk_ata="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^ata/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/')"
disk_usb="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^usb/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/')"
disk_mmc="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^mmc/!d; /part/d; /\/mmcblk/!d; s/^.*\(mmcblk..*\)$/\1/')"
disk_nvme="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^nvme/!d; /part/d; /\/nvme/!d; s/^.*\(nvme...*\)$/\1/')"
disk_ata="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }')"
disk_ata="$(sed '/^ata/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/' <<< $disk_ata | tr '\n' ' ')"
disk_usb="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }')"
disk_usb="$(sed '/^usb/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/' <<< $disk_usb | tr '\n' ' ')"
disk_mmc="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }')"
disk_mmc="$(sed '/^mmc/!d; /part/d; /\/mmcblk/!d; s/^.*\(mmcblk..*\)$/\1/' <<< $disk_mmc | tr '\n' ' ')"
disk_nvme="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }')"
disk_nvme="$(sed '/^nvme/!d; /part/d; /\/nvme/!d; s/^.*\(nvme...*\)$/\1/' <<< $disk_nvme | tr '\n' ' ')"
[ "$disk_ata" ] || disk_ata="-"
[ "$disk_usb" ] || disk_usb="-"
[ "$disk_mmc" ] || disk_mmc="-"
@ -1001,13 +996,13 @@ figet_gpu() { # thanks neofetch, assigne $gpu
# assigne $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type
# $ifnames, $ifnames_type, $mac_address, mac_address_type
figet_ip() { # 23/09/2017
figet_ip() { # 30/09/2017
[ -z "$(which ip)" ] && return 1
ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print " ",$4,"(",$2,")"}')"
ip_local_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)"
gateway="$(LC_ALL=C ip -4 route | awk '/default via/ {print " ",$3,"(",$5,")"}'; LC_ALL=C ip -6 route | awk '/default via/ {print " ",$3,"(",$5,")"}')"
gateway_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $gateway)"
gateway_one="$(head -n 1 <<< $gateway | awk '{print " ",$1}')"
gateway_one="$(awk 'FNR==1 {print " ",$1}' <<< $gateway)"
for ifn in $(ls /sys/class/net/) ; do
[ "$ifn" != "lo" ] && ifnames+=" $ifn"$'\n' # $'\n' -> newline ou $'\x0a' ou $'\012'
[ "$ifn" != "lo" ] && mac_address+=" $ifn: $(cat /sys/class/net/$ifn/address)"$'\n'

View File

@ -5,9 +5,23 @@
* 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)
* prévoir exécution en root si terminal
* option erreur pour f__info
* réorganiser en famille à afficher avec option de choix possible
* swap
* revoir figet_ip, gateway
* éviter 169.254.10.12 / 169.254.10.12/16 ( enp3s0 ) (ethernet)
169.254.0.0/16 adresses locales autoconfigurées (APIPA) RFC 3927 169.254.0.0 à 169.254.255.255
https://fr.wikipedia.org/wiki/Automatic_Private_Internet_Protocol_Addressing
---
* f__wget_test
* comment f__user getInfo
## 1.30.0 30/09/2017
* révision fi_systeme, figet_ip, figet_disk, fi_reseau, fi_gpu, figet_battery
* fix mineur figet_cpu, fi_sources: comptage ligne avec grep si 0 ligne
* fi_sources plus de critère d'architecture dans les paquetsBiz
## 1.29.0 29/09/2017