This commit is contained in:
kyodev 2017-09-04 13:35:14 +02:00
parent 01d2834595
commit 30dcb7d414
2 changed files with 55 additions and 35 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
version=1.12.0
date="03/09/2017"
version=1.13.0
date="04/09/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
script="getInfo"
@ -186,17 +186,18 @@ f_help(){
printf "$BLUE"
cat << 'EOF'
----------------------------------------------------------------------
./getInfo : exécution normale
./getInfo : exécution normale, rapport markdown configuration & diagnostic
getInfo : exécution normale si script installé dans le système
options:
-d, --dmesg : dmesg erreur, warning, critique. root requis, rapport seul de dmesg
-d, --dmesg : dmesg erreur, warning, critique. root requis, rapport markdown seul de dmesg
-h, --help : affichage aide
--ip : affiche ip(s) publique(s) (ipv4 / ipv6), /!\ infos confidentielles, sans rapport
-l, --list : afficher le rapport existant
-p, --paste : exporte le rapport existant, durée du paste standard 7 jours
-s, --ssid : affiche configurations ssid /!\ infos confidentielles
pas de rapport, root et NetworkManager requis
-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
debug : le résultat json du paste sera affiché après export
-tn : durée du paste de n jour(s)
@ -444,7 +445,7 @@ fi_nm_wifis(){ # 30/08/2017
echo -e "$text" >> "$fileOutput"
}
fi_reseau(){ # 30/08/2017
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')"
@ -470,8 +471,8 @@ fi_reseau(){ # 30/08/2017
text+='```\n'
text+="$ip_local_type \n"
text+='```\n\n'
if grep -q 'wlx' <<< "$ifname"; then
text+="**Attention:** une interface wifi est en erreur: $(grep -o 'wlx' <<< $ifname) \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"
text+="au pire, changer le renommage: https://kyodev.frama.io/kyopages/trucs/interfaces-nommage-classique/ \n\n"
fi
@ -574,17 +575,17 @@ fi_sources(){ # 30/08/2017
echo -e "$text" >> "$fileOutput"
}
fi_ssid(){ # affiche configurations ssid # 30/08/2017
fi_ssid(){ # affiche configurations ssid # 04/09/2017
[ "$(which nmcli)" ] || f__error "il manque NetworkManager"
[ $EUID -eq 0 ] || f__error "il manque les droits root"
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éé"
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"
text+='```\n'
text+="$nm_ssid \n"
text+='```\n\n'
text+='```\n'
echo -e "$text"
}
@ -790,16 +791,23 @@ figet_gpu() { # thanks neofetch, assigne $gpu
[[ "$gpu" =~ "intel" ]] && gpu="Intel Integrated Graphics"
}
# $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type, $ifname, $ifname_type
figet_ip() { # v03/09/2017
# 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
[ -z "$(which ip)" ] && return 1
ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print " ",$4,"(",$2,")"}')"
ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print " ",$4,"(",$2,")"}')"
ip_local_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)"
gateway="$(LC_ALL=C ip -4 route | awk '/default via/ {print " ",$3,"(",$5,")"}'; LC_ALL=C ip -6 route | awk '/default via/ {print " ",$3,"(",$5,")"}')"
gateway="$(LC_ALL=C ip -4 route | awk '/default via/ {print " ",$3,"(",$5,")"}'; LC_ALL=C ip -6 route | awk '/default via/ {print " ",$3,"(",$5,")"}')"
gateway_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $gateway)"
gateway_one="$(head -n 1 <<< $gateway | awk '{print " ",$1}')"
ifname="$(ip -4 route | awk '/proto kernel/ {print " ",$3}')"
ifname_type="$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname)"
gateway_one="$(head -n 1 <<< $gateway | awk '{print " ",$1}')"
for ifn in $(ls /sys/class/net/) ; do
[ "$ifn" != "lo" ] && ifnames+=" $ifn"$'\n' # $'\n' -> newline ou $'\x0a' ou $'\012'
[ "$ifn" != "lo" ] && mac_address+=" $ifn: $(cat /sys/class/net/$ifn/address)"$'\n'
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)"
}
# $1=4|6, assigne $ip_public
@ -1124,8 +1132,8 @@ fscript_update(){ # v29/08/2017
}
# initialisation
PATH='/usr/sbin:/usr/bin:/sbin:/bin' ; IFS=' '; TERM=xterm
export PATH TERM
PATH='/usr/sbin:/usr/bin:/sbin:/bin'; TERM=xterm ; IFS=$' \t\n'
export PATH TERM IFS
fileOutput="getInfo_rapport.md"
fileLogs="/var/log/sdeb_$script.log"
fileDev="/opt/bin/fileDev"
@ -1166,7 +1174,7 @@ prg_2(){ # traitements principaux
}
prg_3(){ # fin de traitements
echo -e "[rapport getInfo v$version]($urlNotice)\n" >> "$fileOutput"
fi__dialog_oui_non "non" "exporter sur un pastebin par défaut?" || paste
fi__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 "vous pouvez le visualiser avec $GREEN$script -l$COLOR"
}
@ -1185,9 +1193,9 @@ for i in $options; do
done
[ "$pasteDuration" ] || pasteDuration=7 # durée de conservation standard du paste en jours
# purge option des options
options="$(sed -E 's/debug[ ]*//g; s/-t[0-9]+//g' <<< $options;)"
options="$(sed -E 's/debug[ ]*//g; s/-t[0-9]+//g' <<< $options | xargs)"
# traitement action
[ $# -eq 0 ] && options="info"
[ "$options" == "" ] && options="info"
for i in $options; do
case $i in
info )
@ -1199,6 +1207,12 @@ for i in $options; do
fi_dmesg "dmesg"
prg_3
exit ;; # rapport dmesg only, root requis
-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
--ip )
if figet_ip_public "4" ; then
f__info "raw" " ipv4 publique: $GREEN$ip_public"
@ -1211,12 +1225,10 @@ for i in $options; do
f__info "$BLUE pas de connectivité ipv6"
fi
exit ;; # affiche ip public
-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
-m | --mac )
figet_ip
f__info "mac_address:\n$GREEN$mac_address_type$COLOR"
exit ;; # affiche adresses mac
-s | --ssid )
fi_ssid
exit ;; # affiche configurations ssid, root requis

View File

@ -2,7 +2,15 @@
## todo
* adresses MAC?
## 1.13.0 04/09/2017
* nouveau IFS
* révision figet_ip:
* ifnames, toutes les interfaces et pas seulement les connectées
* mac address des interfaces
* révision affichage fi_ssid
* fix bug: export direct après génération rapport
* nouveau: option affichage adresses mac
## 1.12.0 03/09/2017