diff --git a/scripts/diag_ip_public b/scripts/diag_ip_public new file mode 100755 index 0000000..88d25bb --- /dev/null +++ b/scripts/diag_ip_public @@ -0,0 +1,116 @@ +#!/bin/bash + +get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public + + 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 + # ip_test+=" https://4.ifcfg.me" #down avec wget! + } + 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" + # ip_test+=" http://smart-ip.net/myip" #down avec wget?! + # ip_test+=" https://6.ifcfg.me" #down avec wget?! + } + 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 + local dig_test + local ip_test + if [ "$1" == "IPv4" ]; then + list_ip4_dig + list_ip4 + ip_telnet=4.ifcfg.me + elif [ "$1" == "IPv6" ]; then + list_ip6_dig + list_ip6 + ip_telnet=6.ifcfg.me + else return 1; fi + + if which dig &>/dev/null && [ -z "$ip_public" ]; then + for ii in $dig_test ; do + ip_public=$(dig +short $(sed 's;/; ;g' <<< $ii)) +# [ "$ip_public" ] && break + echo $(sed 's;/; ;g' <<< $ii) $ip_public # test + done + fi +echo "ip dig $ip_public" +unset ip_public # test + + if which wget &>/dev/null && [ -z "$ip_public" ]; then + cmd="wget --quiet --tries=1 --timeout=5 -O - " + for ii in $ip_test ; do + ip_public=$($cmd $ii) +# [ "$ip_public" ] && break + echo -e "wget-$ii:\t $ip_public" # test + done + fi +echo "ip wget $ip_public" +unset ip_public # test + + if which curl &>/dev/null && [ -z "$ip_public" ]; then + cmd="curl --silent --location --retry 0 --max-time 5" #--location pour aider redirections + for ii in $ip_test ; do + ip_public=$($cmd $ii) +# [ "$ip_public" ] && break + echo -e "curl-$ii:\t $ip_public" # test + done + fi +echo "ip curl $ip_public" +unset ip_public # test + + if which telnet &>/dev/null && [ -z "$ip_public" ]; then + ip_public=$(telnet $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4) + fi +echo "ip telnet $ip_public" +[ "$1" == "IPv6" ] && ip_temp=$ip_public +unset ip_public # test + + if which nc &>/dev/null && [ -z "$ip_public" ] && [ "$1" != "IPv6" ]; then + ip_public=$(nc $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4) +echo "ip nc $ip_public" + fi + +[ "$1" == "IPv6" ] && ip_public=$ip_temp + + if [ -z "$ip_public" ]; then + echo -e "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" + fi +} + +get_ip_public "IPv4" +echo "ip4: $ip_public" + +get_ip_public "IPv6" +echo "ip6: $ip_public" diff --git a/scripts/getInfo b/scripts/getInfo index 04b3a03..33255cb 100755 --- a/scripts/getInfo +++ b/scripts/getInfo @@ -1,6 +1,6 @@ #!/bin/bash -version=0.6.4 +version=0.8.0 date="08/2017" projet="simpledeb" contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues" @@ -247,7 +247,6 @@ fi__dialog_oui_non () { get_battery() { # thanks neofetch, assigne $battery - # We use 'prin' here and exit the function early so that we can do multi battery support with a single battery per line. for bat in "/sys/class/power_supply/BAT"*; do local capacity="$(< "${bat}/capacity")" local status="$(< "${bat}/status")" @@ -259,7 +258,7 @@ get_battery() { # thanks neofetch, assigne $battery [[ "$battery_state" ]] && battery+=" En charge" } -get_cpu() { # thanks neofetch, assigne $cpu +get_cpu() { # thanks neofetch, assigne $cpu cpu="$(awk -F ': | @' '/model name|Processor/ {printf $2; exit}' /proc/cpuinfo)" local speed_dir="/sys/devices/system/cpu/cpu0/cpufreq" local temp_dir="/sys/class/hwmon/hwmon0/temp1_input" @@ -303,16 +302,7 @@ get_cpu() { # thanks neofetch, assigne $cpu cpu="${cpu/@/(${cores})(${coresT}) @}" } -get_cpu2(){ - local cpu_bogomips=$(sed -n 's/^bogomips.*: \(.*\)$/\1/p' /proc/cpuinfo | head -n 1) - local cpu_addr=$(sed -n 's/^address sizes.*: \(.*\)$/\1/p' /proc/cpuinfo | head -n 1) - local cpu_flags=$(sed -n 's/^flags.*: \(.*\)$/\1/p;' /proc/cpuinfo | head -n 1) - cpu2+="bogomips: $cpu_bogomips \n" - cpu2+="$cpu_addr \n" - cpu2+="flags cpu: \n$cpu_flags " -} - -get_de() { # thanks neofetch, assigne $de +get_de() { # thanks neofetch, assigne $de de="${XDG_CURRENT_DESKTOP/i3}" de="${de/'X-'}" de="${de/Budgie:GNOME/Budgie}" @@ -361,14 +351,8 @@ get_distro() { # thanks neofetch, assigne $distro [[ -z "$distro" ]] && distro="$os (Unknown)" } -get_dmesg(){ -# ! root -dmesg -l err -dmesg -l warn -} - -get_gpu() { # thanks neofetch, assigne $gpu - gpu="$(PATH="/sbin:$PATH" lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}')" +get_gpu() { # thanks neofetch, assigne $gpu + gpu="$(lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}')" case "$gpu" in *"advanced"*) gpu="${gpu//Intel*$'\n'}" @@ -390,8 +374,103 @@ get_gpu() { # thanks neofetch, assigne $gpu [[ "$gpu" =~ "intel" ]] && gpu="Intel Integrated Graphics" } -get_local_ip() { # thanks neofetch, assigne $local_ip - local_ip="$(ip route get 1 | awk '{print $NF;exit}')" +get_ip() { # assigne $ip_local + ip_local=$(ip route get 1 | awk '/via/ {print $5, ":",$3}') + gateway=$(ip route | awk '/via/ {print "passerelle:", $3, "pour:", $5}') +} + +get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public + + 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 + # ip_test+=" https://4.ifcfg.me" #down avec wget! + } + 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" + # ip_test+=" http://smart-ip.net/myip" #down avec wget?! + # ip_test+=" https://6.ifcfg.me" #down avec wget?! + } + 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 + local dig_test + local ip_test + if [ "$1" == "IPv4" ]; then + list_ip4_dig + list_ip4 + ip_telnet=4.ifcfg.me + elif [ "$1" == "IPv6" ]; then + list_ip6_dig + list_ip6 + ip_telnet=6.ifcfg.me + else return 1; fi + + if which dig &>/dev/null && [ -z "$ip_public" ]; then + for ii in $dig_test ; do + ip_public=$(dig +short $(sed 's;/; ;g' <<< $ii)) + [ "$ip_public" ] && break + done + fi + + if which wget &>/dev/null && [ -z "$ip_public" ]; then + cmd="wget --quiet --tries=1 --timeout=5 -O - " + for ii in $ip_test ; do + ip_public=$($cmd $ii) + [ "$ip_public" ] && break + done + fi + + if which curl &>/dev/null && [ -z "$ip_public" ]; then + cmd="curl --silent --location --retry 0 --max-time 5" #--location pour aider redirections + for ii in $ip_test ; do + ip_public=$($cmd $ii) + [ "$ip_public" ] && break + done + fi + + if which telnet &>/dev/null && [ -z "$ip_public" ]; then + ip_public=$(telnet $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4) + fi + + if which nc &>/dev/null && [ -z "$ip_public" ] && [ "$1" != "IPv6" ]; then + ip_public=$(nc $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4) + fi + + 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" + fi } get_memory() { # thanks neofetch, assigne $memory @@ -409,33 +488,20 @@ get_memory() { # thanks neofetch, assigne $memory memory="${mem_used}Mo / ${mem_total}Mo" } -get_modules(){ # thanks wireless-info, $1 net|all - [ "$1" == "net" ] && local text="\n## modules réseau\n\nliste non garantie complète \n" || \ - local text="\n\n## tous les modules\n\n**lsmod** \n" +get_modules(){ # thanks wireless-info for 'net', $1 net|video, assigne $exportText if [ "$1" == "net" ]; then local MODMATCHES="(air|ar5|at7|ath[^3]?|b43|bcma|brcm|carl|ipw|iwl|ndis|r(818|8192[eu]|871|92su)|8(188|189|192|723|812)[acde][esu]|rt[23567]|rtl|ssb|wl|(cfg|mac)80211)" local LSMODMATCHES="(wmi|(dell|ideapad)[-_]laptop)" local modules=$(lsmod | grep -E "(^|[[:punct:] ])($MODMATCHES|$LSMODMATCHES)[^[:punct:] ]*([[:punct:] ]|$)") - else local modules=$(lsmod); fi - text+='```\n' - text+="$modules \n" - text+='```\n' - echo -e "$text" >> "$fileOutput" -# grep -v '^#' /etc/modules -} - -get_nm_wifis(){ # à exploiter? - if [ -x /usr/bin/nmcli ]; then - echo nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY,ACTIVE,IN-USE device wifi list - else echo "NetworkManager n'est pas installé? (paquet network-manager)"; fi -} - -get_nm(){ # à exploiter? -# etat NM cat -s /var/lib/NetworkManager/NetworkManager.state -# conf NM grep -v '^#' /etc/NetworkManager/NetworkManager.conf -# root cat /etc/NetworkManager/system-connections/ssid -# liste canaux wifi [ -x /sbin/iwlist ] && /sbin/iwlist chan 2>&1| grep -v 'no frequency information' || echo "paquet wireless-tools à installer" -echo + exportText="\n### modules réseau\n\nliste non garantie complète \n" + elif [ "$1" == "video" ]; then + local modules=$(lsmod | grep -i -E 'amdgpu|ati|i915|nouveau|nvidia|radeon|video|gma') + exportText="\n### modules video\n\nliste non garantie complète \n" + fi + exportText+='```\n' + exportText+="$modules \n" + exportText+='```\n' +# grep -vE '#|^$' /etc/modules } get_resolution() { # thanks neofetch, assigne $resolution @@ -467,7 +533,7 @@ get_shell(){ # thanks neofetch, assigne $shell esac } -get_wm() { # thanks neofetch, assigne $wm +get_wm() { # thanks neofetch, assigne $wm 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)" @@ -479,8 +545,8 @@ get_wm() { # thanks neofetch, assigne $wm fi } - # $1 fichier à exporter, $2 durée de conservation en jour; $3 debug -fi_curl_pastery(){ + +paste_curl_pastery(){ # $1 fichier à exporter, $2 durée de conservation en jour; $3 debug [ -e "$1" ] || f__error "fichier $1 inexistant" # curl -X POST "https://www.pastery.net/api/paste/?title=getInfo&language=markdown" -F file=@$1 local curl=$(curl --silent -X POST "https://www.pastery.net/api/paste/?title=getInfo_$version&language=markdown&duration=$(($2*1440))" --data-binary @$1) @@ -495,7 +561,7 @@ fi_curl_pastery(){ # 100ko max } -fi_curl_markdownshare(){ +paste_curl_markdownshare(){ [ -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 @@ -505,6 +571,146 @@ fi_curl_markdownshare(){ #-d expire ? ou --data expire } + +fi_cnx(){ + if ! fi_nm_wifis cnx ; then + f__error "Il manque NetworkManager ou les droits root" + fi + local text="## wifi connecté \n\n" + f__info="$RED""Attention, la clé du réseau wifi est visible!" + text+='```\n' + text+="$nm_connect \n" + text+='```\n' + echo -e "$text" +} + +fi_cpu(){ + local cpu_addr=$(sed -n 's/^address sizes.*: \(.*\)$/\1/p' /proc/cpuinfo | head -n 1) + local cpu_bogomips=$(sed -n 's/^bogomips.*: \(.*\)$/\1/p' /proc/cpuinfo | head -n 1) + local cpu_flags=$(sed -n 's/^flags.*: \(.*\)$/\1/p;' /proc/cpuinfo | head -n 1) + + local memsys=$(free -ht) + + local text="## processeur / mémoire \n\n" + text+='```\n' + get_cpu; text+="CPU: $cpu \n" + text+="adressage: $cpu_addr \n" + text+="bogomips: $cpu_bogomips \n" + get_memory; text+="\nmémoire Ram utilisée/totale: $memory \n\n" + text+="mémoire système: $memsys \n" + text+='```\n' + text+="flags cpu: \n" + text+='```\n' + text+="$cpu_flags \n" + text+='```\n' + echo -e "$text" >> "$fileOutput" +} + +fi_dmesg(){ # root only, si $1=dmesg rapport dmesg only + local text="## dmesg (erreur, warning ou critique) \n\n" + if [ "$EUID" -ne 0 ]; then + if [ "$1" == "dmesg" ]; then + f__info "$RED""dmesg ne peut être affiché qu'avec les droits root" + return 1 + fi + text+="ne peut être affiché qu'avec les droits root" + echo -e "$text" >> "$fileOutput" + return 0 + fi + + local dmesg_err=$(dmesg -l err) + local dmesg_warn=$(dmesg -l warn) + local dmesg_crit=$(dmesg -l crit) + if [ "$dmesg_warn" ]; then + text+="**dmesg -l err** (erreur) \n" + text+='```\n' + text+="$dmesg_err \n" + text+='```\n' + fi + if [ "$dmesg_warn" ]; then + text+="**dmesg -l warn** (warning) \n" + text+='```\n' + text+="$dmesg_warn \n" + text+='```\n' + fi + if [ "$dmesg_crit" ]; then + text+="**dmesg -l crit** (critique) \n" + text+='```\n' + text+="$dmesg_crit \n" + text+='```\n' + fi + if [ -z "$dmesg_crit" ] && [ -z "$dmesg_warn" ] && [ -z "$dmesg_warn" ]; then + text+="**pas de messages** \n" + fi + echo -e "$text" >> "$fileOutput" + if [ "$1" == "dmesg" ]; then cat -n "$fileOutput"; fi +} + +fi_disk(){ + local fstab=$(grep -vE '#|^$' /etc/fstab) + local disk_lsblk=$(lsblk -fi -o +SIZE -o +OWNER) + local utilDisk=$(df -h --output=source,target,fstype,size,used,avail,pcent --exclude=tmpfs --exclude=devtmpfs --exclude=devtmpfs | grep -Ev "devpts|none|proc|sys|tmpfs|udev") + local resume=$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume) + local idSwap=$(grep -vE '#|^$' /etc/fstab | grep -E 'swap' | grep 'UUID' | sed -E 's/^UUID=([0-9a-Z-]*).*/\1/') + local idResume=$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume | grep 'RESUME=' | grep 'UUID' | sed -E 's/^UUID=([0-9a-Z-]*).*/\1/') + local diskAta=$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^ata/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/') + local diskUsb=$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^usb/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/') + local diskMmc=$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^mmc/!d; /part/d; /\/mmcblk/!d; s/^.*\(mmcblk..*\)$/\1/') + local diskNvme=$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^nvme/!d; /part/d; /\/nvme/!d; s/^.*\(nvme...*\)$/\1/') + + local text="## disque(s) \n\n" + get_disk; text+="disque(s): $disk \n\n" + + text+="**grep -vE '#|^$' /etc/fstab** (fstab) \n" + text+='```\n' + text+="$fstab \n" + text+='```\n' + text+="**lsblk -fi -o +SIZE -o +OWNER** (disques) \n" + text+='```\n' + text+="$disk_lsblk \n" + text+='```\n' + text+="**df -h ...** (utilisation disques) \n" + text+='```\n' + text+="$utilDisk \n" + text+='```\n' + text+="**grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume** (resume) \n" + text+='```\n' + text+="$resume \n" + text+='```\n' + [ "$idSwap" ] && [ "$idResume" ] && [ "$idSwap"!="$idResume" ] && text+="_vérifier la config resume_, l'UUID ne semble pas correspondre à celui du swap. en cas de multi-boot, vous pouvez utiliser _RESUME=auto_ ou _RESUME=/dev/sdx_ \n" + text+="\n**types de disque** \n\n" + [ "$diskAta" ] || diskAta="-"; text+="* ata: $diskAta \n" + [ "$diskUsb" ] || diskUsb="-"; text+="* usb: $diskUsb \n" + [ "$diskMmc" ] || diskMmc="-"; text+="* mmc: $diskMmc \n" + [ "$diskNvme" ] || diskNvme="-"; text+="* nvme: $diskNvme \n" + echo -e "$text" >> "$fileOutput" +} + +fi_gpu(){ +# local graphCards=$(lspci -nnk | grep -iEA 3 'vga|display|3d') + local graphCards=$(lspci -nnvvv | grep -iEA 13 '^[0-9]+.*vga|display|3d') + local extraitXorg=$(cat /var/log/Xorg.0.log | grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)') + local resolutions=$(xrandr --query | grep '^ *[0-9]' | head -n 10) + + local text="## graphisme \n\n" + get_gpu; text+="**GPU: $gpu** \n" + get_resolution; text+="**résolution: $resolution** \n\n" + text+="\n**lspci -nnk | grep -iEA 3 'vga|display|3d'** (matériel) \n" + text+='```\n' + text+="$graphCards \n" + text+='```\n' + text+="**xrandr --query | grep '^ *[0-9]' | head -n 10** (10 premières résolutions possibles) \n" + text+='```\n' + text+="$resolutions \n" + text+='```\n' + text+="**cat /var/log/Xorg.0.log | grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)'** (extrait xorg.log) \n" + text+='```\n' + text+="$extraitXorg \n" + text+='```\n' + get_modules video; text+="$exportText" + echo -e "$text" >> "$fileOutput" +} + fi_help(){ printf $BLUE cat << 'EOF' @@ -517,11 +723,13 @@ cat << 'EOF' --help, -h : affichage aide --list, -l : afficher le rapport existant --paste, -p : exporte le rapport existant - + --dmesg : dmesg erreur, warning, critique. root requis, rapport seul de dmesg --install, -i : installation du script dans le système --remove, -r : suppression du script dans le système --upgrade, -u : upgrade script si maj possible --version, -v : version du script, en ligne et en cours d'exécution + --cnx, -c : affiche la connexion wifi en cours, root requis, /!\ infos confidentielles, sans rapport + --ip : affiche ip public, /!\ infos confidentielles, sans rapport exemple ./getInfo construit un rapport et propose un export final @@ -531,37 +739,100 @@ EOF printf "$COLOR\n" } -fi_paste(){ - fi_curl_pastery "$fileOutput" "$dureePaste" "$option" - # à tester fi_curl_markdownshare "$fileOutput" +fi_localisation(){ + local locale=$(grep -vE '#|^$' /etc/default/locale) + local keymap=$(setxkbmap -query) + local keyboard=$(grep -vE '#|^$' /etc/default/keyboard) + + local text="## localisation \n\n" + text+="**grep -vE '#|^$' /etc/default/locale** \n" + text+='```\n' + text+="$locale \n" + text+='```\n' + text+="**setxkbmap -query** \n" + text+='```\n' + text+="$keymap \n" + text+='```\n' + text+="**grep -vE '#|^$' /etc/default/keyboard** \n" + text+='```\n' + text+="$keyboard \n" + text+='```\n' + echo -e "$text" >> "$fileOutput" +} + +fi_nm(){ + [ -x $(which nmcli) ] || return 0 # root sur autre que debian? + local nm_etat=$(grep -vE '#|^$' /var/lib/NetworkManager/NetworkManager.state) + local nm_conf=$(grep -vE '#|^$' /etc/NetworkManager/NetworkManager.conf) + + local text="## Network Manager \n\n" + text+="**grep -vE '#|^$' /var/lib/NetworkManager/NetworkManager.state** \n" + text+='```\n' + text+="$nm_etat \n" + text+='```\n' + text+="**grep -vE '#|^$' /etc/NetworkManager/NetworkManager.conf** \n" + text+='```\n' + text+="$nm_conf \n" + text+='```\n' + echo -e "$text" >> "$fileOutput" +} + +fi_nm_wifis(){ # si $1=cnx retourne connexions wifi et assigne $connections_wifi, $nm_connect + [ -x $(which nmcli) ] || return 0 + local nm_wifis=$(nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY device wifi list) + connections_wifi=$(LC_ALL=C nmcli -f SSID,ACTIVE,IN-USE device wifi list | grep -E 'yes[[:space:]]+\*' | awk '{print $1}') + + if [ "$1" == "cnx" ] && [ $EUID -eq 0 ]; then # root only + connections_wifi=$(LC_ALL=C nmcli -f SSID,ACTIVE,IN-USE device wifi list | grep -E 'yes[[:space:]]+\*' | awk '{print $1}') + nm_connect=$(grep -vE '#|^$' /etc/NetworkManager/system-connections/"$connections_wifi") + return 0 + else return 1; fi + + local text="## wifis à proximité \n\n" + text+="**nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY,ACTIVE,IN-USE device wifi list** \n" + text+='```\n' + text+="$nm_wifis \n" + text+='```\n' + echo -e "$text" >> "$fileOutput" } fi_reseau(){ local netcards=$(lspci -nnk | grep -iEA 3 'network|ethernet') - local ifconfig=$(ip address show) +# local netcards=$(lspci -nnvvv | grep -iEA 12 'network|ethernet') + local ip_a=$(ip address show) local iwconfig=$(iwconfig 2>&1 | grep -v 'no wireless extensions' | grep -v '^$') local interfaces=$(sed '/^#/d;s/^wpa-psk [[:graph:]]\+/wpa-psk /;/^$/d;s/\(.*\)/\1 /' /etc/network/interfaces) local route=$(ip route show) - local resolv=$(grep -v '^#' /etc/resolv.conf) + local resolv=$(grep -vE '#|^$' /etc/resolv.conf) NETMGRPATHS=("/usr/sbin/NetworkManager" "/usr/sbin/wicd" "/usr/sbin/connmand") # thanks wireless-info NETMGRNAMES=("NetworkManager" "Wicd" "ConnMan") # thanks wireless-info for ii in "${!NETMGRPATHS[@]}"; do if [ -f "${NETMGRPATHS[$ii]}" ]; then NETMGRINST+="${NETMGRNAMES[$ii]}"; fi if [ "$(ps -ef | grep -c ${NETMGRPATHS[$ii]})" -ge 2 ]; then netmgrrun+=$(ps -ef | grep -o "${NETMGRPATHS[$ii]}.*$" | head -n 1); fi done - local text="\n## réseau\n\n" + local text="## réseau \n\n" + if which iwlist &>/dev/null; then # liste canaux wifi paquet wireless-tools requis + local liste_canaux_wifi=$(iwlist chan 2>&1 | grep -vE 'no frequency information|^$') + echo TEST + fi + + get_ip; text+="**IP locale $ip_local** \n\n" + text+="l'IP publique n'apparaît pas pour ne pas être publiée, mais elle peut être connue avec: \n" + text+=" ./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' text+="**ip address show** \n" text+='```\n' - text+="$ifconfig \n" - text+='```\n' - text+="**iwconfig** \n" - text+='```\n' - text+="$iwconfig \n" + text+="$ip_a \n" text+='```\n' + if [ "$iwconfig" ]; then + text+="**iwconfig** \n" + text+='```\n' + text+="$iwconfig \n" + text+='```\n' + fi text+="**/etc/network/interfaces** \n" text+='```\n' text+="$interfaces \n" @@ -574,55 +845,91 @@ fi_reseau(){ text+='```\n' text+="$resolv \n" text+='```\n' - text+="**network managers** \n" - [ "$NETMGRINST" ] && text+="**installé(s):** $NETMGRINST \n" || text+="non trouvé parmi: ${NETMGRNAMES[@]} \n" - text+="**en fonctionnement:** " - [ "$netmgrrun" ] && text+="$netmgrrun" || text+="non trouvé\n" + if [ "$NETMGRINST" ]; then + text+="### network managers \n\n" + [ "$NETMGRINST" ] && text+="**installé(s):** $NETMGRINST \n" || text+="non trouvé parmi: ${NETMGRNAMES[@]} \n" + text+="**en fonctionnement:** " + [ "$netmgrrun" ] && text+="$netmgrrun \n" || text+="non trouvé \n" + get_modules net; text+="$exportText" + fi + if [ "$liste_canaux_wifi" ]; then + text+="**iwlist chan** \n" + text+='```\n' + text+="$liste_canaux_wifi \n" + text+='```\n' + fi + echo -e "$text" >> "$fileOutput" +} + +fi_sources(){ + which apt &>/dev/null || return 0 # retour si pas d'apt ? et aptitude...???? + local sources=$(grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null | sed 's/ / /g; s/:/: /') + local dateMaj=$(date -r /var/cache/apt/archives/) + local apt=$(LC_ALL=C apt-get autoremove --simulate) + local autoremove=$(grep -c 'Remv' <<< $apt) + local paquetToRemove=$(grep 'Remv' <<< $apt | sed 's/Remv //; s/\[[0-9.-]*\]//' | tr '\n' ' ') + local dpkgArch=$(dpkg --print-architecture) + local paquetBiz=$(dpkg -l | grep -v '^i' | grep "$dpkgArch" | awk '{print $1, $2, $3}') + + local text+="## sources list \n\n" + text+='```\n' + text+="$sources \n" + text+='```\n' + text+="dernière mise à jour **apt**: $dateMaj \n\n" + if [ $autoremove -ne 0 ] ; then + text+="**$autoremove paquet(s) installé(s) inutile(s)**, vous pouvez utiliser: apt autoremove. paquet(s) concerné(s): \n" + text+='```\n' + text+="$paquetToRemove \n" + text+='```\n' + fi + if [ "$paquetBiz" ]; then + text+="il y a des **paquet(s) dans un état non installé**. ce n'est pas forcément grave, mais ça peut être examiné. paquet(s) concerné(s): \n" + text+='```\n' + text+="$paquetBiz \n" + text+='```\n' + fi echo -e "$text" >> "$fileOutput" } fi_systeme(){ - local bootImage=$(sed 's/root=[^ ]*//;s/[ ]\+/, /g' /proc/cmdline) - [ -x "/usr/bin/lsb_release" ] && local description=$(lsb_release -ds) + [ -d /sys/firmware/efi ] && local mbr="**EFI boot**" || local mbr="Legacy boot" + [ -x "/usr/bin/lsb_release" ] && local description=$(lsb_release -ds) #dépend de apt install lsb-release, sur debian, en standard, juste : lsb-base local uname=$(uname -rmo) - [ -d /sys/firmware/efi ] && local mbr="EFI boot" || local mbr="Legacy boot" - #dépend de apt install lsb-release, debian standard juste : lsb-base + local bootImage=$(sed 's/root=[^ ]*//;s/[ ]\+/, /g' /proc/cmdline) local shells=$(grep -v "^#" /etc/shells | sed 's/\/bin\///' | tr '\n' ' ') local lastboot=$(last -R -n 1 --time-format iso reboot | head -n 1 | grep -o '[0-9:T+-]*' | sed 's/T/ /') local uptime=$(uptime -p) - uptime=$(sed 's/days/jours/; s/day/jour/; s/hour[s]*/h/; s/minute[s]*/mn/' <<< $uptime) + uptime=$(sed 's/up/depuis/; s/days/jours/; s/day/jour/; s/hour[s]*/h/; s/minute[s]*/mn/' <<< $uptime) - local text="\n## système\n\n" - get_distro; text+="$distro \n" - f__architecture || f__error "Architecture non supportée" "vous pouvez contacter contacter $projet $contact si vous voulez aider à parfaire le script" + local text="## système \n\n" + get_cpu; text+="**CPU: $cpu** \n" + get_gpu; text+="**GPU: $gpu** \n" + text+="**type de boot: $mbr** \n" + get_distro; text+="**$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" - text+="$bootImage \n" [ $description ] && text+="description: $description \n" text+="uname: $uname \n" - text+="type de boot: $mbr \n" - get_de; text+="desktop: $de \n" - get_wm; text+="wm: $wm \n" - get_shell; text+="shell: $shell \n" - text+="shells possibles: $shells \n" - get_cpu; text+="CPU: $cpu \n" - get_cpu2; text+="$cpu2 \n" - get_gpu; text+="GPU: $gpu \n" - get_memory; text+="mémoire utilisée/totale: $memory \n" + text+="$bootImage \n" get_resolution; text+="résolution: $resolution \n" - get_disk; text+="Disque(s): $disk \n" - get_battery; text+="Batteries(s): $battery \n" - get_local_ip; text+="IP locale: $local_ip \n" + get_de; text+="desktop (DE): $de \n" + get_wm; text+="window manager: $wm \n" + get_shell; text+="shell actif: $shell \n" + text+="shells installés: $shells \n" + get_disk; text+="disque(s): $disk \n" + get_battery; text+="batteries(s): $battery \n" text+="dernier boot: $lastboot, uptime: $uptime \n" text+='```\n' echo -e "$text" >> "$fileOutput" } -fi_system_analyse(){ # Analyze system boot-up performance +fi_system_analyse(){ local bootTime=$(systemd-analyze time) local bootBlame=$(systemd-analyze blame | head -n 20) - local text="\n## analyse boot\n\n" + local text="## analyse boot \n\n" text+="$(sed 's/Startup finished in /durée de boot: /; s/userspace/espace utilisateur/' <<< $bootTime) \n\n" text+="**systemd-analyze blame | head -n 20** \n" text+='```\n' @@ -631,37 +938,68 @@ fi_system_analyse(){ # Analyze system boot-up performance echo -e "$text" >> "$fileOutput" } +fi_usb(){ + local lsusb=$(lsusb) + local lsusb_t=$(lsusb -t) + + local text="## périphériques USB \n\n" + text+="**lsusb** \n" + text+='```\n' + text+="$lsusb \n" + text+='```\n' + text+="**lsusb -t** \n" + text+='```\n' + text+="$lsusb_t \n" + text+='```\n' + echo -e "$text" >> "$fileOutput" +} + + +fi_paste(){ + paste_curl_pastery "$fileOutput" "$dureePaste" "$option" + # à tester paste_curl_markdownshare "$fileOutput" +} + # initialisation f__affichage fileOutput="getInfo_rapport.md" +rm "$fileOutput" &>/dev/null fileLogs="/var/log/sdeb_$script.log" -dureePaste=1 +dureePaste=1 # en jour -fi_main1(){ # début - f__requis "curl" +prg_1(){ # début + f__requis "curl gawk" fi__context f__user } -fi_main2(){ # traitements principaux +prg_2(){ # traitements principaux os=$(uname -s) hote=$(uname -n) dateRapport=$(date +"%d %b %Y %H:%M %z") echo -e "# getInfo $version sur $hote / $os \n" > "$fileOutput" - echo -e "Rapport au $dateRapport" >> "$fileOutput" + echo -e "Rapport au $dateRapport \n" >> "$fileOutput" fi_systeme + fi_cpu + fi_gpu + fi_disk fi_reseau - get_modules "net" + fi_nm + fi_nm_wifis + fi_usb + fi_localisation fi_system_analyse + fi_sources + fi_dmesg } -fi_main3(){ # fin de traitements +prg_3(){ # fin de traitements cat $fileOutput if ! fi__dialog_oui_non "non" "exporter sur un pastebin par défaut?" ; then fi_paste fi - f__info "$GREEN le rapport est disponible en local, fichier: $fileOutput" + f__info "\n$GREEN le rapport est disponible en local, fichier: $fileOutput" } for i in $@; do @@ -670,39 +1008,37 @@ for i in $@; do option="debug" ;; # affichage résultat complet de l'export paste esac done + for (( i=0 ; i<=$# ; i++ )); do case ${!i} in - --paste | -p ) fi_paste ;; # exporte le rapport existant - --list | -l ) cat $fileOutput ;; # afficher le rapport existant - --install | -i ) fscript_install ;; # installation du script dans le système - --remove | -r ) fscript_remove ;; # suppression du script dans le système - --version | -v ) fscript_get_version ;; # version du script, en ligne et exécuté - --upgrade | -u ) + --paste | -p ) fi_paste ;; # exporte le rapport existant + --list | -l ) cat $fileOutput ;; # afficher le rapport existant + --install | -i ) fscript_install ;; # installation du script dans le système + --remove | -r ) fscript_remove ;; # suppression du script dans le système + --version | -v ) fscript_get_version ;;# version du script, en ligne et exécuté + --upgrade | -u ) f__log="tests mise à jour" fscript_get_version fscript_dl ;; # upgrade script si maj possible + --cnx | -c ) fi_cnx ;; # affiche connexion wifi en cours + --dmesg ) fi_dmesg "dmesg" ;; # rapport dmesg only + --ip ) + get_ip_public "IPv4" + f__info "$GREEN""ip4: $ip_public" + get_ip_public "IPv6" + f__info "$BLUE""ip6: $ip_public" ;; # affiche ip public $0 ) if [ $# -eq 0 ];then - fi_main1 - fi_main2 - fi_main3 + prg_1 + prg_2 + prg_3 fi ;; # programme - --help | -h | * ) fi_help ;; # affichage help + --help | -h | * ) fi_help ;; # affichage help esac done printf $COLOR exit -{ "raw":"https://markdownshare.com/raw/b837c09d-d5ec-4d0b-afb8-a01efe31f350", - "delete":"https://markdownshare.com/delete/cb43e94336dd5cae2d5b2b8a077f700b", - "edit":"https://markdownshare.com/edit/cb43e94336dd5cae2d5b2b8a077f700b", - "link":"https://markdownshare.com/view/b837c09d-d5ec-4d0b-afb8-a01efe31f350", - "id":"b837c09d-d5ec-4d0b-afb8-a01efe31f350", - "auth":"cb43e94336dd5cae2d5b2b8a077f700b" -} - -{"id": "pngznq", "title": "getInfo_0.5.0", "url": "https://www.pastery.net/pngznq/", "language": "markdown", "duration": 1438} - bug markdownshare: '```' pas interprêté en
 
 
@@ -720,5 +1056,5 @@ http://ndossougbe.github.io/strapdown/
 https://www.pastery.net/api/
 	license non libre? pas de depot, mais ça marche
 
-wget https://framagit.org/kyodev/kyopages/raw/master/scripts/getInfo
+wget -O getInfo https://framagit.org/kyodev/kyopages/raw/master/scripts/getInfo
 chmod +x getInfo && ./getInfo