This commit is contained in:
kyodev 2017-08-30 22:46:26 +02:00
parent d84d50ed1f
commit c5a35ee4af
2 changed files with 183 additions and 157 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
version=1.8.0
version=1.9.0
date="30/08/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
@ -88,43 +88,43 @@ f__log(){ # v08/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(){ # v17/08/2017-3
local dependsMissing packagesMissing
unset debOnlyPackages debOnlyPresents
for i in $1; do
local command="$(cut -d '>' -f 1 <<< $i)"
local package="$(cut -d '>' -f 2 <<< $i)"
if [ "$2" == "debOnly" ]; then
if [ "$(which dpkg)" ]; then # package only et debian
LC_ALL=C dpkg --get-selections | grep -qE "^$package[[:space:]]+install" \
&& debOnlyPresents+="$package " || debOnlyPackages+="$package "
else f__error "dpkg n'est pas disponible sur ce système"; fi
elif [ -z "$(which $command)" ]; then
dependsMissing+="$command "
packagesMissing+="$package "
fi
done
[ "$debOnlyPackages" ] && debOnlyPackages="$(xargs <<< $debOnlyPackages)" # trim début & fin
[ "$debOnlyPresents" ] && debOnlyPresents="$(xargs <<< $debOnlyPresents)" # trim début & fin
[ "$debOnlyPackages" ] && return 1
[ "$debOnlyPresents" ] && return 0
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
f__requis(){ # v30/08/2017-3
local dependsMissing packagesMissing command package
unset debOnlyPackages debOnlyPresents
for i in $1; do
command="$(cut -d '>' -f 1 <<< $i)"
package="$(cut -d '>' -f 2 <<< $i)"
if [ "$2" == "debOnly" ]; then
if [ "$(which dpkg)" ]; then # package only et debian
LC_ALL=C dpkg --get-selections | grep -qE "^$package[[:space:]]+install" \
&& debOnlyPresents+="$package " || debOnlyPackages+="$package "
else f__error "dpkg n'est pas disponible sur ce système"; fi
elif [ -z "$(which $command)" ]; then
dependsMissing+="$command "
packagesMissing+="$package "
fi
}
done
[ "$debOnlyPackages" ] && debOnlyPackages="$(xargs <<< $debOnlyPackages)" # trim début & fin
[ "$debOnlyPresents" ] && debOnlyPresents="$(xargs <<< $debOnlyPresents)" # trim début & fin
[ "$debOnlyPackages" ] && return 1
[ "$debOnlyPresents" ] && return 0
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
fi
}
# user ayant initié la session graphique, assigne $user_
# return 1 sur échec identification user, return 2 sur absence home/
# gestion variable environnement user avec: USER_INSTALL=user script
f__user(){ # v21/08/2017-4
f__user(){ # v30/08/2017-4
if [ "$USER_INSTALL" ]; then # user_ via variable environnement, moyen d'injecter root
user_="$USER_INSTALL";
return 0
fi
local user_id test
local root_login="$(grep ':0:' /etc/passwd | cut -d':' -f1)" || local root_login="root"
local user_id test root_login
root_login="$(grep ':0:' /etc/passwd | cut -d':' -f1)" || root_login="root"
if [ "$SUDO_UID" ]; then
user_id="$SUDO_UID";
elif grep -qEo '[0-9]+' <<< "$XDG_RUNTIME_DIR" ; then
@ -151,9 +151,10 @@ f__user(){ # v21/08/2017-4
# test wget, $1 url à tester, sortie script, sur erreur ou retour à la normale
# si $2=print affiche url testée & entêtes http & location (si présente) et sortie normale fonction
f__wget_test(){ #v28/08/2017
local file_test_wget="/tmp/testWget-$RANDOM"
wget -Sq --tries=1 --timeout=10 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget" || local retourWget="$?"
f__wget_test(){ # v30/08/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="$?"
[ "$retourWget" == 1 ] && retourWget="code erreur générique"
[ "$retourWget" == 2 ] && retourWget="parse erreur (ligne de commande?)"
[ "$retourWget" == 3 ] && retourWget="erreur Entrée/sortie fichier"
@ -162,8 +163,8 @@ f__wget_test(){ #v28/08/2017
[ "$retourWget" == 6 ] && retourWget="défaut authentification"
[ "$retourWget" == 7 ] && retourWget="erreur de protocole"
[ "$retourWget" == 8 ] && retourWget="réponse serveur en erreur"
local retourHttp="$(grep -i 'HTTP/' "$file_test_wget" | tr -d '\n' | xargs)"
local location="$(grep -i 'location' $file_test_wget | xargs)"
retourHttp="$(grep -i 'HTTP/' "$file_test_wget" | tr -d '\n' | xargs)"
location="$(grep -i 'location' $file_test_wget | xargs)"
if [ "$2" == "print" ] && [ -z "$retourWget" ]; then
echo -e "\n$1"
echo "$GREEN$retourHttp$COLOR"
@ -218,10 +219,10 @@ fi__context(){
}
# $1 oui|non, $2 message question, return 0 pour défaut, 1 sinon
fi__dialog_oui_non () {
fi__dialog_oui_non () { # 30/08/2017
[[ $1 =~ ^oui$|^non$ ]] || f__error "dialog_oui_non, erreur appel"
local reply
[ "$1" == "oui" ] && local defaut="oui" || local defaut="non"
local reply defaut
[ "$1" == "oui" ] && defaut="oui" || defaut="non"
case $context_appli in
terminal )
[ "$defaut" == "oui" ] && printf "$2 [O/n] " || printf "$2 [o/N] "
@ -240,13 +241,14 @@ fi__dialog_oui_non () {
shopt -u nocasematch
}
fi_cpu(){
local cpu_addr="$(sed -n 's/^address sizes.*: \(.*\)$/\1/p' /proc/cpuinfo | head -n 1)"
local cpu_bogomips="$(sed -n 's/^bogomips.*: \(.*\)$/\1/p' /proc/cpuinfo | head -n 1)"
local cpu_flags="$(sed -n 's/^flags.*: \(.*\)$/\1/p;' /proc/cpuinfo | head -n 1)"
local memsys="$(free -ht)"
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)"
memsys="$(free -ht)"
###
local text="## processeur / mémoire \n\n"
text="## processeur / mémoire \n\n"
text+='```\n'
figet_cpu; text+="CPU: $cpu \n"
text+="adressage: $cpu_addr \n"
@ -261,19 +263,20 @@ fi_cpu(){
echo -e "$text" >> "$fileOutput"
}
fi_disk(){
local fstab="$(grep -vE '#|^$' /etc/fstab)"
local disk_lsblk="$(lsblk -fi -o +SIZE -o +OWNER)"
local utilDisk="$(df -h --output=source,target,fstype,size,used,avail,pcent --exclude=tmpfs --exclude=devtmpfs --exclude=devtmpfs | grep -Ev "devpts|none|proc|sys|tmpfs|udev")"
local resume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume)"
local idSwap="$(grep -vE '#|^$' /etc/fstab | grep 'swap' | grep 'UUID' | sed -E 's/^UUID=([0-9a-Z-]*).*/\1/')"
local idResume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume | grep 'RESUME=' | grep 'UUID' | sed -E 's/^.*UUID=([0-9a-Z-]*).*/\1/')"
local diskAta="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^ata/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/')"
local diskUsb="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^usb/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/')"
local diskMmc="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^mmc/!d; /part/d; /\/mmcblk/!d; s/^.*\(mmcblk..*\)$/\1/')"
local diskNvme="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^nvme/!d; /part/d; /\/nvme/!d; s/^.*\(nvme...*\)$/\1/')"
fi_disk(){ # 30/08/2017
local fstab disk_lsblk utilDisk resume idSwap idResume diskAta diskUsb diskMmc diskNvme text
fstab="$(grep -vE '#|^$' /etc/fstab)"
disk_lsblk="$(lsblk -fi -o +SIZE -o +OWNER)"
utilDisk="$(df -h --output=source,target,fstype,size,used,avail,pcent --exclude=tmpfs --exclude=devtmpfs --exclude=devtmpfs | grep -Ev "devpts|none|proc|sys|tmpfs|udev")"
resume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume)"
idSwap="$(grep -vE '#|^$' /etc/fstab | grep 'swap' | grep 'UUID' | sed -E 's/^UUID=([0-9a-Z-]*).*/\1/')"
idResume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume | grep 'RESUME=' | grep 'UUID' | sed -E 's/^.*UUID=([0-9a-Z-]*).*/\1/')"
diskAta="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^ata/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/')"
diskUsb="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^usb/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/')"
diskMmc="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^mmc/!d; /part/d; /\/mmcblk/!d; s/^.*\(mmcblk..*\)$/\1/')"
diskNvme="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^nvme/!d; /part/d; /\/nvme/!d; s/^.*\(nvme...*\)$/\1/')"
###
local text="## disque(s) \n\n"
text="## disque(s) \n\n"
figet_disk; text+="disque(s): $disk \n\n"
text+="**grep -vE '#|^$' /etc/fstab** (fstab) \n"
text+='```\n'
@ -302,8 +305,9 @@ fi_disk(){
echo -e "$text" >> "$fileOutput"
}
fi_dmesg(){ # root only, si $1=dmesg rapport dmesg only
local text="## dmesg (erreur, warning ou critique) \n\n"
fi_dmesg(){ # root only, si $1=dmesg rapport dmesg only # 30/08/2017
local text dmesg_err dmesg_warn dmesg_crit
text="## dmesg (erreur, warning ou critique) \n\n"
if [ "$EUID" -ne 0 ]; then
if [ "$1" == "dmesg" ]; then
f__info "$RED""dmesg ne peut être affiché qu'avec les droits root"
@ -314,9 +318,9 @@ fi_dmesg(){ # root only, si $1=dmesg rapport dmesg only
return 0
fi
###
local dmesg_err="$(dmesg -l err)"
local dmesg_warn="$(dmesg -l warn)"
local dmesg_crit="$(dmesg -l crit)"
dmesg_err="$(dmesg -l err)"
dmesg_warn="$(dmesg -l warn)"
dmesg_crit="$(dmesg -l crit)"
if [ "$dmesg_err" ]; then
text+="**dmesg -l err** (erreur) \n"
text+='```\n'
@ -347,14 +351,15 @@ fi_dmesg(){ # root only, si $1=dmesg rapport dmesg only
echo -e "$text" >> "$fileOutput"
}
fi_gpu(){
# local graphCards="$(lspci -nnk | grep -iEA 3 'vga|display|3d')"
local graphCards="$(lspci -nnvvv | grep -iEA 13 '^[0-9]+.*vga|display|3d')"
[ "$(which glxinfo)" ] && local openGl="$(glxinfo | grep 'OpenGL version string:')"
local resolutions="$(xrandr --query | grep '^ *[0-9]' | head -n 10)"
local extraitXorg="$(grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)' /var/log/Xorg.*.log /home/$user_/.local/share/xorg/Xorg.*.log 2>/dev/null)"
fi_gpu(){ # 30/08/2017
local graphCards openGl resolutions extraitXorg text
# graphCards="$(lspci -nnk | grep -iEA 3 'vga|display|3d')"
graphCards="$(lspci -nnvvv | grep -iEA 13 '^[0-9]+.*vga|display|3d')"
[ "$(which glxinfo)" ] && openGl="$(glxinfo | grep 'OpenGL version string:')"
resolutions="$(xrandr --query | grep '^ *[0-9]' | head -n 10)"
extraitXorg="$(grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)' /var/log/Xorg.*.log /home/$user_/.local/share/xorg/Xorg.*.log 2>/dev/null)"
###
local text="## graphisme \n\n"
text="## graphisme \n\n"
figet_gpu; text+="**GPU: $gpu** \n"
figet_resolution; text+="**résolution: $resolution** \n\n"
text+="**lspci -nnvvv | grep -iEA 13 '^[0-9]+.*vga|display|3d'** (matériel) \n"
@ -380,13 +385,14 @@ fi_gpu(){
echo -e "$text" >> "$fileOutput"
}
fi_localisation(){
local locale="$(grep -vE '#|^$' /etc/default/locale)"
local timezone="$(cat /etc/timezone)"
local keymap="$(setxkbmap -query)"
local keyboard="$(grep -vE '#|^$' /etc/default/keyboard)"
fi_localisation(){ # 30/08/2017
local locale timezone keymap keyboard text
locale="$(grep -vE '#|^$' /etc/default/locale)"
timezone="$(cat /etc/timezone)"
keymap="$(setxkbmap -query)"
keyboard="$(grep -vE '#|^$' /etc/default/keyboard)"
###
local text="## localisation \n\n"
text="## localisation \n\n"
text+="**grep -vE '#|^$' /etc/default/locale** \n"
text+='```\n'
text+="$locale \n"
@ -406,12 +412,13 @@ fi_localisation(){
echo -e "$text" >> "$fileOutput"
}
fi_nm(){
fi_nm(){ # 30/08/2017
[ -x "$(which nmcli)" ] || return 0 # root sur autre que debian?
local nm_etat="$(grep -vE '#|^$' /var/lib/NetworkManager/NetworkManager.state)"
local nm_conf="$(grep -vE '#|^$' /etc/NetworkManager/NetworkManager.conf)"
local nm_etat nm_conf text
nm_etat="$(grep -vE '#|^$' /var/lib/NetworkManager/NetworkManager.state)"
nm_conf="$(grep -vE '#|^$' /etc/NetworkManager/NetworkManager.conf)"
###
local text="## Network Manager \n\n"
text="## Network Manager \n\n"
text+="**grep -vE '#|^$' /var/lib/NetworkManager/NetworkManager.state** \n"
text+='```\n'
text+="$nm_etat \n"
@ -423,12 +430,13 @@ fi_nm(){
echo -e "$text" >> "$fileOutput"
}
fi_nm_wifis(){
fi_nm_wifis(){ # 30/08/2017
[ -x "$(which nmcli)" ] && [ -z "$1" ] || return 0
local nm_wifis="$(nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY device wifi list)"
local nm_connected="$(LC_ALL=C nmcli -f SSID,ACTIVE,IN-USE device wifi list | grep -E 'yes[[:space:]]+\*' | awk '{print $1}')" # non utilisé
local nm_wifis nm_connected text
nm_wifis="$(nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY device wifi list)"
nm_connected="$(LC_ALL=C nmcli -f SSID,ACTIVE,IN-USE device wifi list | grep -E 'yes[[:space:]]+\*' | awk '{print $1}')" # non utilisé
###
local text="## wifis à proximité \n\n"
text="## wifis à proximité \n\n"
text+="**nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY device wifi list** \n"
text+='```\n'
text+="$nm_wifis \n"
@ -436,25 +444,26 @@ fi_nm_wifis(){
echo -e "$text" >> "$fileOutput"
}
fi_reseau(){
local netcards="$(lspci -nnk | grep -iEA 3 'network|ethernet')"
# local netcards="$(lspci -nnvvv | grep -iEA 12 'network|ethernet')"
local ip_a="$(ip a | sed '/inet6.*scope global/d; /link\/ether/d; /valid_lft/d')" # filtre sur inet6 & scope global & adr MAC & bail?
fi_reseau(){ # 30/08/2017
local netcards ip_a iwconfig interfaces route resolv text liste_canaux_wifi
netcards="$(lspci -nnk | grep -iEA 3 'network|ethernet')"
# netcards="$(lspci -nnvvv | grep -iEA 12 'network|ethernet')"
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
local iwconfig="$(iwconfig 2>&1 | grep -v 'no wireless extensions' | grep -v '^$')"
iwconfig="$(iwconfig 2>&1 | grep -v 'no wireless extensions' | grep -v '^$')"
fi
local interfaces="$(sed '/^#/d;s/^wpa-psk [[:graph:]]\+/wpa-psk <WPA key removed>/;/^$/d;s/\(.*\)/\1 /' /etc/network/interfaces)"
local route="$(ip route show)"
local resolv="$(grep -vE '#|^$' /etc/resolv.conf)"
interfaces="$(sed '/^#/d;s/^wpa-psk [[:graph:]]\+/wpa-psk <WPA key removed>/;/^$/d;s/\(.*\)/\1 /' /etc/network/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 ii in "${!netmgrpaths[@]}"; do
if [ -f "${netmgrpaths[$ii]}" ]; then netmgrinst+="${netmgrnames[$ii]}"; fi
if [ "$(ps -ef | grep -c ${netmgrpaths[$ii]})" -ge 2 ]; then netmgrrun+="$(ps -ef | grep -o "${netmgrpaths[$ii]}.*$" | head -n 1)"; fi
done
local text="## réseau \n\n"
text="## réseau \n\n"
if [ "$(which iwlist)" ]; then # liste canaux wifi; paquet wireless-tools requis
local liste_canaux_wifi="$(iwlist chan 2>&1 | grep -vE 'no frequency information|^$')"
liste_canaux_wifi="$(iwlist chan 2>&1 | grep -vE 'no frequency information|^$')"
fi
###
figet_ip; text+="**IP locale(s):** \n"
@ -513,23 +522,24 @@ fi_reseau(){
echo -e "$text" >> "$fileOutput"
}
fi_sources(){
fi_sources(){ # 30/08/2017
[ "$(which apt)" ] || return 0 # retour si pas d'apt ? et aptitude...????
local sources dateMaj apt autoremove paquetToRemove httpredir upgradable dpkgArch paquetBiz text
printf "."
local sources="$(grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null | sed 's/ / /g; s/:/: /')"
local dateMaj="$(date -r /var/cache/apt/archives/)"
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/)"
printf "."
local apt="$(LC_ALL=C apt-get autoremove --simulate)"
local autoremove="$(grep -c 'Remv' <<< $apt)"
local paquetToRemove="$(grep 'Remv' <<< $apt | sed 's/Remv //; s/\[[0-9.-]*\]//' | tr '\n' ' ')"
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 "."
local httpredir="$(grep 'httpredir' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null)"
local upgradable="$(LC_ALL=C apt list --upgradable 2>/dev/null | sed 's/Listing...//' | grep -v '^$')"
httpredir="$(grep 'httpredir' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null)"
upgradable="$(LC_ALL=C apt list --upgradable 2>/dev/null | sed 's/Listing...//' | grep -v '^$')"
printf "."
local dpkgArch="$(dpkg --print-architecture)"
local paquetBiz="$(dpkg -l | grep -v '^i' | grep "$dpkgArch" | awk '{print $1, $2, $3}')"
dpkgArch="$(dpkg --print-architecture)"
paquetBiz="$(dpkg -l | grep -v '^i' | grep "$dpkgArch" | awk '{print $1, $2, $3}')"
###
local text+="## sources list \n\n"
text+="## sources list \n\n"
text+="**grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null** \n"
text+='```\n'
text+="$sources \n"
@ -564,11 +574,12 @@ fi_sources(){
echo -e "$text" >> "$fileOutput"
}
fi_ssid(){ # affiche configurations ssid
fi_ssid(){ # affiche configurations ssid # 30/08/2017
[ "$(which nmcli)" ] || f__error "il manque NetworkManager"
[ $EUID -eq 0 ] || f__error "il manque les droits root"
local nm_ssid="$(grep -vE '#|^$' /etc/NetworkManager/system-connections/*)"
local text="## configuration(s) ssid networkmanager \n\n"
local nm_ssid text
nm_ssid="$(grep -vE '#|^$' /etc/NetworkManager/system-connections/*)"
text="## configuration(s) ssid networkmanager \n\n"
###
f__info="$RED""Attention, la clé du réseau wifi est visible $COLOR""aucun rapport n'a été créé"
text+='```\n'
@ -577,12 +588,13 @@ fi_ssid(){ # affiche configurations ssid
echo -e "$text"
}
fi_system_analyse(){
fi_system_analyse(){ # 30/08/2017
[ -x "$(which systemd-analyze)" ] || return 0 # pas systemd
local bootTime="$(systemd-analyze time)"
local bootBlame="$(systemd-analyze blame | head -n 20)"
local bootTime bootBlame text
bootTime="$(systemd-analyze time)"
bootBlame="$(systemd-analyze blame | head -n 20)"
###
local text="## analyse boot \n\n"
text="## analyse boot \n\n"
text+="$(sed 's/Startup finished in /**durée de boot:** /; s/userspace/espace utilisateur/; s/= \(.*\)$/= **\1**/' <<< $bootTime) \n\n"
text+="**systemd-analyze blame | head -n 20** \n"
text+='```\n'
@ -591,21 +603,22 @@ fi_system_analyse(){
echo -e "$text" >> "$fileOutput"
}
fi_systeme(){
[ -d /sys/firmware/efi ] && local mbr="**EFI boot**" || local mbr="**Legacy boot**"
[ -x "/usr/bin/lsb_release" ] && local description="$(lsb_release -ds)" #dépend de apt install lsb-release, sur debian, en standard, juste : lsb-base
local uname="$(uname -rmo)"
local bootImage="$(sed 's/root=[^ ]*//;s/[ ]\+/, /g' /proc/cmdline)"
local xorg="$XDG_SESSION_TYPE"
fi_systeme(){ # 30/08/2017
local mbr description uname bootImage xorg shells lastboot uptime text
[ -d /sys/firmware/efi ] && mbr="**EFI boot**" || mbr="**Legacy boot**"
[ -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)"
xorg="$XDG_SESSION_TYPE"
if [ -z "$xorg" ]; then
[ "$(ps -ef | grep -c 'wayland')" -gt 1 ] && xorg="wayland" || xorg="indéterminé"
fi
local shells="$(grep -v "^#" /etc/shells | sed 's/\/bin\///' | tr '\n' ' ')"
local lastboot="$(last -R -n 1 --time-format iso reboot | head -n 1 | grep -o '[0-9:T+-]*' | sed 's/T/ /')"
local uptime="$(uptime -p)"
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)"
###
local text="## système \n\n"
text="## système \n\n"
figet_cpu; text+="CPU: **$cpu** \n"
figet_gpu; text+="GPU: **$gpu** \n"
text+="type de boot: $mbr \n"
@ -629,11 +642,12 @@ fi_systeme(){
echo -e "$text" >> "$fileOutput"
}
fi_usb(){
local lsusb="$(lsusb)"
local lsusb_t="$(lsusb -t)"
fi_usb(){ # 30/08/2017
local lsusb lsusb_t text
lsusb="$(lsusb)"
lsusb_t="$(lsusb -t)"
###
local text="## périphériques USB \n\n"
text="## périphériques USB \n\n"
text+="**lsusb** \n"
text+='```\n'
text+="$lsusb \n"
@ -645,10 +659,11 @@ fi_usb(){
echo -e "$text" >> "$fileOutput"
}
figet_battery() { # thanks neofetch, assigne $battery
figet_battery() { # thanks neofetch, assigne $battery # 30/08/2017
local capacity status
for bat in "/sys/class/power_supply/BAT"*; do
local capacity="$(< "${bat}/capacity")"
local status="$(< "${bat}/status")"
capacity="$(< "${bat}/capacity")"
status="$(< "${bat}/status")"
# Fix for bash on Windows 10 which includes /proc files for battery usage despite there not being a battery installed.
[[ -z "$capacity" ]] && return
battery+="${capacity}% [${status}]"
@ -657,19 +672,20 @@ figet_battery() { # thanks neofetch, assigne $battery
[[ "$battery_state" ]] && battery+=" En charge"
}
figet_cpu() { # thanks neofetch, assigne $cpu
figet_cpu() { # thanks neofetch, assigne $cpu # 30/08/2017
local speed_dir temp_dir speedMin speed speedMin speed temp cores
cpu="$(awk -F ': | @' '/model name|Processor/ {printf $2; exit}' /proc/cpuinfo)"
local speed_dir="/sys/devices/system/cpu/cpu0/cpufreq"
local temp_dir="/sys/class/hwmon/hwmon0/temp1_input"
speed_dir="/sys/devices/system/cpu/cpu0/cpufreq"
temp_dir="/sys/class/hwmon/hwmon0/temp1_input"
# Get cpu speed
if [[ -d "$speed_dir" ]]; then
local speedMin="$(< "${speed_dir}/scaling_min_freq")"
local speed="$(< "${speed_dir}/scaling_max_freq")"
speedMin="$(< "${speed_dir}/scaling_min_freq")"
speed="$(< "${speed_dir}/scaling_max_freq")"
speed="$((speed / 100000))"
local speedMin="$((speedMin / 100000))"
speedMin="$((speedMin / 100000))"
else
local speed="$(awk -F ': |\\.' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)"
local speed="$((speed / 100))"
speed="$(awk -F ': |\\.' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)"
speed="$((speed / 100))"
fi
# Get cpu temp
if [ -f "$temp_dir" ]; then
@ -717,16 +733,17 @@ figet_de() { # thanks neofetch, assigne $de
esac
}
figet_disk() { # thanks neofetch, assigne $disk
figet_disk() { # thanks neofetch, assigne $disk # 30/08/2017
local df_flags df_dir disk_used disk_total disk_total_per
# df flags
local df_flags="-h -l --total"
local df_dir="total"
df_flags="-h -l --total"
df_dir="total"
# Get the disk info
disk="$(df $df_flags | awk -v dir="$df_dir" '$0 ~ dir {print $2 ":" $3 ":" $5}')"
# Format the output
local disk_used="${disk#*:}"
disk_used="${disk#*:}"
disk_used="${disk_used%%:*}"
local disk_total="${disk%%:*}"
disk_total="${disk%%:*}"
disk_total_per="${disk#*:*:}"
# Put it all together
disk="${disk_used} / ${disk_total} (${disk_total_per})"
@ -784,7 +801,7 @@ figet_ip() { # $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_
ifname_type="$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname)"
}
figet_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # v18/08/2017
figet_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # 30/08/2017
list_ip4(){
ip_test+=" http://whatismyip.akamai.com"
@ -823,8 +840,8 @@ figet_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # v18/08/2017
}
unset ip_public
local dig_test
local ip_test
local dig_test ip_test
ip_test
if [ "$1" == "IPv4" ]; then
list_ip4_dig
list_ip4
@ -875,9 +892,10 @@ figet_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # v18/08/2017
fi
}
figet_memory() { # thanks neofetch, assigne $memory
figet_memory() { # thanks neofetch, assigne $memory # 30/08/2017
# MemUsed = Memtotal + Shmem - MemFree - Buffers - Cached - SReclaimable
# Source: https://github.com/KittyKatt/screenFetch/issues/386#issuecomment-249312716
local mem_used mem_total
while IFS=":" read -r a b; do
case "$a" in
"MemTotal") mem_used="$((mem_used+=${b/kB}))"; mem_total="${b/kB}" ;;
@ -885,19 +903,20 @@ figet_memory() { # thanks neofetch, assigne $memory
"MemFree" | "Buffers" | "Cached" | "SReclaimable") mem_used="$((mem_used-=${b/kB}))" ;;
esac
done < /proc/meminfo
local mem_used="$((mem_used / 1024))"
local mem_total="$((mem_total / 1024))"
mem_used="$((mem_used / 1024))"
mem_total="$((mem_total / 1024))"
memory="${mem_used}Mo / ${mem_total}Mo"
}
figet_modules(){ # thanks wireless-info for 'net', $1 net|video, assigne $exportText
figet_modules(){ # thanks wireless-info for 'net', $1 net|video, assigne $exportText # 30/08/2017
local MODMATCHES LSMODMATCHES modules
if [ "$1" == "net" ]; then
local MODMATCHES="(air|ar5|at7|ath[^3]?|b43|bcma|brcm|carl|ipw|iwl|ndis|r(818|8192[eu]|871|92su)|8(188|189|192|723|812)[acde][esu]|rt[23567]|rtl|ssb|wl|(cfg|mac)80211)"
local LSMODMATCHES="(wmi|(dell|ideapad)[-_]laptop)"
local modules="$(lsmod | grep -E "(^|[[:punct:] ])($MODMATCHES|$LSMODMATCHES)[^[:punct:] ]*([[:punct:] ]|$)")"
MODMATCHES="(air|ar5|at7|ath[^3]?|b43|bcma|brcm|carl|ipw|iwl|ndis|r(818|8192[eu]|871|92su)|8(188|189|192|723|812)[acde][esu]|rt[23567]|rtl|ssb|wl|(cfg|mac)80211)"
LSMODMATCHES="(wmi|(dell|ideapad)[-_]laptop)"
modules="$(lsmod | grep -E "(^|[[:punct:] ])($MODMATCHES|$LSMODMATCHES)[^[:punct:] ]*([[:punct:] ]|$)")"
exportText="\n### modules réseau\n\nliste non garantie complète \n"
elif [ "$1" == "video" ]; then
local modules="$(lsmod | grep -i -E 'amdgpu|ati|i915|nouveau|nvidia|radeon|video|gma')"
modules="$(lsmod | grep -i -E 'amdgpu|ati|i915|nouveau|nvidia|radeon|video|gma')"
exportText="\n### modules video\n\nliste non garantie complète \n"
fi
exportText+='```\n'
@ -952,11 +971,12 @@ fipaste(){
# à tester fipaste_curl_markdownshare "$fileOutput"
}
fipaste_curl_pastery(){ # $1 fichier à exporter, $2 durée de conservation en jour; $3 debug
fipaste_curl_pastery(){ # $1 fichier à exporter, $2 durée de conservation en jour; $3 debug # 30/08/2017
[ -e "$1" ] || f__error "fichier $1 inexistant"
local curl id
# curl -X POST "https://www.pastery.net/api/paste/?title=getInfo&language=markdown" -F file=@$1
local curl="$(curl --silent -X POST "https://www.pastery.net/api/paste/?title=getInfo_$version&language=markdown&duration=$(($2*1440))" --data-binary @$1)"
local id="$(echo $curl | cut -d '"' -f 4)"
curl="$(curl --silent -X POST "https://www.pastery.net/api/paste/?title=getInfo_$version&language=markdown&duration=$(($2*1440))" --data-binary @$1)"
id="$(echo $curl | cut -d '"' -f 4)"
f__info "\n\n votre paste:" "https://www.pastery.net/$id/"
[ "$3" == "debug" ] && echo -e "\n$curl\n"
@ -978,11 +998,12 @@ fipaste_curl_markdownshare(){
}
# inscription dans tache upgrade en anacron hebdomadaire, via cron horaire, $1=upgrade|install|remove
fscript_cronAnacron(){ # v27/08/2017
fscript_cronAnacron(){ # v30/08/2017
local dirAnacron dirSpool fileAnacron
[ "$(type -t fscript_cronAnacron_special)" ] && fscript_cronAnacron_special # test, si fonction spécifique, appel
local dirAnacron="/home/$user_/.config/anacron"
local dirSpool="$dirAnacron/spool"
local fileAnacron="$dirAnacron/$script.anacrontab"
dirAnacron="/home/$user_/.config/anacron"
dirSpool="$dirAnacron/spool"
fileAnacron="$dirAnacron/$script.anacrontab"
[ $EUID -eq 0 ] && sed -i "/$script.anacrontab/d" /etc/crontab
case "$1" in
install | upgrade )

View File

@ -4,6 +4,11 @@
* adresses MAC?
## 1.9.0 30/08/2017
* révision f__requis, f__user, f__wget_test, fscript_cronAnacron
* révision déclaration local
## 1.8.0 30/08/2017
* révision conditions d'utilisations, fscript_install, fscript_remove(), fscript_update