This commit is contained in:
kyodev 2017-09-22 14:55:55 +02:00
parent 5f5a9d575e
commit f7d1d60cdf
2 changed files with 88 additions and 51 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
version=1.20.0
date="18/09/2017"
version=1.21.0
date="22/09/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
script="getInfo"
@ -13,7 +13,8 @@ urlNotice="https://kyodev.frama.io/kyopages/scripts/getInfo/"
# contributeurs: kyodev
#####
f__affichage(){ # v18/09/2017
# assigne $affichage_text
f__affichage(){ # 18/09/2017
f__color
affichage_text=" _ ___ __
__ _ ___| |_|_ _|_ __ / _| ___
@ -22,12 +23,13 @@ f__affichage(){ # v18/09/2017
\__, |\___|\__|___|_| |_|_| \___/
|___/
"
clear
echo -e "$BLUE$affichage_text\n$YELLOW version $version - $date$COLOR\n"
}
# detect system architecture, assign $architecture : 32bits, i686 | 64bits, amd64, return 1 on unknown architecture
# remarque, debian: dpkg --print-architecture affiche i386
f__architecture(){ # v08/2017 spécifique
f__architecture(){ # 08/2017 spécifique
case "$(uname -m)" in
amd64 | x86_64 )
architecture="64bits, amd64";;
@ -45,7 +47,7 @@ f__architecture(){ # v08/2017 spécifique
esac
}
f__color(){ # v18/09/2017
f__color(){ # 18/09/2017
YELLOW="$(printf "\033[0;33m")" # question
GREEN="$(printf "\033[0;32m")" # ok
BLUE="$(printf "\033[0;34m")" # info
@ -68,7 +70,7 @@ f__dialog_oui_non () { # 18/09/2017
}
# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si $opType=upgrade
f__error() { # v25/08/2017
f__error() { # 25/08/2017
echo -e "\n$RED $script $version, erreur critique: $1 $COLOR"
for (( i=2 ; i<=$# ; i++ )); do echo -e " $BLUE${!i}"; done
echo "$COLOR"
@ -77,7 +79,7 @@ f__error() { # v25/08/2017
}
# affichage des paramètres en bleu, si $1=raw pas de ligne vide à la fin, si $1=log $2 uniquement logué
f__info() { # v25/08/2017
f__info() { # 25/08/2017
local depart=1
if [ "$1" == "raw" ] || [ "$1" == "log" ]; then depart=2; fi
[ "$1" == "log" ] && f__log "$(sed -E 's/\\t//;s/\\n// ' <<< $2 | xargs )"
@ -86,7 +88,7 @@ f__info() { # v25/08/2017
}
# log spécifique, fichier log limité à 10000octets, $1 message à loguer
f__log(){ # v08/O9/2017
f__log(){ # 08/O9/2017
if [ -w "$fileLogs" ]; then
if [ "$(stat -c %s $fileLogs)" -ge "10000" ]; then
echo "$(date +%Y%m%d\ %H%M%S) $1" &>/dev/null > "$fileLogs"
@ -104,7 +106,7 @@ f__log(){ # v08/O9/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(){ # v30/08/2017-3
f__requis(){ # 30/08/2017-3
local dependsMissing packagesMissing command package
unset debOnlyPackages debOnlyPresents
for i in $1; do
@ -134,7 +136,7 @@ f__requis(){ # v30/08/2017-3
# 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(){ # v30/08/2017-4
f__user(){ # 30/08/2017-4
if [ "$USER_INSTALL" ]; then # user_ via variable environnement, moyen d'injecter root
user_="$USER_INSTALL";
return 0
@ -168,7 +170,7 @@ f__user(){ # v30/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
# si $2=loc affiche seulement location
f__wget_test(){ # v07/09/2017
f__wget_test(){ # 07/09/2017
local file_test_wget retourWget retourHttp location
file_test_wget="/tmp/testWget-$RANDOM"
wget -Sq --tries=1 --timeout=10 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget" || retourWget="$?"
@ -210,7 +212,7 @@ f__wget_test(){ # v07/09/2017
exit 0
}
f_help(){ # v07/09/2017
f_help(){ # 07/09/2017
printf "$BLUE"
cat << 'EOF'
----------------------------------------------------------------------
@ -352,21 +354,28 @@ fi_dmesg(){ # root only, si $1=dmesg rapport dmesg only # 06/09/2017
echo -e "$text" >> "$fileOutput"
}
fi_gpu(){ # 30/08/2017
local graphCards openGl resolutions extraitXorg text
fi_gpu(){ # 22/09/2017
local slotGraphCards 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')"
# graphCards="$(lspci -nnv | grep -iEA 13 '^[0-9]+.*vga|display|3d')"
slotGraphCards="$(lspci | grep -iE 'vga|display|3d' | sed -En 's/^([0-9.:]+).*$/\1/gp')"
for i in $slotGraphCards; do
graphCards+='```\n'
graphCards+="$(lspci -s $i -nnv)\n"
graphCards+='```\n'
done
graphCards="$(echo -e "$graphCards")"
[ "$(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)"
###
text="## graphisme \n\n"
figet_gpu; text+="**GPU: $gpu** \n"
text+="| | | \n"
text+=" --- | --- \n"
figet_gpu; text+="GPU | **$gpu** \n\n"
figet_resolution; text+="**résolution: $resolution** \n\n"
text+="**lspci -nnvvv | grep -iEA 13 '^[0-9]+.*vga|display|3d'** (matériel) \n"
text+='```\n'
text+="$graphCards \n"
text+='```\n\n'
text+="**lspci -nnv | grep -iEA 13 'vga|display|3d'** \n"
text+="$graphCards \n\n"
if [ "$openGl" ]; then
text+="**glxinfo | grep 'OpenGL version string:'** \n"
text+='```\n'
@ -464,10 +473,17 @@ fi_nm_wifis(){ # 30/08/2017
echo -e "$text" >> "$fileOutput"
}
fi_reseau(){ # 04/09/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')"
fi_reseau(){ # 22/09/2017
local slotNetCards netCards ip_a iwconfig interfaces route resolv text liste_canaux_wifi
# netCards="$(lspci -nnk | grep -iEA 5 'network|ethernet')"
# netCards="$(lspci -nnv | grep -iEA 15 'network|ethernet')"
slotNetCards="$(lspci | grep -iE 'network|ethernet' | sed -En 's/^([0-9.:]+).*$/\1/gp')"
for i in $slotNetCards; do
netCards+='```\n'
netCards+="$(lspci -s $i -nnv)\n"
netCards+='```\n'
done
netCards="$(echo -e "$netCards")"
ip_a="$(ip a | sed '/inet6.*scope global/d; /link\/ether/d; /valid_lft/d')" # filtre sur inet6 & scope global & adr MAC & bail?
if [ "$(which iwlist)" ]; then #paquet wireless-tools requis
iwconfig="$(iwconfig 2>&1 | grep -v 'no wireless extensions' | grep -v '^$')"
@ -490,6 +506,7 @@ fi_reseau(){ # 04/09/2017
text+='```\n'
text+="$ip_local_type \n"
text+='```\n\n'
text+="* les adresses Mac peut être affichées avec "'`./getInfo -m` ou `getInfo -m`'" (script installé) \n\n"
if grep -q 'wlx' <<< "$ifnames"; then
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"
@ -499,11 +516,9 @@ fi_reseau(){ # 04/09/2017
text+='```\n'
text+="$gateway_type \n"
text+='```\n\n'
text+="l'IP publique peut être connue avec: "'`./getInfo --ip` ou `getInfo --ip` (script installé)\n\n'
text+="**lspci -nnk | grep -iEA 3 'network|ethernet'** \n"
text+='```\n'
text+="$netcards \n"
text+='```\n\n'
text+="* l'IP publique peut être connue avec: "'`./getInfo --ip` ou `getInfo --ip` (script installé) \n\n'
text+="**lspci -nnv | grep -iEA 15 'network|ethernet'** \n"
text+="$netCards \n\n"
text+="**ip address** (ipv6 lien local, pas d'adresses MAC) \n"
text+='```\n'
text+="$ip_a \n"
@ -531,6 +546,7 @@ fi_reseau(){ # 04/09/2017
text+='```\n'
text+="$liste_canaux_wifi \n"
text+='```\n\n'
text+="* la configuration ssid utilisé peut être connue (si NetworkManager utilisé) avec "'`./getInfo -s` ou `getInfo -s`'" (script installé) \n\n"
fi
if [ "$netmgrinst" ]; then
text+="### network managers \n\n"
@ -542,9 +558,9 @@ fi_reseau(){ # 04/09/2017
echo -e "$text" >> "$fileOutput"
}
fi_sources(){ # 30/08/2017
fi_sources(){ # 22/09/2017
[ "$(which apt)" ] || return 0 # retour si pas d'apt ? et aptitude...????
local sources dateMaj apt autoremove paquetToRemove httpredir upgradable dpkgArch paquetBiz text
local sources dateMaj apt autoremove paquetToRemove httpredir upgradable nbUpgradable dpkgArch paquetBiz text
printf "."
sources="$(grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null | sed 's/ / /g; s/:/: /')"
dateMaj="$(date -r /var/cache/apt/archives/)"
@ -555,6 +571,7 @@ fi_sources(){ # 30/08/2017
printf "."
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 '^$')"
[ "$upgradable" ] && nbUpgradable="$(wc -l <<< "$upgradable")"
printf "."
dpkgArch="$(dpkg --print-architecture)"
paquetBiz="$(dpkg -l | grep -v '^i' | grep "$dpkgArch" | awk '{print $1, $2, $3}')"
@ -579,7 +596,8 @@ fi_sources(){ # 30/08/2017
text+='```\n\n'
fi
if [ "$upgradable" ]; then
text+="**des paquets devraient être mis à jour.** "'`apt list --upgradable`'" \n"
text+="**$nbUpgradable paquets devraient être mis à jour:** \n"
text+="**apt list --upgradable** \n"
text+='```\n'
text+="$upgradable \n"
text+='```\n\n'
@ -623,12 +641,13 @@ fi_system_analyse(){ # 30/08/2017
echo -e "$text" >> "$fileOutput"
}
fi_systeme(){ # 30/08/2017
fi_systeme(){ # 22/09/2017
local mbr description uname bootImage xorg shells lastboot uptime text
[ -d /sys/firmware/efi ] && mbr="**EFI boot**" || mbr="**Legacy boot**"
[ -d /sys/firmware/efi ] && mbr="**EFI**" || mbr="**Legacy (mbr)**"
[ -x "/usr/bin/lsb_release" ] && description="$(lsb_release -ds)" #dépend de apt install lsb-release, sur debian, en standard, juste : lsb-base
uname="$(uname -rmo)"
bootImage="$(sed 's/root=[^ ]*//;s/[ ]\+/, /g' /proc/cmdline)"
initDaemon="$(ps -p1)" #? ps -ax | awk '$1==1' ou ps -p1 | awk '$1==1'
xorg="$XDG_SESSION_TYPE"
if [ -z "$xorg" ]; then
[ "$(ps -ef | grep -c 'wayland')" -gt 1 ] && xorg="wayland" || xorg="indéterminé"
@ -639,16 +658,25 @@ fi_systeme(){ # 30/08/2017
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)"
###
text="## système \n\n"
figet_cpu; text+="CPU: **$cpu** \n"
figet_gpu; text+="GPU: **$gpu** \n"
text+="type de boot: $mbr \n"
figet_distro; text+="distribution: **$distro** \n\n"
text+="| | | \n"
text+=" --- | --- \n"
figet_cpu; text+="CPU | **$cpu** \n"
figet_gpu; text+="GPU | **$gpu** \n"
text+="boot | $mbr \n"
figet_distro; text+="distribution | **$distro** \n\n"
f__architecture || f__info "Architecture non supportée" "vous pouvez contacter contacter $projet $contact si vous voulez aider à parfaire le script"
text+='```\n'
text+="architecture: $architecture \n"
[ "$description" ] && text+="description: $description \n"
text+="uname: $uname \n"
text+="$bootImage \n"
if grep -qi systemd <<< "$initDaemon"; then
text+="démon d'initialisation: systemd \n"
else
text+="démon d'initialisation: **non systemd** \n"
# ps ax | awk '$1=="1"{print $5}') affiche le 1er process daemon init, normalement /sbin/init
text+="$(sed -En 's/^.* (\/.*$)/\1/p' <<< $(ls -l $(ps ax | awk '$1=="1"{print $5}'))) \n"
fi
figet_resolution; text+="résolution: $resolution \n"
text+="serveur d'affichage: $xorg \n"
figet_de; text+="desktop (DE): $de \n"
@ -812,7 +840,7 @@ figet_gpu() { # thanks neofetch, assigne $gpu
# assigne $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type
# $ifnames, $ifnames_type, $mac_address, mac_address_type
figet_ip() { # v04/09/2017
figet_ip() { # 04/09/2017
[ -z "$(which ip)" ] && return 1
ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print " ",$4,"(",$2,")"}')"
ip_local_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)"
@ -830,7 +858,7 @@ figet_ip() { # v04/09/2017
}
# $1=4|6, assigne $ip_public
figet_ip_public(){ # v03/09/2017
figet_ip_public(){ # 03/09/2017
list_ip4(){
ip_test+=" http://whatismyip.akamai.com"
@ -1001,13 +1029,13 @@ fipaste(){
# à tester fipaste_curl_markdownshare "$fileOutput"
}
fipaste_curl_pastery(){ # $1 fichier à exporter, $2 durée de conservation en jour; $3 debug # 30/08/2017
fipaste_curl_pastery(){ # $1 fichier à exporter, $2 durée de conservation en jour; $3 debug # 22/09/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
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/"
f__info "\n\n votre paste:$GREEN https://www.pastery.net/$id/"
[ "$3" == "debug" ] && echo -e "\n$curl\n"
# ?api_key=<api_key>
@ -1028,7 +1056,7 @@ fipaste_curl_markdownshare(){
}
# inscription dans tache upgrade en anacron hebdomadaire, via cron horaire, $1=upgrade|install|remove
fscript_cronAnacron(){ # v06/09/2017
fscript_cronAnacron(){ # 06/09/2017
local dirAnacron dirSpool fileAnacron
[ "$(type -t fscript_cronAnacron_special)" ] && fscript_cronAnacron_special # test, si fonction spécifique, appel
dirAnacron="/home/$user_/.config/anacron"
@ -1063,7 +1091,7 @@ fscript_cronAnacron(){ # v06/09/2017
}
# version script en ligne, assigne $versionScript, $script_aJour=ok|ko
fscript_get_version(){ # v07/09/2017
fscript_get_version(){ # 07/09/2017
f__info "raw" "$GREEN""version script en cours: $version"
versionScript="$(wget -q --tries=2 --timeout=15 -O - "$urlScript" | grep '^version=' | cut -d '=' -f 2)"
if [ "$versionScript" ]; then
@ -1078,7 +1106,7 @@ fscript_get_version(){ # v07/09/2017
}
# installation du script dans le système
fscript_install(){ # v06/09/2017
fscript_install(){ # 06/09/2017
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"
return
@ -1105,7 +1133,7 @@ fscript_install(){ # v06/09/2017
}
# suppression du script dans le système
fscript_remove(){ # v06/09/2017
fscript_remove(){ # 06/09/2017
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
@ -1127,7 +1155,7 @@ fscript_remove(){ # v06/09/2017
}
# mise à jour script si dispo
fscript_update(){ # v06/09/2017
fscript_update(){ # 06/09/2017
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"
return
@ -1176,24 +1204,24 @@ prg_1(){ # début
echo -e "Rapport au $dateRapport \n" >> "$fileOutput"
}
prg_2(){ # traitements principaux
printf "."
printf " ."
fi_systeme; printf "."
fi_cpu; printf "."
fi_gpu; printf "."
fi_localisation; printf "."
fi_sources "."
fi_sources; printf "."
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 "."
fi_dmesg; printf ".\n"
fi_dmesg; printf ".\n\n"
}
prg_3(){ # fin de traitements
echo -e "[rapport getInfo v$version]($urlNotice)\t$(date '+%a %d/%m/%Y %k:%M:%S')\n" >> "$fileOutput"
f__dialog_oui_non "non" "exporter sur un pastebin par défaut?" && fipaste
f__info "\n$GREEN le rapport est disponible en local, fichier: $fileOutput"
f__info "\n le rapport est disponible en local, fichier:$GREEN $fileOutput"
f__info "vous pouvez le visualiser avec $GREEN$script -l$COLOR"
}

View File

@ -1,6 +1,15 @@
# changelog getInfo
## 1.21.0 22/09/2017
* système, présentation en table pour meilleure présentation
* daemon d'initialisation (systemd ou autre)
* révision fi_gpu, réduction verbosité (1v au lieu de 3v)(pour éviter erreur en root avec capabilities)
et sélection par slot, présentation
* révision fi_reseau, homogénéité nnv au lieu de nnk et sélection par slot , présentation
* révision fi_sources, présentation et nombres de paquets upgradables
## 1.20.0 18/09/2017
* révision f__dialog_oui_non