kyopages/scripts/getInfo

1531 lines
57 KiB
Plaintext
Raw Normal View History

2017-07-30 17:08:05 +02:00
#!/bin/bash
2017-10-04 10:29:08 +02:00
version=1.33.0
date="03/10/2017"
2017-08-02 01:16:24 +02:00
projet="simpledeb"
2017-08-26 09:05:54 +02:00
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
2017-07-30 17:08:05 +02:00
script="getInfo"
##### license LPRAB/WTFPL
2017-08-17 10:49:12 +02:00
# auteur: simpledeb
2017-07-30 17:08:05 +02:00
# contributeurs: kyodev
#####
2017-09-22 14:55:55 +02:00
# assigne $affichage_text
f__affichage(){ # 18/09/2017
2017-09-19 08:15:55 +02:00
f__color
affichage_text=" _ ___ __
2017-07-30 17:08:05 +02:00
__ _ ___| |_|_ _|_ __ / _| ___
/ _' |/ _ \ __|| || '_ \| |_ / _ \
| (_| | __/ |_ | || | | | _| (_) |
\__, |\___|\__|___|_| |_|_| \___/
|___/
2017-09-19 08:15:55 +02:00
"
2017-09-22 14:55:55 +02:00
clear
2017-09-19 08:15:55 +02:00
echo -e "$BLUE$affichage_text\n$YELLOW version $version - $date$COLOR\n"
2017-07-30 17:08:05 +02:00
}
2017-08-03 02:44:53 +02:00
# detect system architecture, assign $architecture : 32bits, i686 | 64bits, amd64, return 1 on unknown architecture
# remarque, debian: dpkg --print-architecture affiche i386
2017-09-22 14:55:55 +02:00
f__architecture(){ # 08/2017 spécifique
2017-08-03 02:44:53 +02:00
case "$(uname -m)" in
amd64 | x86_64 )
architecture="64bits, amd64";;
i?86 | x86 )
architecture="32bits, i686";;
* )
case "$(getconf LONG_BIT)" in
64 )
architecture="64bits, amd64";;
32 )
architecture="32bits, i686";;
*)
return 1
esac ;;
esac
}
2017-09-22 14:55:55 +02:00
f__color(){ # 18/09/2017
2017-09-19 08:15:55 +02:00
YELLOW="$(printf "\033[0;33m")" # question
GREEN="$(printf "\033[0;32m")" # ok
BLUE="$(printf "\033[0;34m")" # info
RED="$(printf "\033[0;31m")" # alerte
COLOR="$(printf "\033[0m")" # standard
}
# $1=oui|non réponse par défaut, $2=message de la question, return 0 pour oui, 1 pour non
f__dialog_oui_non () { # 18/09/2017
local reply
2017-09-15 08:54:24 +02:00
[[ "$1" =~ ^oui$|^non$ ]] || f__error "dialog_oui_non, erreur appel fonction"
2017-09-19 08:15:55 +02:00
printf "$BLUE $2"
[ "$1" == "oui" ] && printf " [O/n] " || printf " [o/N] "
printf "$COLOR"
read -r reply
if [ -z "$reply" ]; then
[ "$1" == "oui" ] && reply="oui" || reply="non"
fi
if [[ ${reply,,} =~ ^ou?i?$ ]]; then return 0; else return 1; fi #*{,,} lowercase
2017-09-15 08:54:24 +02:00
}
2017-08-26 09:05:54 +02:00
# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si $opType=upgrade
2017-09-23 12:23:41 +02:00
f__error() { # 22/09/2017
2017-08-26 09:05:54 +02:00
echo -e "\n$RED $script $version, erreur critique: $1 $COLOR"
2017-09-23 12:23:41 +02:00
for (( i=2 ; i<=$# ; i++ )); do echo -e " $BLUE${!i}"; done
unset i
2017-07-30 17:08:05 +02:00
echo "$COLOR"
2017-08-03 02:44:53 +02:00
if [ "$opType" == "upgrade" ]; then f__log "$script $version: $1"; fi
2017-07-30 17:08:05 +02:00
exit 1
}
2017-09-23 12:23:41 +02:00
# affichage des paramètres en bleu, si $1=raw pas de ligne vide à la fin, si $1=log uniquement $2 logué
f__info() { # 22/09/2017
2017-08-26 13:04:14 +02:00
local depart=1
2017-08-26 09:05:54 +02:00
if [ "$1" == "raw" ] || [ "$1" == "log" ]; then depart=2; fi
2017-08-21 19:07:08 +02:00
[ "$1" == "log" ] && f__log "$(sed -E 's/\\t//;s/\\n// ' <<< $2 | xargs )"
2017-08-26 13:04:14 +02:00
for (( i=$depart ; i<=$# ; i++ )); do echo -e " $BLUE${!i}"; done
2017-09-23 12:23:41 +02:00
unset i
2017-08-17 10:49:12 +02:00
[ "$1" == raw ] && printf "$COLOR" || echo "$COLOR"
2017-07-30 17:08:05 +02:00
}
2017-08-22 01:49:27 +02:00
# log spécifique, fichier log limité à 10000octets, $1 message à loguer
2017-09-22 14:55:55 +02:00
f__log(){ # 08/O9/2017
2017-08-22 01:49:27 +02:00
if [ -w "$fileLogs" ]; then
if [ "$(stat -c %s $fileLogs)" -ge "10000" ]; then
echo "$(date +%Y%m%d\ %H%M%S) $1" &>/dev/null > "$fileLogs"
else
echo "$(date +%Y%m%d\ %H%M%S) $1" &>/dev/null >> "$fileLogs"
fi
else
2017-09-09 20:26:43 +02:00
f__info "$fileLogs doit être activé" "Réinstaller un script plus récent" \
"voir $GREEN""$urlNotice#installation-rapide-du-script"
2017-08-22 01:49:27 +02:00
fi
2017-07-30 17:08:05 +02:00
}
2017-08-17 10:49:12 +02:00
# test dépendances/paquets, $1 liste commande[>paquet] (ex: killall>psmisc)
2017-08-18 20:15:13 +02:00
# si manque, SORTIE & info commandes manquantes, si debian, SORTIE & proposition paquet à installer
2017-08-17 10:49:12 +02:00
# 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
2017-09-23 12:23:41 +02:00
f__requis(){ # 22/09/2017
2017-08-30 22:46:26 +02:00
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 "
2017-08-17 10:49:12 +02:00
fi
2017-08-30 22:46:26 +02:00
done
2017-09-23 12:23:41 +02:00
unset i
2017-08-30 22:46:26 +02:00
[ "$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
}
2017-07-30 17:08:05 +02:00
2017-08-21 19:07:08 +02:00
# user ayant initié la session graphique, assigne $user_
# return 1 sur échec identification user, return 2 sur absence home/
2017-08-17 10:49:12 +02:00
# gestion variable environnement user avec: USER_INSTALL=user script
2017-10-02 15:34:29 +02:00
f__user(){ # 02/10/2017-4
2017-08-21 19:07:08 +02:00
if [ "$USER_INSTALL" ]; then # user_ via variable environnement, moyen d'injecter root
user_="$USER_INSTALL";
return 0
2017-10-02 15:34:29 +02:00
elif [[ "$TERM" =~ linux ]]; then #debian 9 recovery ou nomodeset TERM=linux
if [ "$USER" ]; then
user_="$USER"
elif [ "$EUID" -eq 0 ]; then
user_="root"
return 0
fi
echo "test \$TERM:$TERM"
2017-08-17 10:49:12 +02:00
fi
2017-08-30 22:46:26 +02:00
local user_id test root_login
root_login="$(grep ':0:' /etc/passwd | cut -d':' -f1)" || root_login="root"
2017-08-21 19:07:08 +02:00
if [ "$SUDO_UID" ]; then
user_id="$SUDO_UID";
elif grep -qEo '[0-9]+' <<< "$XDG_RUNTIME_DIR" ; then
user_id="$(grep -Eo '[0-9]+' <<< $XDG_RUNTIME_DIR | cut -d'/' -f4)"
elif grep -qEo '[0-9]+' <<< "$XAUTHORITY" ; then
user_id="$(grep -Eo '[0-9]+' <<< $XAUTHORITY | cut -d'/' -f4)"
2017-08-17 10:49:12 +02:00
fi
2017-08-21 19:07:08 +02:00
[ "$user_id" ] && user_="$(grep $user_id /etc/passwd | cut -d ":" -f 1 )"
if [ "$user_" ] && [ "$user_" != "$root_login" ]; then
return 0
else
if [ "$SUDO_USER" ] && [ "$SUDO_USER" != "$root_login" ]; then
user_="$SUDO_USER";
elif grep -qv 'root' <<< "$(who)"; then
2017-10-01 06:09:57 +02:00
user_="$(grep -v 'root' <<< $(who) | head -n1 | cut -d ' ' -f1)"; # grep -v 'root' <<< $(who) | awk 'FNR==1{print $1}'
2017-08-21 19:07:08 +02:00
elif grep -q 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab; then
2017-10-01 06:09:57 +02:00
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}
2017-08-21 19:07:08 +02:00
fi
2017-08-03 02:44:53 +02:00
fi
2017-08-21 19:07:08 +02:00
if [ -z "$user_" ]; then return 1; fi
if [ ! -d "/home/$user_" ]; then return 2; fi
return 0
2017-08-02 05:30:37 +02:00
}
2017-09-25 23:38:39 +02:00
# test wget, $1 url à tester, sortie du script si $1 seul (même si url testée ok)
2017-08-28 10:09:47 +02:00
# si $2=print affiche url testée & entêtes http & location (si présente) et sortie normale fonction
2017-09-25 23:38:39 +02:00
# si $2=loc affiche seulement location et sortie normale fonction
# si $2=test return 0 si ok, return 1 si ko
2017-09-29 20:27:53 +02:00
f__wget_test(){ # 29/09/2017
2017-08-30 22:46:26 +02:00
local file_test_wget retourWget retourHttp location
2017-09-28 20:47:34 +02:00
file_test_wget="/tmp/testWget-$$-$RANDOM"
2017-09-29 20:27:53 +02:00
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
2017-08-26 09:05:54 +02:00
[ "$retourWget" == 1 ] && retourWget="code erreur générique"
[ "$retourWget" == 2 ] && retourWget="parse erreur (ligne de commande?)"
[ "$retourWget" == 3 ] && retourWget="erreur Entrée/sortie fichier"
[ "$retourWget" == 4 ] && retourWget="défaut réseau"
[ "$retourWget" == 5 ] && retourWget="défaut vérification SSL"
[ "$retourWget" == 6 ] && retourWget="défaut authentification"
[ "$retourWget" == 7 ] && retourWget="erreur de protocole"
[ "$retourWget" == 8 ] && retourWget="réponse serveur en erreur"
2017-08-30 22:46:26 +02:00
retourHttp="$(grep -i 'HTTP/' "$file_test_wget" | tr -d '\n' | xargs)"
location="$(grep -i 'location' $file_test_wget | xargs)"
2017-09-09 20:26:43 +02:00
if [ "$2" == "print" ]; then
if [ "$retourWget" ]; then
echo "erreur wget: $RED$retourWget$COLOR"
echo -e "$BLUE $1$COLOR\t$RED $retourHttp$COLOR"
else
2017-09-25 23:38:39 +02:00
echo -e "$BLUE $1$COLOR\t$GREEN $retourHttp$COLOR"
2017-09-09 20:26:43 +02:00
fi
fi
2017-09-25 23:38:39 +02:00
if [ "$2" == "print" ] || [ "$2" == "loc" ]; then
[ "$location" ] && echo "$YELLOW $location" || echo "$YELLOW no location"
echo "$COLOR"
return 0
2017-08-28 10:09:47 +02:00
fi
if [ "$retourWget" ]; then
rm "$file_test_wget"
2017-09-01 22:17:15 +02:00
f__error "erreur wget, $retourWget" "$1" "$YELLOW$retourHttp" \
2017-08-28 10:09:47 +02:00
"si persistance, contacter $projet $contact en indiquant les messages précédents"
fi
2017-09-25 23:38:39 +02:00
if [ "$(grep -c '200' <<< $retourHttp)" -ne 0 ]; then
echo -e "$GREEN\ntout est ok, réessayer\n$COLOR"
fi
2017-08-26 09:05:54 +02:00
rm "$file_test_wget"
2017-08-28 10:09:47 +02:00
exit 0
2017-08-07 21:58:22 +02:00
}
2017-09-22 14:55:55 +02:00
f_help(){ # 07/09/2017
2017-08-30 01:04:45 +02:00
printf "$BLUE"
cat << 'EOF'
----------------------------------------------------------------------
2017-09-04 13:35:14 +02:00
./getInfo : exécution normale, rapport markdown configuration & diagnostic
2017-08-30 01:04:45 +02:00
getInfo : exécution normale si script installé dans le système
options:
2017-09-04 13:35:14 +02:00
-d, --dmesg : dmesg erreur, warning, critique. root requis, rapport markdown seul de dmesg
2017-08-30 01:04:45 +02:00
-h, --help : affichage aide
2017-09-04 13:35:14 +02:00
-l, --list : afficher le rapport markdown existant
-p, --paste : exporte le rapport markdown existant, durée du paste standard 7 jours
--ip : affiche ip(s) publique(s) (ipv4 / ipv6), infos confidentielles, sans rapport markdown
-m, --mac : affiche les adresses Mac, infos confidentielles, sans rapport markdown
-s, --ssid : affiche configurations ssid, infos confidentielles
pas de rapport markdown, root et NetworkManager requis
2017-08-30 01:04:45 +02:00
debug : le résultat json du paste sera affiché après export
-tn : durée du paste de n jour(s)
-i, --install : installation du script dans le système, droits root requis
-r, --remove : suppression du script dans le système, droits root requis
-u, --upgrade : upgrade script si maj possible
-v, --version : version du script, en ligne et en cours d'exécution
EOF
2017-09-09 20:26:43 +02:00
echo -e "$COLOR\n plus d'infos: $GREEN$urlNotice$COLOR\n"
2017-08-30 01:04:45 +02:00
}
2017-09-28 20:47:34 +02:00
# [$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'
2017-10-02 00:34:34 +02:00
text+="$batt_detail"
2017-09-28 20:47:34 +02:00
text+='```\n\n'
if [ "$1" == "debug" ]; then
2017-10-02 00:34:34 +02:00
text+='```\n'
text+="$(cat /sys/class/power_supply/BAT?/uevent) \n"
text+='```\n'
2017-09-28 20:47:34 +02:00
fi
echo -e "$text" >> "$fileOutput"
}
2017-10-04 10:29:08 +02:00
fi_cpu(){ # 03/10/2017
local cpu_addr cpu_bogomips cpu_flags text
2017-09-29 20:27:53 +02:00
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')"
2017-08-26 09:05:54 +02:00
###
2017-08-30 22:46:26 +02:00
text="## processeur / mémoire \n\n"
2017-09-25 23:38:39 +02:00
figet_cpu
2017-09-29 20:27:53 +02:00
text+='```\n'
2017-10-02 15:34:29 +02:00
text+="CPU: $figet_cpu \n"
2017-10-02 00:34:34 +02:00
text+="adressage: $cpu_addr \n"
text+="bogomips: $cpu_bogomips \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+="flags cpu: \n"
2017-09-29 20:27:53 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$cpu_flags \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-04 10:29:08 +02:00
echo -e "$text" >> "$fileOutput"
}
fi_mem(){ # 03/10/2017
local memsys swappiness text
memsys="$(free -hwt)"
swappiness="$(cat /proc/sys/vm/swappiness)"
###
2017-09-29 20:27:53 +02:00
figet_memory
text+='```\n'
2017-10-02 15:34:29 +02:00
text+="mémoire Ram utilisée/totale: $figet_memory \n\n"
2017-10-04 10:29:08 +02:00
text+="$memsys \n\n"
2017-10-02 00:34:34 +02:00
text+="swappiness: $swappiness \n"
2017-09-29 20:27:53 +02:00
text+='```\n\n'
2017-08-26 09:05:54 +02:00
echo -e "$text" >> "$fileOutput"
2017-08-02 05:30:37 +02:00
}
2017-10-02 15:34:29 +02:00
fi_disk(){ # 02/10/2017
2017-09-27 20:40:28 +02:00
local fstab resume idResume idSwap alert_uuidResume text
2017-10-02 15:34:29 +02:00
fstab="$(grep -vE '^[[:blank:]]*#|^$' /etc/fstab)"
resume="$(grep -Ev '^[[:blank:]]*#|^$' /etc/initramfs-tools/conf.d/resume 2>/dev/null)"
idResume="$(grep -Ev '^[[:blank:]]*#|^$' /etc/initramfs-tools/conf.d/resume 2>/dev/null | sed -En 's/.*UUID=([0-9a-Z-]*).*$/\1/p')"
idSwap="$(grep -Ev '^[[:blank:]]*#|^$' /etc/fstab | sed -En 's/UUID=([0-9a-Z-]*).*swap.*$/\1/p')"
2017-09-16 14:25:36 +02:00
if [ "$idSwap" ] && [ "$idResume" ] && [ "$idSwap" != "$idResume" ]; then
2017-09-27 20:40:28 +02:00
alert_uuidResume+="id swap : $idSwap \nid resume: $idResume\n"
2017-10-02 15:34:29 +02:00
alert_uuidResume+="**vérifier la config resume**, l'UUID ne correspond pas à celui du swap. \n"
alert_uuidResume+="vous pouvez utiliser _RESUME=auto_ ou _RESUME=/dev/sdx_, voir supprimer ce fichier"
2017-09-16 14:25:36 +02:00
fi
2017-08-26 09:05:54 +02:00
###
2017-08-30 22:46:26 +02:00
text="## disque(s) \n\n"
2017-09-27 20:40:28 +02:00
[ "$part_fix_tot" ] || figet_disk # appel figet_disk si pas déjà fait par fi_systeme
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$part_fix_tot \n" # espaces des partitions montées
2017-09-27 20:40:28 +02:00
text+="disque(s) fixe(s): $disk_fix \n" # devices fixes
text+="disque(s) amovible(s): $disk_hotplug \n\n" # devices hotplug
text+="$disk_detail \n" # caractéristiques des disques trouvés
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+="**types de disque** \n\n"
2017-09-27 20:40:28 +02:00
text+="| ata | usb | mmc | nvme | \n"
text+="| :---: | :---: | :---: | :---: | \n"
text+="| $disk_ata | $disk_usb | $disk_mmc | $disk_nvme | \n\n"
# df, espaces des partitions montées seules
2017-10-02 00:34:34 +02:00
text+='`df -h --output=source,target,fstype,size,used,avail,pcent --exclude=tmpfs --exclude=devtmpfs` (utilisation disques) \n'
2017-09-27 20:40:28 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$disk_utilisation \n"
2017-09-27 20:40:28 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+='`'"lsblk -o NAME,FSTYPE,SIZE,LABEL,MOUNTPOINT,UUID"'` (disques) \n' # lsblk
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$disk_lsblk \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 15:34:29 +02:00
text+='`'"grep -vE '^[[:blank:]]*#|^$' /etc/fstab"'` (fstab) \n' # fstab
text+='```\n'
text+="$fstab \n"
text+='```\n\n'
text+='`'"grep -Ev '^[[:blank:]]*#|^$' /etc/initramfs-tools/conf.d/resume"'` (resume) \n' # resume
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-09-29 20:27:53 +02:00
if [ "$resume" ]; then
text+="$resume \n"
else
2017-10-02 15:34:29 +02:00
text+="pas de fichier resume trouvé dans /etc/initramfs-tools/conf.d/ \n"
2017-09-29 20:27:53 +02:00
fi
text+='```\n\n'
2017-09-27 20:40:28 +02:00
if [ "$alert_uuidResume" ]; then
text+="$alert_uuidResume \n\n"
fi
2017-08-26 09:05:54 +02:00
echo -e "$text" >> "$fileOutput"
2017-08-02 05:30:37 +02:00
}
2017-09-28 10:16:50 +02:00
fi_dmesg(){ # root only, si $1=dmesg rapport dmesg only # 27/09/2017
2017-08-30 22:46:26 +02:00
local text dmesg_err dmesg_warn dmesg_crit
text="## dmesg (erreur, warning ou critique) \n\n"
2017-09-28 10:16:50 +02:00
if ! dmesg --nopager &> /dev/null; then
text+="la commande \`dmesg\` n'est pas disponible (droits root requis?) \n"
echo -e "$text" >> "$fileOutput"
return 0
2017-08-26 09:05:54 +02:00
fi
###
2017-09-28 10:16:50 +02:00
dmesg_err="$(dmesg -Hk --nopager -l err)"
dmesg_warn="$(dmesg -Hk --nopager -l warn)"
dmesg_crit="$(dmesg -Hk --nopager -l crit)"
2017-08-26 09:05:54 +02:00
if [ "$dmesg_err" ]; then
2017-10-02 00:34:34 +02:00
text+='`dmesg -l err` (erreur) \n'
2017-09-22 16:31:40 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$dmesg_err \n"
text+='```\n\n'
2017-08-26 09:05:54 +02:00
fi
if [ "$dmesg_warn" ]; then
2017-10-02 00:34:34 +02:00
text+='`dmesg -l warn` (warning) \n'
2017-09-22 16:31:40 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$dmesg_warn \n"
text+='```\n\n'
2017-08-26 09:05:54 +02:00
fi
if [ "$dmesg_crit" ]; then
2017-10-02 00:34:34 +02:00
text+='`dmesg -l crit` (critique) \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$dmesg_crit \n"
text+='```\n\n'
2017-08-26 09:05:54 +02:00
fi
2017-09-22 16:31:40 +02:00
if [ -z "$dmesg_crit" ] && [ -z "$dmesg_warn" ] && [ -z "$dmesg_err" ]; then
2017-10-02 00:34:34 +02:00
text+="pas de messages à afficher \n\n"
2017-08-26 09:05:54 +02:00
fi
echo -e "$text" >> "$fileOutput"
2017-08-03 02:44:53 +02:00
}
2017-10-02 00:34:34 +02:00
fi_gpu(){ # 01/10/2017
local slotGraphCards graphCards openGl resolutions logXorg modules text
2017-08-30 22:46:26 +02:00
# graphCards="$(lspci -nnk | grep -iEA 3 'vga|display|3d')"
2017-09-22 14:55:55 +02:00
# 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
2017-10-01 06:09:57 +02:00
graphCards+="$(lspci -s $i -nnv)"$'\n'
2017-09-22 14:55:55 +02:00
done
2017-09-23 12:23:41 +02:00
unset i
2017-09-25 23:38:39 +02:00
[ "$(which glxinfo)" ] && openGl="$(glxinfo | grep 'OpenGL version')"
2017-08-30 22:46:26 +02:00
resolutions="$(xrandr --query | grep '^ *[0-9]' | head -n 10)"
2017-09-25 23:38:39 +02:00
logXorg="$(grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)' /var/log/Xorg.*.log /home/$user_/.local/share/xorg/Xorg.*.log 2>/dev/null)"
2017-10-02 00:34:34 +02:00
modules="$(lsmod | grep -iE 'amdgpu|ati|i915|nouveau|nvidia|radeon|video|gma')"
2017-08-26 09:05:54 +02:00
###
2017-08-30 22:46:26 +02:00
text="## graphisme \n\n"
2017-09-22 14:55:55 +02:00
text+="| | | \n"
text+=" --- | --- \n"
2017-09-25 23:38:39 +02:00
figet_gpu
2017-10-02 15:34:29 +02:00
text+="GPU | **$figet_gpu** \n\n"
[ "$figet_resolution" ] || figet_resolution
text+="**résolution: $figet_resolution** \n\n"
2017-10-02 00:34:34 +02:00
text+='`'"lspci -nnv | grep -iEA 13 'vga|display|3d'"'` \n'
2017-10-01 06:09:57 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$graphCards"
2017-10-01 06:09:57 +02:00
text+='```\n\n'
2017-08-26 09:05:54 +02:00
if [ "$openGl" ]; then
2017-10-02 00:34:34 +02:00
text+='`'"glxinfo | grep 'OpenGL version'"'` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$openGl \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-08-03 02:44:53 +02:00
fi
2017-10-02 00:34:34 +02:00
text+='`'"xrandr --query | grep '^ *[0-9]' | head -n 10"'` (10 premières résolutions possibles) \n'
text+='```\n'
text+="$resolutions \n"
text+='```\n\n'
text+='`'"grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)' /var/log/Xorg.?.log /home/user/.local/share/xorg/Xorg.?.log"'` (xorg.log) \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$logXorg \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+="### modules video \n\n"
text+="liste non garantie complète \n"
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$modules\n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
echo -e "$text" >> "$fileOutput"
2017-08-03 02:44:53 +02:00
}
2017-09-25 23:38:39 +02:00
fi_localisation(){ # 25/09/2017
2017-09-16 14:25:36 +02:00
local locale timezone keymap keyboard timedatectl alert_Rtc alert_Rtc_info alert_NTP alert_Ntp_info text
2017-08-30 22:46:26 +02:00
locale="$(grep -vE '#|^$' /etc/default/locale)"
timezone="$(cat /etc/timezone)"
2017-09-16 14:25:36 +02:00
if [ "$(which timedatectl)" ]; then
timedatectl="$(timedatectl status --no-pager)"
grep -q 'RTC in local TZ: yes' <<< "$timedatectl" && alert_Rtc="Attention RTC in local TZ"
alert_Rtc_info="**Lhorloge système doit être en UTC** pour que les applications de date et heure fonctionnent
correctement avec le fuseau horaire configuré sur le système. Les modifications dheure
2017-10-02 00:34:34 +02:00
dété/hiver peuvent être incohérentes quand lhorloge matérielle est en heure locale. \n"
2017-09-16 14:25:36 +02:00
grep -q 'Network time on: no' <<< "$timedatectl" && alert_NTP="Attention NTP"
alert_Ntp_info="Le système ne synchronise pas l'heure sur un serveur NTP. Si ce n'est pas voulu:
activer le service: timedatectl set-ntp true
2017-10-02 00:34:34 +02:00
et/ou installer le démon Ntp: apt install ntp \n"
2017-09-16 14:25:36 +02:00
fi
2017-08-30 22:46:26 +02:00
keymap="$(setxkbmap -query)"
keyboard="$(grep -vE '#|^$' /etc/default/keyboard)"
2017-08-26 09:05:54 +02:00
###
2017-08-30 22:46:26 +02:00
text="## localisation \n\n"
2017-10-02 00:34:34 +02:00
text+='`'"grep -vE '#|^$' /etc/default/locale"'` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$locale \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+='`'"cat /etc/timezone"'` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$timezone \n"
2017-09-16 14:25:36 +02:00
text+='```\n'
if [ "$timedatectl" ]; then
2017-10-02 00:34:34 +02:00
text+='\n`'"timedatectl status --no-pager"'` \n'
2017-09-16 14:25:36 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$timedatectl \n"
2017-09-16 14:25:36 +02:00
text+='```\n'
fi
[ "$alert_Rtc" ] && text+="$alert_Rtc_info \n"
[ "$alert_Ntp" ] && text+="$alert_Ntp_info \n"
2017-10-02 00:34:34 +02:00
text+='\n`'"setxkbmap -query"'` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$keymap \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+='`'"grep -vE '#|^$' /etc/default/keyboard"'` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$keyboard \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
echo -e "$text" >> "$fileOutput"
}
2017-08-06 02:43:48 +02:00
2017-09-25 23:38:39 +02:00
fi_nm(){ # 25/09/2017
2017-09-24 06:27:21 +02:00
[ -x "$(which nmcli)" ] || return 0 # nécessite root sur autre que debian?
2017-08-30 22:46:26 +02:00
local nm_etat nm_conf text
nm_etat="$(grep -vE '#|^$' /var/lib/NetworkManager/NetworkManager.state)"
nm_conf="$(grep -vE '#|^$' /etc/NetworkManager/NetworkManager.conf)"
2017-08-26 09:05:54 +02:00
###
2017-08-30 22:46:26 +02:00
text="## Network Manager \n\n"
2017-10-02 00:34:34 +02:00
text+='`'"grep -vE '#|^$' /var/lib/NetworkManager/NetworkManager.state"'` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$nm_etat \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+='`'"grep -vE '#|^$' /etc/NetworkManager/NetworkManager.conf"'` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$nm_conf \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
echo -e "$text" >> "$fileOutput"
}
2017-08-06 02:43:48 +02:00
2017-10-02 00:34:34 +02:00
fi_nm_wifis(){ # 01/10/2017
2017-09-24 06:27:21 +02:00
[ -x "$(which nmcli)" ] || return 0
2017-08-30 22:46:26 +02:00
local nm_wifis nm_connected text
nm_wifis="$(nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY device wifi list)"
2017-10-02 00:34:34 +02:00
nm_connected="$(LC_ALL=C nmcli -f SSID,ACTIVE,IN-USE device wifi list | awk '/yes[[:space:]]+\*/ {print $1}')"
2017-08-26 09:05:54 +02:00
###
2017-08-30 22:46:26 +02:00
text="## wifis à proximité \n\n"
2017-10-02 00:34:34 +02:00
text+='`'"nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY device wifi list"'` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$nm_wifis \n"
2017-08-26 09:05:54 +02:00
text+='```\n'
echo -e "$text" >> "$fileOutput"
}
2017-08-06 02:43:48 +02:00
2017-09-25 23:38:39 +02:00
fi_nonFree(){ # 25/09/2017
2017-09-24 06:27:21 +02:00
local vrmsOut text
if [ "$(which vrms)" ]; then
vrmsOut="$(vrms)"
else
vrmsOut="les paquets non-free ou contrib ne peuvent être détectés sans l'installation de vrms"
fi
###
text="## Paquets non-libres \n\n"
2017-09-25 23:38:39 +02:00
if [ "$(which vrms)" ]; then
2017-10-02 00:34:34 +02:00
text+='`vrms` \n'
2017-09-25 23:38:39 +02:00
text+='```\n'
fi
2017-10-02 00:34:34 +02:00
text+="$vrmsOut \n"
2017-09-24 06:27:21 +02:00
[ "$(which vrms)" ] && text+='```\n'
echo -e "$text" >> "$fileOutput"
}
2017-10-02 00:34:34 +02:00
fi_reseau(){ # 01/10/2017
2017-09-22 14:55:55 +02:00
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
2017-10-01 06:09:57 +02:00
netCards+="$(lspci -s $i -nnv)"$'\n'
2017-09-22 14:55:55 +02:00
done
2017-09-23 12:23:41 +02:00
unset i
2017-08-30 22:46:26 +02:00
ip_a="$(ip a | sed '/inet6.*scope global/d; /link\/ether/d; /valid_lft/d')" # filtre sur inet6 & scope global & adr MAC & bail?
2017-08-26 09:05:54 +02:00
if [ "$(which iwlist)" ]; then #paquet wireless-tools requis
2017-08-30 22:46:26 +02:00
iwconfig="$(iwconfig 2>&1 | grep -v 'no wireless extensions' | grep -v '^$')"
2017-08-06 02:43:48 +02:00
fi
2017-10-01 06:09:57 +02:00
interfaces="$(grep -Evr '#|^$' /etc/network/interfaces* 2>/dev/null)"
interfaces="$(sed -E 's/wpa-psk [[:graph:]]+/wpa-psk <WPA key removed>/; s/:/: /' <<< $interfaces )"
2017-08-30 22:46:26 +02:00
route="$(ip route show)"
resolv="$(grep -vE '#|^$' /etc/resolv.conf)"
2017-08-26 09:05:54 +02:00
netmgrpaths=("/usr/sbin/NetworkManager" "/usr/sbin/wicd" "/usr/sbin/connmand") # thanks wireless-info
netmgrnames=("NetworkManager" "Wicd" "ConnMan") # thanks wireless-info
2017-09-23 12:23:41 +02:00
for i in "${!netmgrpaths[@]}"; do
if [ -f "${netmgrpaths[$i]}" ]; then netmgrinst+="${netmgrnames[$i]}"; fi
2017-10-01 06:09:57 +02:00
if [ "$(ps -ef | grep -c ${netmgrpaths[$i]})" -ge 2 ]; then
netmgrrun+="$(ps -ef | grep -o "${netmgrpaths[$i]}.*$" | head -n 1)"
fi
2017-08-26 09:05:54 +02:00
done
2017-09-23 12:23:41 +02:00
unset i
2017-08-26 09:05:54 +02:00
if [ "$(which iwlist)" ]; then # liste canaux wifi; paquet wireless-tools requis
2017-08-30 22:46:26 +02:00
liste_canaux_wifi="$(iwlist chan 2>&1 | grep -vE 'no frequency information|^$')"
2017-08-06 02:43:48 +02:00
fi
2017-08-26 09:05:54 +02:00
###
2017-10-02 00:34:34 +02:00
text="## réseau \n\n"
text+='`'"lspci -nnv | grep -iEA 15 'network|ethernet"'` \n'
text+='```\n'
text+="$netCards"
text+='```\n\n'
2017-09-25 23:38:39 +02:00
figet_ip
text+="**IP locale(s):** \n"
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$ip_local_type \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+="* les adresses Mac peut être affichées avec "'`./getInfo -m` ou `getInfo -m`'" (script installé) \n"
text+="* l'IP publique peut être connue avec: "'`./getInfo --ip` ou `getInfo --ip` (script installé) \n\n'
2017-09-04 13:35:14 +02:00
if grep -q 'wlx' <<< "$ifnames"; then
2017-10-02 00:34:34 +02:00
text+="**Attention:** une interface wifi est en erreur: $(grep -o 'wlx' <<< $ifnames) \n"
text+="l'interface n'est pas reconnue et est donc mal nommée \n"
text+="au pire, changer le renommage: https://kyodev.frama.io/kyopages/trucs/interfaces-nommage-classique/ \n\n"
2017-08-06 02:43:48 +02:00
fi
2017-08-26 09:05:54 +02:00
text+="**Passerelle(s):** \n"
2017-08-06 02:43:48 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$gateway_type \n"
2017-10-01 06:09:57 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+='`ip address`'" (ipv6 lien local, pas d'adresses MAC) \n"
2017-08-17 17:32:34 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$ip_a \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-26 09:05:54 +02:00
if [ "$iwconfig" ]; then
2017-10-02 00:34:34 +02:00
text+='`iwconfig` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$iwconfig \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
fi
2017-10-02 00:34:34 +02:00
text+='`'"grep -Evr '#|^$' /etc/network/interfaces*"'` \n'
2017-08-17 17:32:34 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$interfaces \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+='`ip route show` \n'
2017-08-17 17:32:34 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$route \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-10-04 10:29:08 +02:00
text+='`cat /etc/resolv.conf` serveurs de noms DNS utilisés par défaut \n'
2017-08-17 17:32:34 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$resolv \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-26 09:05:54 +02:00
if [ "$liste_canaux_wifi" ]; then
2017-10-02 00:34:34 +02:00
text+='`iwlist chan` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$liste_canaux_wifi \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+="* la configuration ssid utilisé peut être connue (si NetworkManager utilisé) avec "'`./getInfo -s` ou `getInfo -s`'" (script installé) \n\n"
2017-08-26 09:05:54 +02:00
fi
if [ "$netmgrinst" ]; then
2017-10-02 00:34:34 +02:00
text+="### network managers \n\n"
2017-08-26 09:05:54 +02:00
[ "$netmgrinst" ] && text+="installé(s): **$netmgrinst** \n" || text+="non trouvé parmi: ${netmgrnames[@]} \n"
text+="en fonctionnement: "
2017-10-02 00:34:34 +02:00
[ "$netmgrrun" ] && text+="**$netmgrrun** \n\n" || text+="non \n\n"
2017-08-19 03:45:31 +02:00
fi
2017-10-02 00:34:34 +02:00
figet_mod_net
text+="### modules réseau \n\n"
text+="liste non garantie complète \n"
text+='```\n'
2017-10-02 15:34:29 +02:00
text+="$modules_net \n"
2017-10-02 00:34:34 +02:00
text+='```\n\n'
2017-08-17 17:32:34 +02:00
echo -e "$text" >> "$fileOutput"
}
2017-10-02 15:34:29 +02:00
fi_sources(){ # 02/10/2017
2017-09-29 20:27:53 +02:00
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
2017-10-01 06:09:57 +02:00
local paquetBiz text
2017-08-26 09:05:54 +02:00
printf "."
2017-09-29 20:27:53 +02:00
sources="$(grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null)"
2017-10-02 00:34:34 +02:00
sources="$(sed 's/:deb/: deb/; s/ / /g' <<< $sources)"
2017-10-02 15:34:29 +02:00
dateMaj="$(date -r /var/cache/apt/pkgcache.bin '+%d/%m/%Y %H:%M %z')" # /var/lib/dpkg/
2017-09-29 20:27:53 +02:00
nb_packages="$(dpkg -l | grep -c '^ii')"
2017-08-26 09:05:54 +02:00
printf "."
2017-08-30 22:46:26 +02:00
apt="$(LC_ALL=C apt-get autoremove --simulate)"
autoremove="$(grep -c 'Remv' <<< $apt)"
2017-10-02 15:34:29 +02:00
paquetToRemove="$(sed -En 's/Remv (.*)\[[0-9.-]*\]/\1/p' <<< $apt | tr '\n' ' ')"
2017-08-26 09:05:54 +02:00
printf "."
2017-09-29 20:27:53 +02:00
httpredir="$(grep 'httpredir' <<< $sources)"
2017-10-02 15:34:29 +02:00
upgradable="$(LC_ALL=C apt list --upgradable 2>/dev/null | sed '1d')"
2017-10-01 06:09:57 +02:00
[ "$upgradable" ] && nbUpgradable="$(grep -c '.' <<< "$upgradable")"
2017-08-26 09:05:54 +02:00
printf "."
2017-10-02 00:34:34 +02:00
paquetBiz="$(dpkg -l | awk 'FNR>5 && ! /^i/ {print $1, $2, $3}')"
2017-08-19 03:45:31 +02:00
###
2017-08-30 22:46:26 +02:00
text+="## sources list \n\n"
2017-10-02 00:34:34 +02:00
text+='`'"grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null"'` \n'
2017-08-26 09:05:54 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$sources \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+="nombre de paquets installés: **$nb_packages** \n\n"
text+="dernière mise à jour apt: **$dateMaj** \n\n"
2017-08-26 09:05:54 +02:00
if [ "$autoremove" -ne 0 ] ; then
2017-10-02 00:34:34 +02:00
text+="**$autoremove paquet(s) installé(s) inutile(s)**, vous pouvez utiliser: "'`apt autoremove`'" \n"
text+="paquet(s) concerné(s): \n"
2017-08-06 02:43:48 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$paquetToRemove \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
2017-08-26 09:05:54 +02:00
if [ "$httpredir" ]; then
2017-09-29 20:27:53 +02:00
text+="url **httpredir,** ces urls sont obsolètes, préférer http://deb.debian.org/debian/ ou un miroir local \n"
2017-08-06 02:43:48 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$httpredir \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
2017-08-26 09:05:54 +02:00
if [ "$upgradable" ]; then
2017-10-02 00:34:34 +02:00
text+="**$nbUpgradable paquets devraient être mis à jour:** \n"
text+='`apt list --upgradable` \n'
2017-08-06 02:43:48 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$upgradable \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
2017-08-26 09:05:54 +02:00
if [ "$paquetBiz" ]; then
2017-10-02 00:34:34 +02:00
text+="il y a des **paquet(s) dans un état non installé**. ce n'est pas forcément grave, mais ça peut être examiné. \n"
text+="paquet(s) concerné(s): \n"
2017-08-19 03:45:31 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$paquetBiz \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
echo -e "$text" >> "$fileOutput"
}
2017-09-25 23:38:39 +02:00
fi_ssid(){ # affiche configurations ssid # 25/09/2017
2017-08-26 09:05:54 +02:00
[ "$(which nmcli)" ] || f__error "il manque NetworkManager"
[ $EUID -eq 0 ] || f__error "il manque les droits root"
2017-08-30 22:46:26 +02:00
local nm_ssid text
nm_ssid="$(grep -vE '#|^$' /etc/NetworkManager/system-connections/*)"
2017-08-19 03:45:31 +02:00
###
2017-09-04 13:35:14 +02:00
f__info "$RED""Attention, la clé du réseau wifi est visible $COLOR""aucun rapport n'a été créé"
text="## configuration(s) ssid networkmanager \n\n"
2017-09-25 23:38:39 +02:00
text+="$GREEN""grep -vE '#|^$' /etc/NetworkManager/system-connections/*$COLOR \n\n"
2017-10-02 00:34:34 +02:00
text+="$nm_ssid \n\n"
2017-08-26 09:05:54 +02:00
echo -e "$text"
2017-08-06 02:43:48 +02:00
}
2017-09-25 23:38:39 +02:00
fi_system_analyse(){ # 25/09/2017
2017-08-26 09:05:54 +02:00
[ -x "$(which systemd-analyze)" ] || return 0 # pas systemd
2017-08-30 22:46:26 +02:00
local bootTime bootBlame text
bootTime="$(systemd-analyze time)"
bootBlame="$(systemd-analyze blame | head -n 20)"
2017-08-19 03:45:31 +02:00
###
2017-08-30 22:46:26 +02:00
text="## analyse boot \n\n"
2017-10-02 00:34:34 +02:00
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'
2017-08-06 02:43:48 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$bootBlame \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
echo -e "$text" >> "$fileOutput"
}
2017-10-02 15:34:29 +02:00
fi_systeme(){ # 02/10/2017
2017-09-28 20:47:34 +02:00
local mbr description uname bootImage xorg shells lastboot uptime text pluriel
2017-09-22 14:55:55 +02:00
[ -d /sys/firmware/efi ] && mbr="**EFI**" || mbr="**Legacy (mbr)**"
2017-08-30 22:46:26 +02:00
[ -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)"
2017-10-02 15:34:29 +02:00
bootImage="$(awk '/BOOT_IMAGE/ {print $1}' /proc/cmdline)"
bootImage="$(awk '{print $1}{i=2; while (i <= NF-1) { print " ",$i; i++}}' /proc/cmdline)"
2017-10-01 06:09:57 +02:00
initDaemon="$(ps -p1 | awk 'FNR==2 {print $4}')" #? ps -ax | awk '$1==1' ou ps -p1 | awk '$1==1'
2017-08-30 22:46:26 +02:00
xorg="$XDG_SESSION_TYPE"
2017-08-26 09:05:54 +02:00
if [ -z "$xorg" ]; then
[ "$(ps -ef | grep -c 'wayland')" -gt 1 ] && xorg="wayland" || xorg="indéterminé"
fi
2017-10-02 15:34:29 +02:00
shells="$(grep -vE '^[[:blank:]]*#|^$' /etc/shells | sed 's/\/bin\///' | tr '\n' ' ')"
# lastboot="$(last -n 1 --time-format iso reboot | awk 'FNR==1 {sub(/T/," ",$5);print $5}')" # remis à jours en début de mois ?!!
lastboot="$(date -r /var/run/utmp '+%d/%m/%Y %H:%M %z')"
2017-10-01 06:09:57 +02:00
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/')"
2017-08-19 03:45:31 +02:00
###
2017-08-30 22:46:26 +02:00
text="## système \n\n"
2017-09-22 14:55:55 +02:00
text+="| | | \n"
text+=" --- | --- \n"
2017-09-25 23:38:39 +02:00
figet_cpu
2017-10-02 15:34:29 +02:00
text+="CPU | **$figet_cpu** \n"
2017-09-25 23:38:39 +02:00
figet_gpu
2017-10-02 15:34:29 +02:00
text+="GPU | **$figet_gpu** \n"
2017-10-02 00:34:34 +02:00
text+="boot | $mbr \n"
2017-09-25 23:38:39 +02:00
figet_distro
2017-10-02 15:34:29 +02:00
text+="distribution | **$figet_distro** \n\n"
2017-08-26 09:05:54 +02:00
f__architecture || f__info "Architecture non supportée" "vous pouvez contacter contacter $projet $contact si vous voulez aider à parfaire le script"
2017-08-06 02:43:48 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="architecture: $architecture \n"
[ "$description" ] && text+="description: $description \n"
text+="uname: $uname \n"
text+="$bootImage \n"
text+="démon d'initialisation: $initDaemon \n"
2017-09-25 23:38:39 +02:00
figet_resolution
2017-10-02 15:34:29 +02:00
text+="résolution: $figet_resolution \n"
2017-10-02 00:34:34 +02:00
text+="serveur d'affichage: $xorg \n"
2017-09-25 23:38:39 +02:00
figet_de
2017-10-02 15:34:29 +02:00
text+="desktop (DE): $figet_de \n"
2017-09-25 23:38:39 +02:00
figet_wm
2017-10-02 15:34:29 +02:00
text+="window manager: $figet_wm \n"
2017-09-25 23:38:39 +02:00
figet_shell
2017-10-02 15:34:29 +02:00
text+="shell actif: $figet_shell \n"
2017-10-02 00:34:34 +02:00
text+="shells installés: $shells \n"
2017-09-25 23:38:39 +02:00
figet_disk
2017-10-02 00:34:34 +02:00
text+="$part_fix_tot \n"
2017-09-25 23:38:39 +02:00
figet_battery
2017-09-28 20:47:34 +02:00
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
2017-10-02 00:34:34 +02:00
text+="dernier boot: $lastboot, uptime: $uptime \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
echo -e "$text" >> "$fileOutput"
}
2017-09-25 23:38:39 +02:00
fi_usb(){ # 25/09/2017
2017-08-30 22:46:26 +02:00
local lsusb lsusb_t text
lsusb="$(lsusb)"
lsusb_t="$(lsusb -t)"
2017-08-19 03:45:31 +02:00
###
2017-08-30 22:46:26 +02:00
text="## périphériques USB \n\n"
2017-10-02 00:34:34 +02:00
text+='`lsusb` \n'
2017-08-06 02:43:48 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$lsusb \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-10-02 00:34:34 +02:00
text+='`lsusb -t` \n'
2017-08-06 02:43:48 +02:00
text+='```\n'
2017-10-02 00:34:34 +02:00
text+="$lsusb_t \n"
2017-08-26 09:05:54 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
echo -e "$text" >> "$fileOutput"
2017-08-02 01:16:24 +02:00
}
2017-09-28 20:47:34 +02:00
# informations batterie(s), assigne $batt_nb $batt_detail
2017-10-02 15:34:29 +02:00
figet_battery(){ # 02/10/2017
2017-09-28 20:47:34 +02:00
local batt_alim batt_unit batt_capa_design batt_capa_full batt_capa_now batt_conso
2017-10-02 15:34:29 +02:00
local batt_voltage batt_status batt_sn batt_cycle tempo batt_restant ibat
2017-09-28 20:47:34 +02:00
batt_nb="$(ls /sys/class/power_supply/ | grep -c 'BAT')"
if [ "$batt_nb" -gt "0" ]; then
2017-09-29 20:27:53 +02:00
# extraction valeur
2017-10-02 16:14:14 +02:00
batt_alim="$(grep . /sys/class/power_supply/AC*/online | sed -n '1p')"
2017-09-28 20:47:34 +02:00
unset batt_detail
for ibat in /sys/class/power_supply/BAT*; do
2017-09-29 20:27:53 +02:00
# extraction pour valeur de calcul ou selon type unité
2017-09-28 20:47:34 +02:00
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
2017-09-29 20:27:53 +02:00
# mise en forme micro en milli
2017-09-28 20:47:34 +02:00
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}"
2017-09-29 20:27:53 +02:00
# extraction
batt_voltage="$(cat $ibat/voltage_min_design 2>/dev/null)"
batt_status="$(cat $ibat/status 2>/dev/null)"
2017-09-28 20:47:34 +02:00
batt_sn="$(cat $ibat/serial_number 2>/dev/null)"
batt_cycle="$(cat $ibat/cycle_count 2>/dev/null)"
2017-09-29 20:27:53 +02:00
# 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): "
2017-09-28 20:47:34 +02:00
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 "
2017-09-29 20:27:53 +02:00
batt_detail+="$batt_voltage V "
2017-10-01 06:09:57 +02:00
[ "$batt_batt_sn" ] && batt_detail+="n° série:$batt_sn"$'\n'
[ "$batt_cycle" != "0" ] && batt_detail+="$batt_cycle cycles"$'\n' || batt_detail+=$'\n'
2017-09-29 20:27:53 +02:00
[ "$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 => "
2017-10-01 06:09:57 +02:00
[ "$batt_sante" ] && batt_detail+="$batt_sante % (indicateur santé)"$'\n'
[ "$batt_restant" ] && batt_detail+="$batt_restant"$'\n'
2017-09-28 20:47:34 +02:00
done
fi
2017-08-26 09:05:54 +02:00
}
2017-10-02 15:34:29 +02:00
figet_cpu() { # thanks neofetch, assigne $figet_cpu # 02/10/2017
local cpu speed_dir temp_dir speedMin speed speedMin speed temp cores
2017-08-26 09:05:54 +02:00
cpu="$(awk -F ': | @' '/model name|Processor/ {printf $2; exit}' /proc/cpuinfo)"
2017-08-30 22:46:26 +02:00
speed_dir="/sys/devices/system/cpu/cpu0/cpufreq"
temp_dir="/sys/class/hwmon/hwmon0/temp1_input"
2017-08-26 09:05:54 +02:00
# Get cpu speed
if [[ -d "$speed_dir" ]]; then
2017-08-30 22:46:26 +02:00
speedMin="$(< "${speed_dir}/scaling_min_freq")"
speed="$(< "${speed_dir}/scaling_max_freq")"
2017-08-26 09:05:54 +02:00
speed="$((speed / 100000))"
2017-08-30 22:46:26 +02:00
speedMin="$((speedMin / 100000))"
2017-08-26 09:05:54 +02:00
else
2017-08-30 22:46:26 +02:00
speed="$(awk -F ': |\\.' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)"
speed="$((speed / 100))"
2017-08-06 02:43:48 +02:00
fi
2017-08-26 09:05:54 +02:00
# Get cpu temp
if [ -f "$temp_dir" ]; then
temp="$(< "$temp_dir")"
temp="$((temp * 100 / 10000))"
temp="[${temp/${temp: -1}}.${temp: -1}°C]"
2017-08-19 03:45:31 +02:00
fi
2017-08-26 09:05:54 +02:00
# Show/hide hyperthreaded cores
2017-10-01 06:09:57 +02:00
cores="$(grep "^core id" /proc/cpuinfo | sort -u | grep -c '.')" # physique
2017-09-29 20:27:53 +02:00
coresT="$(grep -c "^processor" /proc/cpuinfo)" # logique
2017-08-26 09:05:54 +02:00
# 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
cpu="$cpu @ ${speedMin} - ${speed} GHz $temp"
# Remove uneeded patterns from cpu output, this is faster than sed/gsub
cpu="${cpu//(tm)}"
cpu="${cpu//(TM)}"
cpu="${cpu//(r)}"
cpu="${cpu//(R)}"
cpu="${cpu//CPU}"
cpu="${cpu//Processor}"
cpu="${cpu//Dual-Core}"
cpu="${cpu//Quad-Core}"
cpu="${cpu//Six-Core}"
cpu="${cpu//Eight-Core}"
cpu="${cpu//Core}"
cpu="${cpu//with Radeon * Graphics}"
# Add cpu cores to output
2017-09-29 20:27:53 +02:00
cpu="${cpu/@/(${cores})phys. (${coresT})logi. @}"
2017-10-02 15:34:29 +02:00
figet_cpu="$cpu"
2017-08-26 09:05:54 +02:00
}
2017-10-04 10:29:08 +02:00
figet_de() { # thanks neofetch, assigne $figet_de #03/10/2017
2017-10-02 15:34:29 +02:00
# local de="${XDG_CURRENT_DESKTOP/i3}" #supprime i3??...
local de="$XDG_CURRENT_DESKTOP"
2017-08-26 09:05:54 +02:00
de="${de/'X-'}"
de="${de/Budgie:GNOME/Budgie}"
# Fallback to using xprop.
2017-10-02 15:34:29 +02:00
if [[ -n "$DISPLAY" && -z "$de" ]]; then
de="$(xprop -root | awk '/KDE_SESSION_VERSION|^_MUFFIN|xfce4|xfce5|TDE_FULL_SESSION/')" #ajout TDE_FULL_SESSION, oubli?à tester
fi
2017-08-26 09:05:54 +02:00
# Format strings
case "$de" in
2017-10-02 15:34:29 +02:00
"KDE_SESSION_VERSION"* )
de="KDE${de/* = }"
;;
*"TDE_FULL_SESSION"* )
de="Trinity"
;;
*"MUFFIN"* | "Cinnamon" )
de="$(cinnamon --version)"
de="${de:-Cinnamon}"
;;
2017-10-04 10:29:08 +02:00
*"xfce"*)
de="xfce" # suppression xfce4 ou xfce5 (la version ne sort pas dans xprop ou $XDG_
2017-10-02 15:34:29 +02:00
;;
2017-08-26 09:05:54 +02:00
esac
2017-10-02 15:34:29 +02:00
figet_de="${de,,}"
figet_de="${figet_de^}"
2017-08-26 09:05:54 +02:00
}
2017-09-27 20:40:28 +02:00
# 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
2017-10-02 15:34:29 +02:00
figet_disk(){ # 02/10/2017
local vendor_model idisk
2017-10-02 00:34:34 +02:00
disk_lsblk="$(lsblk -o NAME,FSTYPE,SIZE,LABEL,MOUNTPOINT,UUID)"
2017-09-27 20:40:28 +02:00
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
2017-10-01 06:09:57 +02:00
disk_detail="disque: vendeur modèle n° serie révision"$'\n'
2017-09-27 20:40:28 +02:00
for idisk in $(grep -v 'loop' <<< $(ls /sys/block/)); do
2017-10-02 00:34:34 +02:00
vendor_model="$(sed -n '2p' <<< $(lsblk -o VENDOR,MODEL /dev/$idisk) | xargs )"
if [ -z "$vendor_model" ]; then
vendor_model=" na na "
vendor_model="$(ls -l /dev/disk/by-id/ | awk '{print $9,$11}' | sed '/-part/d' | grep $idisk)"
vendor_model="$(sed -E 's/.*-(.*)_[0-9]+.*$/\1/;s/_/ /g' <<< $vendor_model)"
fi
disk_detail+="$idisk: $vendor_model $(sed -n '2p' <<< "$(lsblk -o SERIAL,REV /dev/$idisk)")"$'\n'
2017-09-27 20:40:28 +02:00
if [ "$(sed -n '2p' <<< $(lsblk -o HOTPLUG /dev/$idisk) | xargs)" == "1" ]; then
disk_hotplug+="$idisk "
else
disk_fix+="$idisk " # "sda sdb sdc"
fi
done
2017-10-02 15:34:29 +02:00
disk_detail=${disk_detail::-1}
2017-09-27 20:40:28 +02:00
# séquences partitions fixes, $part_fix, $(printf '/dev/%s ' $part_fix), "sda1 sda2 sda3"
2017-09-28 20:47:34 +02:00
part_fix="$(lsblk -o KNAME,MOUNTPOINT $(printf '/dev/%s ' $disk_fix) 2>/dev/null | grep '/')"
part_fix="$(awk '{print $1}' <<< $part_fix | tr '\n' ' ')"
2017-09-27 20:40:28 +02:00
# séquences partitions amovibles, $part_hotplug
2017-09-28 20:47:34 +02:00
part_hotplug="$(lsblk -o KNAME,MOUNTPOINT $(printf '/dev/%s ' $disk_hotplug) 2>/dev/null | grep '/')"
part_hotplug="$(awk '{print $1}' <<< $part_hotplug | tr '\n' ' ')"
2017-09-27 20:40:28 +02:00
[ "$disk_fix" ] || disk_fix="-"
[ "$part_fix" ] || part_fix="-"
[ "$disk_hotplug" ] || disk_hotplug="-"
[ "$part_hotplug" ] || part_hotplug="-"
# total espaces partition montées et fixes
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)"
2017-10-02 00:34:34 +02:00
disk_ata="$(ls -l /dev/disk/by-id/ | awk '{print $9,$11}')"
2017-10-01 06:09:57 +02:00
disk_ata="$(sed '/^ata/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/' <<< $disk_ata | tr '\n' ' ')"
2017-10-02 00:34:34 +02:00
disk_usb="$(ls -l /dev/disk/by-id/ | awk '{print $9,$11}')"
2017-10-01 06:09:57 +02:00
disk_usb="$(sed '/^usb/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/' <<< $disk_usb | tr '\n' ' ')"
2017-10-02 00:34:34 +02:00
disk_mmc="$(ls -l /dev/disk/by-id/ | awk '{print $9,$11}')"
2017-10-01 06:09:57 +02:00
disk_mmc="$(sed '/^mmc/!d; /part/d; /\/mmcblk/!d; s/^.*\(mmcblk..*\)$/\1/' <<< $disk_mmc | tr '\n' ' ')"
2017-10-02 00:34:34 +02:00
disk_nvme="$(ls -l /dev/disk/by-id/ | awk '{print $9,$11}')"
2017-10-01 06:09:57 +02:00
disk_nvme="$(sed '/^nvme/!d; /part/d; /\/nvme/!d; s/^.*\(nvme...*\)$/\1/' <<< $disk_nvme | tr '\n' ' ')"
2017-09-27 20:40:28 +02:00
[ "$disk_ata" ] || disk_ata="-"
[ "$disk_usb" ] || disk_usb="-"
[ "$disk_mmc" ] || disk_mmc="-"
[ "$disk_nvme" ] || disk_nvme="-"
2017-08-26 09:05:54 +02:00
}
2017-10-02 15:34:29 +02:00
figet_distro() { # thanks neofetch, assigne $figet_distro # 02/10/2017
local distro file
2017-08-26 09:05:54 +02:00
if type -p lsb_release >/dev/null; then distro="$(lsb_release -sd)";
elif type -p guix >/dev/null; then distro="GuixSD";
elif type -p crux >/dev/null; then distro="$(crux)";
else
# Source the os-release file
2017-10-02 15:34:29 +02:00
for file in /etc/os-release /usr/lib/os-release /etc/*release /usr/lib/*release; do
source "$file" && break
2017-08-26 09:05:54 +02:00
done
# Workarounds for distros that go against the os-release standard.
[[ -z "${distro// }" ]] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/*ease /usr/lib/*ease)"
[[ -z "${distro// }" ]] && distro="$(awk -F '=' '{print $2; exit}' /etc/*ease /usr/lib/*ease)"
# for debian, add version
grep -qi 'Debian' /etc/issue && distro="$(sed 's/"//g' <<< $distro) $(cat /etc/debian_version)"
2017-08-06 02:43:48 +02:00
fi
2017-08-26 09:05:54 +02:00
[[ -z "$distro" ]] && distro="$os (Unknown)"
2017-10-02 15:34:29 +02:00
figet_distro="$distro"
2017-08-06 02:43:48 +02:00
}
2017-10-02 15:34:29 +02:00
figet_gpu() { # thanks neofetch, assigne $figet_gpu # 02/10/2017
local gpu="$(lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}')"
2017-08-26 09:05:54 +02:00
case "$gpu" in
*"advanced"*)
gpu="${gpu//Intel*$'\n'}"
gpu="${gpu/'[AMD/ATI]' }"
gpu="${gpu/'[AMD]' }"
gpu="${gpu/OEM }"
gpu="${gpu/ \/ *}"
gpu="${gpu/*\[}"
gpu="${gpu/\]*}"
gpu="AMD $gpu" ;;
*"nvidia"*)
gpu="${gpu//Intel*$'\n'}"
gpu="${gpu/*\[}"
gpu="${gpu/\]*}"
gpu="NVIDIA $gpu" ;;
*"virtualbox"*)
gpu="VirtualBox Graphics Adapter" ;;
esac
[[ "$gpu" =~ "intel" ]] && gpu="Intel Integrated Graphics"
2017-10-02 15:34:29 +02:00
figet_gpu="$gpu"
2017-08-26 09:05:54 +02:00
}
2017-09-04 13:35:14 +02:00
# assigne $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type
# $ifnames, $ifnames_type, $mac_address, mac_address_type
2017-10-02 15:34:29 +02:00
figet_ip() { # 02/10/2017
local ifn
2017-08-26 09:05:54 +02:00
[ -z "$(which ip)" ] && return 1
2017-09-04 13:35:14 +02:00
ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print " ",$4,"(",$2,")"}')"
2017-08-26 09:05:54 +02:00
ip_local_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)"
2017-09-04 13:35:14 +02:00
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,")"}')"
2017-09-03 09:37:47 +02:00
gateway_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $gateway)"
2017-10-01 06:09:57 +02:00
gateway_one="$(awk 'FNR==1 {print " ",$1}' <<< $gateway)"
2017-09-04 13:35:14 +02:00
for ifn in $(ls /sys/class/net/) ; do
2017-10-02 00:34:34 +02:00
[ "$ifn" != "lo" ] && ifnames+=" $ifn"$'\n'
2017-09-04 13:35:14 +02:00
[ "$ifn" != "lo" ] && mac_address+=" $ifn: $(cat /sys/class/net/$ifn/address)"$'\n'
done
ifnames="$(sed '/^$/d' <<< $ifnames)" # suppression \n final
ifnames_type+="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ifnames)"
mac_address="$(sed '/^$/d' <<< $mac_address)" # suppression \n final
mac_address_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $mac_address)"
2017-08-26 09:05:54 +02:00
}
2017-09-03 09:37:47 +02:00
# $1=4|6, assigne $ip_public
2017-10-02 15:34:29 +02:00
figet_ip_public(){ # 02/10/2017
local dig_test ip_test iip
2017-08-26 09:05:54 +02:00
list_ip4(){
ip_test+=" http://whatismyip.akamai.com"
ip_test+=" http://ipof.in/txt"
ip_test+=" http://eth0.me"
ip_test+=" http://ipecho.net/plain"
ip_test+=" http://alma.ch/myip.cgi"
ip_test+=" http://checkip.amazonaws.com"
ip_test+=" http://eth0.me"
ip_test+=" http://ipecho.net/plain"
ip_test+=" api.infoip.io/ip" # http & https
ip_test+=" api.ipify.org" # http & https
ip_test+=" ipinfo.io/ip" # http & https
}
list_ip6(){
ip_test+=" http://ipv6.whatismyip.akamai.com"
ip_test+=" http://bot.whatismyipaddress.com"
ip_test+=" ip.tyk.nu" # http & https
ip_test+=" l2.io/ip" # http & https
ip_test+=" ident.me" # http & https
ip_test+=" icanhazip.com" # http & https
ip_test+=" wgetip.com" # http & https
ip_test+=" https://canhazip.com"
ip_test+=" https://tnx.nl/ip"
}
list_ip4_dig(){
dig_test+=" whoami.akamai.net/@ns1-1.akamaitech.net"
dig_test+=" myip.opendns.com/@resolver1.opendns.com"
dig_test+=" myip.opendns.com/@resolver2.opendns.com"
dig_test+=" myip.opendns.com/@resolver3.opendns.com"
dig_test+=" myip.opendns.com/@resolver4.opendns.com"
}
list_ip6_dig(){
dig_test+=" -6/myip.opendns.com/aaaa/@resolver1.ipv6-sandbox.opendns.com"
dig_test+=" -6/myip.opendns.com/aaaa/@resolver2.ipv6-sandbox.opendns.com"
}
unset ip_public
2017-09-03 09:37:47 +02:00
if [ "$1" == "4" ]; then
ping -4 -c1 google.com &>/dev/null || ping -4 -c1 free.fr &>/dev/null || return 1 # test connectivité
2017-08-26 09:05:54 +02:00
list_ip4_dig
list_ip4
ip_telnet=4.ifcfg.me
2017-09-03 09:37:47 +02:00
elif [ "$1" == "6" ]; then
ping -6 -c1 google.com &>/dev/null || ping -6 -c1 free.fr &>/dev/null || return 1 # test connectivité
2017-08-26 09:05:54 +02:00
list_ip6_dig
list_ip6
ip_telnet=6.ifcfg.me
2017-09-03 09:37:47 +02:00
fi
2017-08-26 09:05:54 +02:00
if [ "$(which dig)" ] && [ -z "$ip_public" ]; then
2017-10-02 15:34:29 +02:00
for iip in $dig_test ; do
ip_public="$(dig +short $(sed 's;/; ;g' <<< $iip))"
2017-08-26 09:05:54 +02:00
[ "$ip_public" ] && break
done
fi
if [ "$(which wget)" ] && [ -z "$ip_public" ]; then
cmd="wget --quiet --tries=1 --timeout=5 -O - "
2017-10-02 15:34:29 +02:00
for iip in $ip_test ; do
ip_public="$($cmd $iip)"
2017-08-26 09:05:54 +02:00
[ "$ip_public" ] && break
done
fi
if [ "$(which curl)" ] && [ -z "$ip_public" ]; then
cmd="curl --silent --location --retry 0 --max-time 5" #--location pour aider redirections
2017-10-02 15:34:29 +02:00
for iip in $ip_test ; do
ip_public="$($cmd $iip)"
2017-08-26 09:05:54 +02:00
[ "$ip_public" ] && break
done
2017-08-06 02:43:48 +02:00
fi
2017-08-26 09:05:54 +02:00
if [ "$(which telnet)" ] && [ -z "$ip_public" ]; then
ip_public="$(telnet $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4)"
2017-08-17 10:49:12 +02:00
fi
2017-08-26 09:05:54 +02:00
if [ "$(which nc)" ] && [ -z "$ip_public" ] && [ "$1" != "IPv6" ]; then
ip_public="$(nc $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4)"
2017-08-17 10:49:12 +02:00
fi
2017-08-26 09:05:54 +02:00
if [ -z "$ip_public" ]; then
f__error "il manque une des commandes suivantes:\n" \
"dig / wget / curl / telnet / nc \n" \
"ou les ip de test sont devenues défaillantes\n" \
"réessayer après avoir installé dig (dnsutils) et wget\n" \
"si l'erreur persiste, merci de prévenir $projet $contact"
2017-08-06 02:43:48 +02:00
fi
2017-08-02 01:16:24 +02:00
}
2017-10-04 10:29:08 +02:00
figet_memory() { # thanks neofetch, assigne $figet_memory # 03/10/2017
2017-08-26 09:05:54 +02:00
# MemUsed = Memtotal + Shmem - MemFree - Buffers - Cached - SReclaimable
# Source: https://github.com/KittyKatt/screenFetch/issues/386#issuecomment-249312716
2017-10-02 15:34:29 +02:00
local mem_used mem_total a b
2017-08-26 09:05:54 +02:00
while IFS=":" read -r a b; do
case "$a" in
2017-10-04 10:29:08 +02:00
"MemTotal" )
mem_used="$((mem_used+=${b/kB}))"
mem_total="${b/kB}"
;;
"Shmem" )
mem_used="$((mem_used+=${b/kB}))"
;;
"MemFree" | "Buffers" | "Cached" | "SReclaimable" )
mem_used="$((mem_used-=${b/kB}))"
;;
2017-08-26 09:05:54 +02:00
esac
done < /proc/meminfo
2017-08-30 22:46:26 +02:00
mem_used="$((mem_used / 1024))"
mem_total="$((mem_total / 1024))"
2017-08-26 09:05:54 +02:00
memory="${mem_used}Mo / ${mem_total}Mo"
2017-10-02 15:34:29 +02:00
figet_memory="$memory"
2017-08-17 17:32:34 +02:00
}
2017-10-02 15:34:29 +02:00
figet_mod_net(){ # thanks wireless-info, assigne $modules_net # 01/10/2017
2017-10-02 00:34:34 +02:00
local MODMATCHES LSMODMATCHES
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)"
2017-10-02 15:34:29 +02:00
modules_net="$(lsmod | grep -E "(^|[[:punct:] ])($MODMATCHES|$LSMODMATCHES)[^[:punct:] ]*([[:punct:] ]|$)")"
2017-08-17 17:32:34 +02:00
}
2017-10-02 15:34:29 +02:00
figet_resolution() { # thanks neofetch, assigne $figet_resolution # 02/10/2017
local resolution
2017-08-26 09:05:54 +02:00
if type -p xrandr >/dev/null; then
resolution="$(xrandr --nograb --current | awk 'match($0,/[0-9]*\.[0-9]*\*/) {printf $1 " @ " substr($0,RSTART,RLENGTH) "Hz, "}')"
resolution="${resolution//\*}"
resolution="${resolution//\.[0-9][0-9]}"
elif type -p xdpyinfo >/dev/null; then resolution="$(xdpyinfo | awk '/dimensions:/ {printf $2}')"; fi
resolution="${resolution%,*}"
2017-10-02 15:34:29 +02:00
figet_resolution="$resolution"
2017-08-03 13:37:46 +02:00
}
2017-10-02 15:34:29 +02:00
figet_shell(){ # thanks neofetch, assigne $figet_shell # 02/10/2017
local shell
2017-08-26 09:05:54 +02:00
shell="${SHELL##*/}"
case "${SHELL##*/}" in
"bash")
shell+=" ${BASH_VERSION/-*}" ;;
"zsh")
shell+="$(zsh --version)"
shell="${shell/ zsh}" ;;
"mksh" | "ksh")
shell+="$("$SHELL" -c 'printf "%s" "$KSH_VERSION"')"
shell="${shell/ * KSH}" ;;
"tcsh" | "csh")
shell+="$("$SHELL" --version)"
shell="${shell/tcsh}"
shell="${shell/\(*}" ;;
"fish")
shell+="$(fish -c 'printf "%s" "$FISH_VERSION"')" ;;
esac
2017-10-02 15:34:29 +02:00
figet_shell="$shell"
2017-08-26 09:05:54 +02:00
}
2017-10-02 15:34:29 +02:00
figet_wm() { # thanks neofetch, assigne $figet_wm # 02/10/2017
local id wm
2017-08-26 09:05:54 +02:00
if [ -n "$DISPLAY" ]; then
id="$(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}')"
wm="$(xprop -id "$id" -notype -f _NET_WM_NAME 8t)"
wm="${wm/*_NET_WM_NAME = }"
wm="${wm/\"}"
wm="${wm/\"*}"
# Fallback for Wayland wms
[[ "$wm" == "xwlc" ]] && wm="$(ps -e | grep -m 1 -o -F -e "sway" -e "orbment" -e "velox" -e "orbital")"
fi
2017-10-02 15:34:29 +02:00
figet_wm="$wm"
2017-08-06 02:43:48 +02:00
}
2017-08-26 09:05:54 +02:00
fipaste(){
2017-09-27 20:40:28 +02:00
f__requis "curl" # requis pour paste
2017-08-30 01:04:45 +02:00
fipaste_curl_pastery "$fileOutput" "$pasteDuration" "$optDebug"
2017-08-26 09:05:54 +02:00
# à tester fipaste_curl_markdownshare "$fileOutput"
2017-08-06 02:43:48 +02:00
}
2017-09-22 14:55:55 +02:00
fipaste_curl_pastery(){ # $1 fichier à exporter, $2 durée de conservation en jour; $3 debug # 22/09/2017
2017-08-19 03:45:31 +02:00
[ -e "$1" ] || f__error "fichier $1 inexistant"
2017-08-30 22:46:26 +02:00
local curl id
2017-08-19 03:45:31 +02:00
# curl -X POST "https://www.pastery.net/api/paste/?title=getInfo&language=markdown" -F file=@$1
2017-08-30 22:46:26 +02:00
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)"
2017-09-22 14:55:55 +02:00
f__info "\n\n votre paste:$GREEN https://www.pastery.net/$id/"
2017-08-19 03:45:31 +02:00
[ "$3" == "debug" ] && echo -e "\n$curl\n"
# ?api_key=<api_key>
# &duration=<duration> en mn, 1 jour par défaut
# &language=autodetect possible
# &max_views=<max_views>
# 100ko max
}
2017-10-02 15:34:29 +02:00
fipaste_curl_markdownshare(){ # à tester/finir
2017-08-19 03:45:31 +02:00
[ -e "$1" ] || f__error "fichier $1 inexistant"
curl -H "Accept: application/json" -X POST -F "text=<$1" https://markdownshare.com/create/
#-A, --user-agent and -e, --referer options
#If you wish to allow a post to expire then add an expire= parameter too:
#expire=Nh Expire in N hours.
#expire=Nd Expire in N days.
#-d expire ? ou --data expire
}
2017-08-28 10:09:47 +02:00
# inscription dans tache upgrade en anacron hebdomadaire, via cron horaire, $1=upgrade|install|remove
2017-09-22 14:55:55 +02:00
fscript_cronAnacron(){ # 06/09/2017
2017-08-30 22:46:26 +02:00
local dirAnacron dirSpool fileAnacron
2017-08-26 09:05:54 +02:00
[ "$(type -t fscript_cronAnacron_special)" ] && fscript_cronAnacron_special # test, si fonction spécifique, appel
2017-08-30 22:46:26 +02:00
dirAnacron="/home/$user_/.config/anacron"
dirSpool="$dirAnacron/spool"
fileAnacron="$dirAnacron/$script.anacrontab"
2017-09-06 14:08:03 +02:00
[ "$EUID" -eq 0 ] && sed -i "/$script.anacrontab/d" /etc/crontab
2017-08-26 09:05:54 +02:00
case "$1" in
install | upgrade )
mkdir -p "$dirAnacron"
# table anacron
echo "7 10 $script nice /opt/bin/$script --upgrade 1>/dev/null" > "$fileAnacron" # juste erreurs en syslog
## anacron journalier pour dev logname
2017-08-27 07:05:26 +02:00
if [ -e "$fileDev" ]; then
echo "1 00 $script""Dev nice /opt/bin/$script --upgrade 1>/dev/null" >> "$fileAnacron"
2017-08-26 09:05:54 +02:00
fi
# création spool anacron utilisateur
mkdir -p "$dirSpool"
2017-09-06 14:08:03 +02:00
chown -R "$user_:" "$dirAnacron" "$dirSpool"
if [ "$EUID" -eq 0 ]; then
2017-08-26 09:05:54 +02:00
# crontab pour activation horaire anacron
echo "@hourly $user_ /usr/sbin/anacron -t $fileAnacron -S $dirSpool" >> /etc/crontab
fi
[ "$(grep "$script" /etc/crontab)" ] || echo f__error "inscription crontab" \
"certains systèmes semblent poser poser problème, merci de rapporter ce bug à $projet $contact"
;;
remove )
rm "$dirSpool/$script"* &>/dev/null
rm "$fileAnacron" &>/dev/null
rmdir "$dirSpool" "$dirAnacron" &>/dev/null
;;
esac
}
# version script en ligne, assigne $versionScript, $script_aJour=ok|ko
2017-09-22 14:55:55 +02:00
fscript_get_version(){ # 07/09/2017
2017-08-27 07:36:27 +02:00
f__info "raw" "$GREEN""version script en cours: $version"
2017-08-26 09:05:54 +02:00
versionScript="$(wget -q --tries=2 --timeout=15 -O - "$urlScript" | grep '^version=' | cut -d '=' -f 2)"
if [ "$versionScript" ]; then
if [ "$version" != "$versionScript" ]; then
f__info "version script en ligne: $versionScript, mise à jour possible"
script_aJour="ko"
else
f__info "version script en ligne: $versionScript"
script_aJour="ok"
fi
2017-09-09 20:26:43 +02:00
else f__info "version script en ligne $RED""non accessible"; fi
2017-08-26 09:05:54 +02:00
}
# installation du script dans le système
2017-09-22 14:55:55 +02:00
fscript_install(){ # 06/09/2017
2017-08-30 01:04:45 +02:00
if grep -q 'bin' <<< "$(dirname $0)" ; then
f__info "$RED""l'installation dans le système doit se faire depuis un script local $GREEN(./$script -i )$COLOR"
2017-09-06 14:08:03 +02:00
return
2017-08-26 09:05:54 +02:00
fi
2017-09-06 14:08:03 +02:00
if [ "$EUID" -ne 0 ]; then
2017-08-30 01:04:45 +02:00
f__info "$RED""vous devez être ROOT pour installer ce script dans le système$COLOR"
return 3
fi
[ "$(type -t fscript_install_special)" ] && fscript_install_special # test, si fonction spécifique, appel
2017-08-26 09:05:54 +02:00
f__requis "wget anacron cron"
# install /opt
mkdir -p /opt/bin/
cp -d "$(basename $0)" "/opt/bin/$script"
ln -s "/opt/bin/$script" "/usr/bin/$script" &>/dev/null
chmod 755 "/opt/bin/$script"
# cron/anacron install
fscript_cronAnacron "install"
# création fichier log
touch "$fileLogs"
chmod 644 "$fileLogs"
2017-09-06 14:08:03 +02:00
chown "$user_:" "$fileLogs" "/opt/bin/$script"
2017-08-27 07:05:26 +02:00
[ -e "$fileDev" ] || rm "$(basename $0)" &>/dev/null ## on efface pas si fileDev (dev)
2017-08-27 07:51:11 +02:00
f__info "log" "$script $version installé dans le système." "maintenant, appel du script par:$GREEN $script$BLUE (sans ./)"
2017-08-26 09:05:54 +02:00
}
# suppression du script dans le système
2017-09-22 14:55:55 +02:00
fscript_remove(){ # 06/09/2017
2017-08-30 01:04:45 +02:00
if ! grep -q 'bin' <<< "$(dirname $0)" ; then
f__info "$RED""cette fonction doit être appelée depuis le script installé dans le système $GREEN($script -r)$COLOR"
return 1
fi
if [ ! -x "/opt/bin/$script" ];then
f__info "$RED$script n'est pas installé$COLOR"
return 2
fi
2017-09-06 14:08:03 +02:00
if [ "$EUID" -ne 0 ]; then
2017-08-30 01:04:45 +02:00
f__info "$RED""vous devez être ROOT pour supprimer ce script dans le système$COLOR"
return 3
fi
2017-08-26 09:05:54 +02:00
# suppression de /opt
2017-09-06 14:08:03 +02:00
rm "/opt/bin/$script" &>/dev/null
unlink "/usr/bin/$script" &>/dev/null
2017-08-26 09:05:54 +02:00
# cron/anacron remove
fscript_cronAnacron "remove"
f__info "log" "$script $version supprimé du système."
}
# mise à jour script si dispo
2017-09-22 14:55:55 +02:00
fscript_update(){ # 06/09/2017
2017-08-30 01:04:45 +02:00
if ! grep -q 'bin' <<< "$(dirname $0)" ; then
f__info "$RED""cette fonction doit être appelée depuis le script installé dans le système $GREEN($script -u)$COLOR"
2017-09-06 14:08:03 +02:00
return
2017-08-30 01:04:45 +02:00
fi
2017-08-26 09:05:54 +02:00
fscript_get_version
if [ "$script_aJour" == "ok" ]; then
2017-08-30 01:04:45 +02:00
f__info "log" "pas de mise à jour disponible pour $script $version"
2017-08-26 09:05:54 +02:00
return 0
fi
2017-09-06 14:08:03 +02:00
local dirTemp="/tmp/$script-$RANDOM"
2017-08-26 09:05:54 +02:00
mkdir -p "$dirTemp"
2017-09-06 14:08:03 +02:00
wget -q --tries=2 --timeout=15 -O "$dirTemp/$script" "$urlScript"
2017-08-26 09:05:54 +02:00
if [ "$?" != "0" ]; then f__wget_test "$urlScript"; fi
2017-09-06 14:08:03 +02:00
chmod 755 "$dirTemp/$script"
chown "$user_:" "$dirTemp/$script"
cp -d "$dirTemp/$script" "/opt/bin/$script"
rm -rf "$dirTemp/"
2017-08-26 09:05:54 +02:00
fscript_cronAnacron "upgrade"
2017-08-26 23:42:34 +02:00
f__info "log" "$script mis à jour en version $versionScript"
2017-08-26 09:05:54 +02:00
}
2017-07-30 17:08:05 +02:00
# initialisation
2017-09-04 13:35:14 +02:00
PATH='/usr/sbin:/usr/bin:/sbin:/bin'; TERM=xterm ; IFS=$' \t\n'
export PATH TERM IFS
2017-09-25 23:38:39 +02:00
urlScript="https://frama.link/getinfo"
2017-09-29 20:27:53 +02:00
f__wget_test "$urlScript" "test" || urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/$script"
2017-09-25 23:38:39 +02:00
urlNotice="https://frama.link/doc-getinfo"
f__wget_test "$urlNotice" test || urlNotice="https://kyodev.frama.io/kyopages/scripts/getInfo/"
2017-08-03 02:44:53 +02:00
fileOutput="getInfo_rapport.md"
fileLogs="/var/log/sdeb_$script.log"
2017-08-28 10:09:47 +02:00
fileDev="/opt/bin/fileDev"
2017-09-15 08:54:24 +02:00
2017-08-07 11:47:09 +02:00
f__affichage
2017-10-02 15:34:29 +02:00
f__user
retourFUser="$?"
[ "$retourFUser" -eq 1 ] && f__error "user indéterminé, pour éventuellement contourner, lancer le script avec:\n USER_INSTALL=user $0 \n"
2017-09-28 20:47:34 +02:00
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
2017-09-27 20:40:28 +02:00
[ "$(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
2017-08-01 01:48:22 +02:00
2017-08-19 03:45:31 +02:00
prg_1(){ # début
2017-09-28 20:47:34 +02:00
# rm "$fileOutput" &>/dev/null
# touch "$fileOutput"
echo > "$fileOutput"
2017-08-07 09:49:37 +02:00
chown $user_: "$fileOutput"
2017-08-18 00:14:09 +02:00
hote="$(uname -n)"
2017-10-02 15:34:29 +02:00
dateRapport="$(date '+%d/%m/%Y %H:%M %z')"
2017-09-25 23:38:39 +02:00
echo -e "# $script sur $hote \n" > "$fileOutput"
2017-10-02 00:34:34 +02:00
echo -e "Rapport du $dateRapport -- [$script $version]($urlNotice) \n" >> "$fileOutput"
2017-08-06 19:10:10 +02:00
}
2017-09-28 20:47:34 +02:00
prg_2(){ # traitements principaux
2017-09-22 14:55:55 +02:00
printf " ."
2017-08-17 10:49:12 +02:00
fi_systeme; printf "."
fi_cpu; printf "."
fi_gpu; printf "."
2017-09-28 20:47:34 +02:00
fi_batt; printf "."
2017-08-17 10:49:12 +02:00
fi_localisation; printf "."
2017-09-22 14:55:55 +02:00
fi_sources; printf "."
2017-08-17 10:49:12 +02:00
fi_disk; printf "."
fi_reseau; printf "."
fi_nm; printf "." # si network manager, état et conf
fi_nm_wifis; printf "." # si network manager, wifi proximité
fi_usb; printf "."
fi_system_analyse; printf "."
2017-09-24 06:27:21 +02:00
fi_dmesg; printf "."
fi_nonFree; printf ".\n\n"
2017-08-03 02:44:53 +02:00
}
2017-08-06 02:43:48 +02:00
prg_3(){ # fin de traitements
2017-09-22 16:31:40 +02:00
echo -e "--- \n" >> "$fileOutput"
2017-09-25 23:38:39 +02:00
echo -e "[$script $version]($urlNotice) -- $dateRapport\n" >> "$fileOutput"
2017-09-19 08:15:55 +02:00
f__dialog_oui_non "non" "exporter sur un pastebin par défaut?" && fipaste
2017-09-22 14:55:55 +02:00
f__info "\n le rapport est disponible en local, fichier:$GREEN $fileOutput"
2017-08-17 10:49:12 +02:00
f__info "vous pouvez le visualiser avec $GREEN$script -l$COLOR"
2017-08-03 02:44:53 +02:00
}
2017-07-30 17:08:05 +02:00
2017-08-30 01:04:45 +02:00
options=$@
# traitement option
2017-09-23 12:23:41 +02:00
for j in $options; do
case $j in
2017-09-28 20:47:34 +02:00
--debug-paste )
2017-08-30 01:04:45 +02:00
optDebug="debug"
;; # si debug, retour json de pastery.net
-t* )
2017-09-28 20:47:34 +02:00
pasteDuration="$(sed -En 's/-t([0-9]+)/\1/p' <<< $j)"
2017-08-30 01:04:45 +02:00
;; # durée de conservation standard du paste en jours
esac
done
2017-09-23 12:23:41 +02:00
unset j
2017-08-30 01:04:45 +02:00
[ "$pasteDuration" ] || pasteDuration=7 # durée de conservation standard du paste en jours
# purge option des options
2017-09-28 20:47:34 +02:00
options="$(sed -E 's/--debug-paste//g; s/-t[0-9]+//g' <<< $options | xargs)"
2017-08-30 01:04:45 +02:00
# traitement action
2017-09-04 13:35:14 +02:00
[ "$options" == "" ] && options="info"
2017-09-23 12:23:41 +02:00
for j in $options; do
case $j in
2017-08-30 01:04:45 +02:00
info )
prg_1
prg_2
prg_3
exit ;; # programme
2017-09-28 20:47:34 +02:00
--batt )
prg_1
fi_batt
prg_3
exit ;; # debug battery
--debug-batt )
prg_1
fi_batt "debug"
prg_3
exit ;; # debug battery
2017-08-30 01:04:45 +02:00
-d | --dmesg )
2017-09-22 15:38:15 +02:00
prg_1
2017-08-19 03:45:31 +02:00
fi_dmesg "dmesg"
2017-08-26 09:05:54 +02:00
prg_3
2017-08-30 01:04:45 +02:00
exit ;; # rapport dmesg only, root requis
2017-09-04 13:35:14 +02:00
-l | --list )
[ -e $fileOutput ] && cat $fileOutput || f__info "pas de rapport à afficher"
exit ;; # afficher le rapport existant
-p | --paste )
fipaste
exit ;; # exporte le rapport existant
2017-08-26 09:05:54 +02:00
--ip )
2017-09-03 09:37:47 +02:00
if figet_ip_public "4" ; then
f__info "raw" " ipv4 publique: $GREEN$ip_public"
else
f__info "$BLUE pas de connectivité ipv4"
fi
if figet_ip_public "6" ; then
f__info "raw" " ipv6 publique: $GREEN$ip_public"
else
f__info "$BLUE pas de connectivité ipv6"
fi
2017-08-30 01:04:45 +02:00
exit ;; # affiche ip public
2017-09-04 13:35:14 +02:00
-m | --mac )
figet_ip
f__info "mac_address:\n$GREEN$mac_address_type$COLOR"
exit ;; # affiche adresses mac
2017-08-30 01:04:45 +02:00
-s | --ssid )
2017-08-26 23:42:34 +02:00
fi_ssid
2017-08-30 01:04:45 +02:00
exit ;; # affiche configurations ssid, root requis
2017-08-26 23:42:34 +02:00
-i | --install )
2017-09-03 10:37:30 +02:00
fscript_install
2017-08-30 01:04:45 +02:00
exit ;; # installation du script dans le système
2017-08-26 23:42:34 +02:00
-r | --remove )
2017-09-03 10:37:30 +02:00
fscript_remove
2017-08-30 01:04:45 +02:00
exit ;; # suppression du script dans le système
2017-08-26 23:42:34 +02:00
-u | --upgrade )
opType="upgrade"
2017-09-03 10:37:30 +02:00
fscript_update
2017-08-30 01:04:45 +02:00
exit ;; # upgrade script si maj possible
2017-08-26 23:42:34 +02:00
-v | --version )
fscript_get_version
2017-08-30 01:04:45 +02:00
exit ;; # version du script, en ligne et exécuté
2017-08-26 23:42:34 +02:00
-h | --help | * )
2017-08-30 01:04:45 +02:00
f_help
exit ;; # affichage help
2017-08-03 02:44:53 +02:00
esac
done
2017-09-23 12:23:41 +02:00
unset j
2017-08-17 10:49:12 +02:00
exit 0
2017-08-02 01:16:24 +02:00
2017-09-25 23:38:39 +02:00
wget -O getInfo https://frama.link/getinfo
2017-08-02 01:16:24 +02:00
chmod +x getInfo && ./getInfo
2017-09-25 23:38:39 +02:00
wget -O getInfo https://framagit.org/kyodev/kyopages/raw/master/scripts/getInfo