kyopages/scripts/getInfo

1138 lines
42 KiB
Plaintext
Raw Normal View History

2017-07-30 17:08:05 +02:00
#!/bin/bash
2017-08-21 19:07:08 +02:00
version=1.1.0
date="21/08/2017"
2017-08-02 01:16:24 +02:00
projet="simpledeb"
2017-07-30 17:08:05 +02:00
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues"
script="getInfo"
2017-08-03 02:44:53 +02:00
urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/$script"
2017-08-17 10:49:12 +02:00
urlNotice="https://kyodev.frama.io/kyopages/scripts/getInfo/"
2017-08-18 11:29:40 +02:00
lognameDev="kyodev"
2017-07-30 17:08:05 +02:00
##### license LPRAB/WTFPL
2017-08-17 10:49:12 +02:00
# auteur: simpledeb
2017-07-30 17:08:05 +02:00
# contributeurs: kyodev
#####
2017-08-20 10:14:56 +02:00
f__affichage(){ # v06/2017 définition couleurs
2017-07-30 17:08:05 +02:00
YELLOW="$(printf "\033[0;33m")" # ?
GREEN="$(printf "\033[0;32m")" # ok
BLUE="$(printf "\033[0;34m")" # info
RED="$(printf "\033[0;31m")" # alerte
COLOR="$(printf "\033[0m")" # standard
2017-08-03 02:44:53 +02:00
clear
2017-07-30 17:08:05 +02:00
printf "$BLUE"
cat << 'EOF'
_ ___ __
__ _ ___| |_|_ _|_ __ / _| ___
/ _' |/ _ \ __|| || '_ \| |_ / _ \
| (_| | __/ |_ | || | | | _| (_) |
\__, |\___|\__|___|_| |_|_| \___/
|___/
EOF
echo -e "$YELLOW version $version - $date$COLOR\n"
}
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-08-17 10:49:12 +02:00
f__architecture(){ # v08/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-08-17 10:49:12 +02:00
# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si upgrade($opType)
f__error() { # v16/08/2017
echo -e "\n$RED Erreur critique: $1 $COLOR"
2017-07-30 17:08:05 +02:00
for (( i=2 ; i<=$# ; i++ )); do echo -e " $BLUE${!i}"; done
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-08-17 10:49:12 +02:00
# affichage des paramètres en bleu, si $1=raw, pas d'espace en début de ligne, pas de ligne vide à la fin
2017-08-21 19:07:08 +02:00
# si $1=log, uniquement $2 logué
f__info() { # v21/08/2017
if [ "$1" == "raw" ] || [ "$1" == "log" ]; then depart=2;
2017-08-17 10:49:12 +02:00
else local espace=" "; local depart=1; fi
2017-08-21 19:07:08 +02:00
[ "$1" == "log" ] && f__log "$(sed -E 's/\\t//;s/\\n// ' <<< $2 | xargs )"
2017-08-17 10:49:12 +02:00
for (( i=$depart ; i<=$# ; i++ )); do echo -e "$espace$BLUE${!i}"; done
[ "$1" == raw ] && printf "$COLOR" || echo "$COLOR"
2017-07-30 17:08:05 +02:00
}
2017-08-21 19:07:08 +02:00
# affichage des paramètres en bleu, si $1=raw, pas d'espace en début de ligne, pas de ligne vide à la fin
# si $1=log, uniquement $2 logué avec \t et \n supprimés
f__info() { # v21/08/2017
if [ "$1" == "raw" ] || [ "$1" == "log" ]; then depart=2;
else local espace=" "; local depart=1; fi
[ "$1" == "log" ] && f__log "$(sed -E 's/\\t//;s/\\n// ' <<< $2 | xargs )"
for (( i=$depart ; i<=$# ; i++ )); do echo -e "$espace$BLUE${!i}"; done
[ "$1" == raw ] && printf "$COLOR" || echo "$COLOR"
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-08-17 12:12:05 +02:00
f__requis(){ # v17/08/2017-3
local dependsMissing packagesMissing
unset debOnlyPackages debOnlyPresents
for i in $1; do
local command="$(cut -d '>' -f 1 <<< $i)"
local package="$(cut -d '>' -f 2 <<< $i)"
if [ "$2" == "debOnly" ]; then
if [ "$(which dpkg)" ]; then # package only et debian
LC_ALL=C dpkg --get-selections | grep -qE "^$package[[:space:]]+install" \
&& debOnlyPresents+="$package " || debOnlyPackages+="$package "
else f__error "dpkg n'est pas disponible sur ce système"; fi
elif [ -z "$(which $command)" ]; then
dependsMissing+="$command "
packagesMissing+="$package "
fi
done
[ "$debOnlyPackages" ] && debOnlyPackages="$(xargs <<< $debOnlyPackages)" # trim début & fin
[ "$debOnlyPresents" ] && debOnlyPresents="$(xargs <<< $debOnlyPresents)" # trim début & fin
[ "$debOnlyPackages" ] && return 1
[ "$debOnlyPresents" ] && return 0
if [ "$dependsMissing" ]; then
if [ -e /etc/debian_version ]; then f__error "paquet(s) manquant(s): " " $dependsMissing" \
" vous devriez exécuter:$GREEN apt install $packagesMissing"
else f__error "commandes(s) manquante(s): " "$dependsMissing"; fi
2017-08-17 10:49:12 +02:00
fi
2017-08-17 12:12:05 +02:00
}
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-08-21 19:07:08 +02:00
f__user(){ # v21/08/2017-4
if [ "$USER_INSTALL" ]; then # user_ via variable environnement, moyen d'injecter root
user_="$USER_INSTALL";
return 0
2017-08-17 10:49:12 +02:00
fi
2017-08-21 19:07:08 +02:00
local user_id test
local root_login="$(grep ':0:' /etc/passwd | cut -d':' -f1)" || local root_login="root"
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
user_="$(grep -v 'root' <<< $(who) | head -n1 | cut -d ' ' -f1)";
elif grep -q 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab; then
user_="$(grep 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | head -n1 | cut -d' ' -f2)";
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-08-03 02:44:53 +02:00
# test wget, $1 url à tester, sortie script sur erreur
2017-08-17 10:49:12 +02:00
f__wget_test(){ # v07/2017
2017-08-03 02:44:53 +02:00
echo " $1"
2017-08-17 10:49:12 +02:00
wget -Sq --tries=1 --timeout=15 --user-agent="$user_agent" -O /dev/null "$1"
2017-08-03 02:44:53 +02:00
f__error "Erreur wget" " réessayer et si persistance, contacter $projet $contact" " en indiquant les messages précédents."
2017-07-30 17:08:05 +02:00
}
2017-08-03 02:44:53 +02:00
# inscription dans tache upgrade en anacron hebdomadaire, via cron horaire
2017-08-20 10:14:56 +02:00
fscript_cronAnacron(){ # v20/08/2017
[ "$(type -t fscript_cronAnacron_special)" ] && fscript_cronAnacron_special # test, si fonction spécifique, appel
2017-08-07 13:24:21 +02:00
local dirAnacron="/home/$user_/.config/anacron"
2017-08-03 02:44:53 +02:00
local dirSpool="$dirAnacron/spool"
local fileAnacron="$dirAnacron/$script.anacrontab"
2017-08-18 20:15:13 +02:00
[ $EUID -eq 0 ] && sed -i "/$script.anacrontab/d" /etc/crontab
2017-08-07 21:04:56 +02:00
case "$1" in
2017-08-17 10:49:12 +02:00
install | upgrade )
2017-08-07 21:04:56 +02:00
mkdir -p "$dirAnacron"
# table anacron
2017-08-19 08:50:09 +02:00
echo "7 01 $script nice /opt/bin/$script --upgrade 1>/dev/null" > "$fileAnacron" # juste erreurs en syslog
## anacron journalier pour dev logname
if [ "$user_" == "$lognameDev" ]; then
echo "1 01 $script""Dev nice /opt/bin/$script --upgrade 1>/dev/null" >> "$fileAnacron" # juste erreurs en syslog
fi
2017-08-07 21:04:56 +02:00
# création spool anacron utilisateur
mkdir -p "$dirSpool"
2017-08-17 10:49:12 +02:00
chown -R "$user_": "$dirAnacron" "$dirSpool"
if [ $EUID -eq 0 ]; then
# crontab pour activation horaire anacron
2017-08-07 21:04:56 +02:00
echo "@hourly $user_ /usr/sbin/anacron -t $fileAnacron -S $dirSpool" >> /etc/crontab
2017-08-17 10:49:12 +02:00
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"
2017-08-07 21:04:56 +02:00
;;
remove )
rm "$dirSpool/$script"* &>/dev/null
rm "$fileAnacron" &>/dev/null
rmdir "$dirSpool" "$dirAnacron" &>/dev/null
;;
esac
2017-07-30 17:08:05 +02:00
}
2017-08-17 10:49:12 +02:00
# mise à jour script si dispo
2017-08-21 19:07:08 +02:00
fscript_dl(){ # v21/08/2017
2017-08-18 20:15:13 +02:00
f__requis "wget"
2017-08-21 19:07:08 +02:00
if [ "$script_aJour" == "ok" ]; then
f__log "pas de mise à jour disponible pour $script"
return 0
fi
2017-08-07 21:58:22 +02:00
local dirTemp="/tmp/$script-$RANDOM/"
mkdir -p "$dirTemp"
2017-08-19 08:50:09 +02:00
wget -q --tries=2 --timeout=15 -O "$dirTemp$script" "$urlScript"
2017-08-07 21:58:22 +02:00
if [ "$?" != "0" ]; then f__wget_test "$urlScript"; fi
2017-08-17 10:49:12 +02:00
chmod 755 "$dirTemp$script"
2017-08-07 21:58:22 +02:00
chown "$user_": "$dirTemp$script"
cp -d "$dirTemp$script" /opt/bin/"$script"
rm -rf "$dirTemp"
2017-08-17 10:49:12 +02:00
fscript_cronAnacron "upgrade"
2017-08-21 19:07:08 +02:00
f__info "log" "\n $script mis à jour en version $versionScript"
2017-08-07 21:58:22 +02:00
}
# version script en ligne, assigne $versionScript, $script_aJour=ok|ko
2017-08-19 08:50:09 +02:00
fscript_get_version(){ # v19/08/2017
2017-08-18 20:15:13 +02:00
f__requis "wget"
2017-08-19 08:50:09 +02:00
f__info "$GREEN""\n version script en cours: $version"
2017-08-07 21:58:22 +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
else f__info "version script en ligne non accessible"; fi
}
2017-08-08 12:48:49 +02:00
# installation du script dans le système
2017-08-21 19:07:08 +02:00
fscript_install(){ # v21/08/2017
2017-08-07 21:58:22 +02:00
if dirname "$0" | grep -q 'bin' ; then
2017-08-19 08:50:09 +02:00
f__info "\n $script $version est déjà installé"
2017-08-07 21:58:22 +02:00
return 1
fi
[ $EUID -eq 0 ] || f__error "vous devez être ROOT pour installer ce script dans le système"
2017-08-18 20:15:13 +02:00
f__requis "wget anacron cron"
2017-08-07 21:58:22 +02:00
# install /opt
mkdir -p /opt/bin/
cp -d "$(basename $0)" "/opt/bin/$script"
ln -s "/opt/bin/$script" "/usr/bin/$script" &>/dev/null
2017-08-17 10:49:12 +02:00
chmod 755 "/opt/bin/$script"
2017-08-07 21:58:22 +02:00
# cron/anacron install
fscript_cronAnacron "install"
# création fichier log
touch "$fileLogs"
2017-08-17 10:49:12 +02:00
chmod 644 "$fileLogs"
chown "$user_": "$fileLogs" "/opt/bin/$script"
[ -f "$script"_changelog.md ] || rm "$(basename $0)" &>/dev/null ## on efface pas si changelog (dev)
2017-08-21 19:07:08 +02:00
f__info "log" "$script $version installé dans le système." "maintenant, appel du script par:$GREEN $script$BLUE (sans ./)"
2017-08-07 21:58:22 +02:00
}
# suppression du script dans le système
2017-08-21 19:07:08 +02:00
fscript_remove(){ # v21/08/2017
2017-08-08 12:48:49 +02:00
[ $EUID -eq 0 ] || f__error "vous devez être ROOT pour supprimer ce script dans le système"
2017-08-07 21:58:22 +02:00
# suppression de /opt
rm /opt/bin/"$script" &>/dev/null
unlink /usr/bin/"$script" &>/dev/null
# cron/anacron remove
2017-08-17 10:49:12 +02:00
fscript_cronAnacron "remove"
2017-08-21 19:07:08 +02:00
f__info "log" "$script $version supprimé du système."
2017-08-07 21:58:22 +02:00
}
2017-08-03 02:44:53 +02:00
# assigne $context_appli, context_break
fi__context(){
context_break="\n"
if [ -t 0 ]; then context_appli="terminal";
elif [ -x /usr/bin/zenity ]; then context_appli="zenity";
elif [ -x /usr/bin/kdialog ]; then context_appli="kdialog";
else exit 1; fi
}
2017-08-02 05:30:37 +02:00
2017-08-03 02:44:53 +02:00
# $1 oui|non, $2 message question, return 0 pour défaut, 1 sinon
fi__dialog_oui_non () {
[[ $1 =~ ^oui$|^non$ ]] || f__error "dialog_oui_non, erreur appel"
local reply
[ "$1" == "oui" ] && local defaut="oui" || local defaut="non"
case $context_appli in
terminal )
[ "$defaut" == "oui" ] && printf "$2 [O/n] " || printf "$2 [o/N] "
read -r reply ;;
zenity )
zenity --question --text="$2" || reply="n" ;;
kdialog )
kdialog --yesno "$2" || reply="n" ;;
esac
shopt -s nocasematch
if [ "$defaut" == "oui" ]; then
if [[ ! $reply =~ ^no?n?$ ]]; then return 0; else return 1; fi
elif [ "$defaut" == "non" ]; then
if [[ ! $reply =~ ^ou?i?$ ]]; then return 0; else return 1; fi
2017-08-02 05:30:37 +02:00
fi
2017-08-03 02:44:53 +02:00
shopt -u nocasematch
}
get_battery() { # thanks neofetch, assigne $battery
for bat in "/sys/class/power_supply/BAT"*; do
local capacity="$(< "${bat}/capacity")"
local status="$(< "${bat}/status")"
# Fix for bash on Windows 10 which includes /proc files for battery usage despite there not being a battery installed.
[[ -z "$capacity" ]] && return
battery+="${capacity}% [${status}]"
done
return
[[ "$battery_state" ]] && battery+=" En charge"
2017-08-02 05:30:37 +02:00
}
2017-08-06 02:43:48 +02:00
get_cpu() { # thanks neofetch, assigne $cpu
2017-08-02 05:30:37 +02:00
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"
# Get cpu speed
if [[ -d "$speed_dir" ]]; then
2017-08-03 13:37:46 +02:00
local speedMin="$(< "${speed_dir}/scaling_min_freq")"
local speed="$(< "${speed_dir}/scaling_max_freq")"
2017-08-02 05:30:37 +02:00
speed="$((speed / 100000))"
2017-08-03 13:37:46 +02:00
local speedMin="$((speedMin / 100000))"
2017-08-02 05:30:37 +02:00
else
local speed="$(awk -F ': |\\.' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)"
local speed="$((speed / 100))"
fi
# Get cpu temp
if [ -f "$temp_dir" ]; then
temp="$(< "$temp_dir")"
temp="$((temp * 100 / 10000))"
temp="[${temp/${temp: -1}}.${temp: -1}°C]"
fi
# Show/hide hyperthreaded cores
cores="$(grep "^core id" /proc/cpuinfo | sort -u | wc -l)" # physique
coresT="$(grep -c "^processor" /proc/cpuinfo)" # logique
# Fix for speeds under 1ghz
if [[ -z "${speed:1}" ]]; then speed="0.${speed}"; else speed="${speed:0:1}.${speed:1}"; fi
2017-08-03 13:37:46 +02:00
if [[ -z "${speedMin:1}" ]]; then speedMin="0.${speedMin}"; else speedMin="${speedMin:0:1}.${speedMin:1}"; fi
cpu="$cpu @ ${speedMin} - ${speed} GHz $temp"
2017-08-02 05:30:37 +02:00
# 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
cpu="${cpu/@/(${cores})(${coresT}) @}"
}
2017-08-06 02:43:48 +02:00
get_de() { # thanks neofetch, assigne $de
2017-08-03 02:44:53 +02:00
de="${XDG_CURRENT_DESKTOP/i3}"
de="${de/'X-'}"
de="${de/Budgie:GNOME/Budgie}"
# Fallback to using xprop.
[[ -n "$DISPLAY" && -z "$de" ]] && de="$(xprop -root | awk '/KDE_SESSION_VERSION|^_MUFFIN|xfce4|xfce5/')"
# Format strings
case "$de" in
"KDE_SESSION_VERSION"*) de="KDE${de/* = }" ;;
*"TDE_FULL_SESSION"*) de="Trinity" ;;
*"MUFFIN"* | "Cinnamon") de="$(cinnamon --version)"; de="${de:-Cinnamon}" ;;
*"xfce4"*) de="XFCE4" ;;
*"xfce5"*) de="XFCE5" ;;
esac
}
get_disk() { # thanks neofetch, assigne $disk
# df flags
local df_flags="-h -l --total"
local df_dir="total"
# Get the disk info
disk="$(df $df_flags | awk -v dir="$df_dir" '$0 ~ dir {print $2 ":" $3 ":" $5}')"
# Format the output
local disk_used="${disk#*:}"
disk_used="${disk_used%%:*}"
local disk_total="${disk%%:*}"
disk_total_per="${disk#*:*:}"
# Put it all together
disk="${disk_used} / ${disk_total} (${disk_total_per})"
}
get_distro() { # thanks neofetch, assigne $distro
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
for file in /etc/os-release /usr/lib/os-release /etc/*release /usr/lib/*release; do
source "$file" && break
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)"
2017-08-17 17:32:34 +02:00
# for debian, add version
grep -qi 'Debian' /etc/issue && distro="$(sed 's/"//g' <<< $distro) $(cat /etc/debian_version)"
2017-08-03 02:44:53 +02:00
fi
[[ -z "$distro" ]] && distro="$os (Unknown)"
}
2017-08-06 02:43:48 +02:00
get_gpu() { # thanks neofetch, assigne $gpu
gpu="$(lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}')"
2017-08-02 05:30:37 +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/\]*}"
2017-08-03 02:44:53 +02:00
gpu="AMD $gpu" ;;
2017-08-02 05:30:37 +02:00
*"nvidia"*)
gpu="${gpu//Intel*$'\n'}"
gpu="${gpu/*\[}"
gpu="${gpu/\]*}"
2017-08-03 02:44:53 +02:00
gpu="NVIDIA $gpu" ;;
2017-08-02 05:30:37 +02:00
*"virtualbox"*)
2017-08-03 02:44:53 +02:00
gpu="VirtualBox Graphics Adapter" ;;
2017-08-02 05:30:37 +02:00
esac
[[ "$gpu" =~ "intel" ]] && gpu="Intel Integrated Graphics"
}
2017-08-06 11:48:11 +02:00
get_ip() { # $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type, $ifname, $ifname_type
2017-08-18 20:15:13 +02:00
[ -z "$(which ip)" ] && return 1
2017-08-18 11:29:40 +02:00
ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print $4,"(",$2,")"}')"
2017-08-18 00:14:09 +02:00
ip_local_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)"
2017-08-18 11:29:40 +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,")"}')"
gateway_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.µ)/\1 (ethernet)/' <<< $gateway)"
gateway_one="$(head -n 1 <<< $gateway | awk '{print $1}')"
2017-08-18 20:15:13 +02:00
ifname="$(ip -4 route | awk '/proto kernel/ {print $3}')"
ifname_type="$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname)"
2017-08-06 02:43:48 +02:00
}
2017-08-18 20:15:13 +02:00
get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # v18/08/2017
2017-08-06 02:43:48 +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
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
2017-08-18 20:15:13 +02:00
if [ "$(which dig)" ] && [ -z "$ip_public" ]; then
2017-08-06 02:43:48 +02:00
for ii in $dig_test ; do
2017-08-18 00:14:09 +02:00
ip_public="$(dig +short $(sed 's;/; ;g' <<< $ii))"
2017-08-06 02:43:48 +02:00
[ "$ip_public" ] && break
done
fi
2017-08-18 20:15:13 +02:00
if [ "$(which wget)" ] && [ -z "$ip_public" ]; then
2017-08-06 02:43:48 +02:00
cmd="wget --quiet --tries=1 --timeout=5 -O - "
for ii in $ip_test ; do
2017-08-18 00:14:09 +02:00
ip_public="$($cmd $ii)"
2017-08-06 02:43:48 +02:00
[ "$ip_public" ] && break
done
fi
2017-08-18 20:15:13 +02:00
if [ "$(which curl)" ] && [ -z "$ip_public" ]; then
2017-08-06 02:43:48 +02:00
cmd="curl --silent --location --retry 0 --max-time 5" #--location pour aider redirections
for ii in $ip_test ; do
2017-08-18 00:14:09 +02:00
ip_public="$($cmd $ii)"
2017-08-06 02:43:48 +02:00
[ "$ip_public" ] && break
done
fi
2017-08-18 20:15:13 +02:00
if [ "$(which telnet)" ] && [ -z "$ip_public" ]; then
2017-08-18 00:14:09 +02:00
ip_public="$(telnet $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4)"
2017-08-06 02:43:48 +02:00
fi
2017-08-18 20:15:13 +02:00
if [ "$(which nc)" ] && [ -z "$ip_public" ] && [ "$1" != "IPv6" ]; then
2017-08-18 00:14:09 +02:00
ip_public="$(nc $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4)"
2017-08-06 02:43:48 +02:00
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
2017-08-03 02:44:53 +02:00
}
2017-08-02 05:30:37 +02:00
get_memory() { # thanks neofetch, assigne $memory
# MemUsed = Memtotal + Shmem - MemFree - Buffers - Cached - SReclaimable
# Source: https://github.com/KittyKatt/screenFetch/issues/386#issuecomment-249312716
while IFS=":" read -r a b; do
case "$a" in
"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}))" ;;
esac
done < /proc/meminfo
local mem_used="$((mem_used / 1024))"
local mem_total="$((mem_total / 1024))"
memory="${mem_used}Mo / ${mem_total}Mo"
}
2017-08-06 02:43:48 +02:00
get_modules(){ # thanks wireless-info for 'net', $1 net|video, assigne $exportText
2017-08-03 02:44:53 +02:00
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)"
2017-08-18 00:14:09 +02:00
local modules="$(lsmod | grep -E "(^|[[:punct:] ])($MODMATCHES|$LSMODMATCHES)[^[:punct:] ]*([[:punct:] ]|$)")"
2017-08-06 02:43:48 +02:00
exportText="\n### modules réseau\n\nliste non garantie complète \n"
elif [ "$1" == "video" ]; then
2017-08-18 00:14:09 +02:00
local modules="$(lsmod | grep -i -E 'amdgpu|ati|i915|nouveau|nvidia|radeon|video|gma')"
2017-08-06 02:43:48 +02:00
exportText="\n### modules video\n\nliste non garantie complète \n"
fi
exportText+='```\n'
exportText+="$modules \n"
2017-08-18 11:29:40 +02:00
exportText+='```\n\n'
2017-08-06 02:43:48 +02:00
# grep -vE '#|^$' /etc/modules
2017-08-02 05:30:37 +02:00
}
2017-08-03 02:44:53 +02:00
get_resolution() { # thanks neofetch, assigne $resolution
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-08-02 05:30:37 +02:00
}
get_shell(){ # thanks neofetch, assigne $shell
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-08-06 02:43:48 +02:00
get_wm() { # thanks neofetch, assigne $wm
2017-08-03 02:44:53 +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-08-02 01:16:24 +02:00
2017-08-06 02:43:48 +02:00
fi_cpu(){
2017-08-18 00:14:09 +02:00
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)"
2017-08-19 03:45:31 +02:00
###
2017-08-06 02:43:48 +02:00
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"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
text+="flags cpu: \n"
text+='```\n'
text+="$cpu_flags \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-08-17 17:32:34 +02:00
fi_disk(){
2017-08-18 00:14:09 +02:00
local fstab="$(grep -vE '#|^$' /etc/fstab)"
local disk_lsblk="$(lsblk -fi -o +SIZE -o +OWNER)"
local utilDisk="$(df -h --output=source,target,fstype,size,used,avail,pcent --exclude=tmpfs --exclude=devtmpfs --exclude=devtmpfs | grep -Ev "devpts|none|proc|sys|tmpfs|udev")"
local resume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume)"
local idSwap="$(grep -vE '#|^$' /etc/fstab | grep 'swap' | grep 'UUID' | sed -E 's/^UUID=([0-9a-Z-]*).*/\1/')"
local idResume="$(grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume | grep 'RESUME=' | grep 'UUID' | sed -E 's/^.*UUID=([0-9a-Z-]*).*/\1/')"
local diskAta="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^ata/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/')"
local diskUsb="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^usb/!d; /part/d; /\/sd/!d; s/^.*\(sd..*\)$/\1/')"
local diskMmc="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^mmc/!d; /part/d; /\/mmcblk/!d; s/^.*\(mmcblk..*\)$/\1/')"
local diskNvme="$(ls -l /dev/disk/by-id/ | awk '{ print $9, $11 }' | sed '/^nvme/!d; /part/d; /\/nvme/!d; s/^.*\(nvme...*\)$/\1/')"
2017-08-19 03:45:31 +02:00
###
2017-08-17 17:32:34 +02:00
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"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-17 17:32:34 +02:00
text+="**lsblk -fi -o +SIZE -o +OWNER** (disques) \n"
text+='```\n'
text+="$disk_lsblk \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-17 17:32:34 +02:00
text+="**df -h ...** (utilisation disques) \n"
text+='```\n'
text+="$utilDisk \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-17 17:32:34 +02:00
text+="**grep -Ev '#|^$' /etc/initramfs-tools/conf.d/resume** (resume) \n"
text+='```\n'
text+="$resume \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
if [ "$idSwap" ] && [ "$idResume" ] && [ "$idSwap"!="$idResume" ]; then
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\n"
fi
text+="**types de disque** \n\n"
2017-08-17 17:32:34 +02:00
[ "$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"
}
2017-08-06 02:43:48 +02:00
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
2017-08-06 19:10:10 +02:00
text+="ne peut être affiché qu'avec les droits root\n"
2017-08-06 02:43:48 +02:00
echo -e "$text" >> "$fileOutput"
return 0
fi
2017-08-19 03:45:31 +02:00
###
2017-08-18 00:14:09 +02:00
local dmesg_err="$(dmesg -l err)"
local dmesg_warn="$(dmesg -l warn)"
local dmesg_crit="$(dmesg -l crit)"
2017-08-19 03:45:31 +02:00
if [ "$dmesg_err" ]; then
2017-08-06 02:43:48 +02:00
text+="**dmesg -l err** (erreur) \n"
text+='```\n'
text+="$dmesg_err \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
if [ "$dmesg_warn" ]; then
text+="**dmesg -l warn** (warning) \n"
text+='```\n'
text+="$dmesg_warn \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
if [ "$dmesg_crit" ]; then
text+="**dmesg -l crit** (critique) \n"
text+='```\n'
text+="$dmesg_crit \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
if [ -z "$dmesg_crit" ] && [ -z "$dmesg_warn" ] && [ -z "$dmesg_warn" ]; then
2017-08-19 03:45:31 +02:00
text+='```\n'
text+="pas de messages \n"
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
2017-08-17 10:49:12 +02:00
if [ "$1" == "dmesg" ]; then
2017-08-19 03:45:31 +02:00
echo > "$fileOutput" # vidage $fileOutput
2017-08-17 10:49:12 +02:00
chown "$user_": "$fileOutput"
fi
2017-08-06 02:43:48 +02:00
echo -e "$text" >> "$fileOutput"
}
fi_gpu(){
2017-08-18 00:14:09 +02:00
# local graphCards="$(lspci -nnk | grep -iEA 3 'vga|display|3d')"
local graphCards="$(lspci -nnvvv | grep -iEA 13 '^[0-9]+.*vga|display|3d')"
2017-08-18 20:15:13 +02:00
[ "$(which glxinfo)" ] && local openGl="$(glxinfo | grep 'OpenGL version string:')"
2017-08-18 00:14:09 +02:00
local resolutions="$(xrandr --query | grep '^ *[0-9]' | head -n 10)"
2017-08-19 03:45:31 +02:00
local extraitXorg="$(grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)' /var/log/Xorg.*.log /home/$user_/.local/share/xorg/Xorg.*.log 2>/dev/null)"
###
2017-08-06 02:43:48 +02:00
local text="## graphisme \n\n"
get_gpu; text+="**GPU: $gpu** \n"
get_resolution; text+="**résolution: $resolution** \n\n"
2017-08-19 03:45:31 +02:00
text+="**lspci -nnvvv | grep -iEA 13 '^[0-9]+.*vga|display|3d'** (matériel) \n"
2017-08-06 02:43:48 +02:00
text+='```\n'
text+="$graphCards \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
if [ "$openGl" ]; then
text+="**glxinfo | grep 'OpenGL version string:'** \n"
text+='```\n'
text+="$openGl \n"
text+='```\n\n'
fi
2017-08-06 02:43:48 +02:00
text+="**xrandr --query | grep '^ *[0-9]' | head -n 10** (10 premières résolutions possibles) \n"
text+='```\n'
text+="$resolutions \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 11:48:11 +02:00
text+="**grep -E '\(WW\)|\(EE\)|\(NI\)|\(\?\?\)' /var/log/Xorg.*.log /home/user/.local/share/xorg/Xorg.*.log** (extrait xorg.log) \n"
2017-08-17 10:49:12 +02:00
[ "$noHome" == "true" ] && text+="attention pas de home utilisateur détecté \n"
2017-08-06 02:43:48 +02:00
text+='```\n'
text+="$extraitXorg \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
get_modules video; text+="$exportText"
echo -e "$text" >> "$fileOutput"
}
2017-08-03 02:44:53 +02:00
fi_help(){
2017-08-07 11:47:09 +02:00
printf "$BLUE"
2017-08-03 02:44:53 +02:00
cat << 'EOF'
----------------------------------------------------------------------
./getInfo : exécution normale
getInfo : exécution normale si script installé dans le système
options:
2017-08-17 10:49:12 +02:00
-d, --dmesg : dmesg erreur, warning, critique. root requis, rapport 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
-s, --ssid : affiche configurations ssid /!\ infos confidentielles
pas de rapport, root et NetworkManager requis
-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
2017-08-03 02:44:53 +02:00
EOF
printf "$COLOR\n"
}
2017-08-06 02:43:48 +02:00
fi_localisation(){
2017-08-18 00:14:09 +02:00
local locale="$(grep -vE '#|^$' /etc/default/locale)"
local timezone="$(cat /etc/timezone)"
local keymap="$(setxkbmap -query)"
local keyboard="$(grep -vE '#|^$' /etc/default/keyboard)"
2017-08-19 03:45:31 +02:00
###
2017-08-06 02:43:48 +02:00
local text="## localisation \n\n"
text+="**grep -vE '#|^$' /etc/default/locale** \n"
text+='```\n'
text+="$locale \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-17 10:49:12 +02:00
text+="**cat /etc/timezone** \n"
text+='```\n'
text+="$timezone \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
text+="**setxkbmap -query** \n"
text+='```\n'
text+="$keymap \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
text+="**grep -vE '#|^$' /etc/default/keyboard** \n"
text+='```\n'
text+="$keyboard \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
echo -e "$text" >> "$fileOutput"
}
fi_nm(){
2017-08-19 03:45:31 +02:00
[ -x "$(which nmcli)" ] || return 0 # root sur autre que debian?
2017-08-18 00:14:09 +02:00
local nm_etat="$(grep -vE '#|^$' /var/lib/NetworkManager/NetworkManager.state)"
local nm_conf="$(grep -vE '#|^$' /etc/NetworkManager/NetworkManager.conf)"
2017-08-19 03:45:31 +02:00
###
2017-08-06 02:43:48 +02:00
local text="## Network Manager \n\n"
text+="**grep -vE '#|^$' /var/lib/NetworkManager/NetworkManager.state** \n"
text+='```\n'
text+="$nm_etat \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
text+="**grep -vE '#|^$' /etc/NetworkManager/NetworkManager.conf** \n"
text+='```\n'
text+="$nm_conf \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-08-07 11:47:09 +02:00
fi_nm_wifis(){
2017-08-18 00:14:09 +02:00
[ -x "$(which nmcli)" ] && [ -z "$1" ] || return 0
local nm_wifis="$(nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY device wifi list)"
local nm_connected="$(LC_ALL=C nmcli -f SSID,ACTIVE,IN-USE device wifi list | grep -E 'yes[[:space:]]+\*' | awk '{print $1}')" # non utilisé
2017-08-19 03:45:31 +02:00
###
2017-08-06 02:43:48 +02:00
local text="## wifis à proximité \n\n"
2017-08-07 11:47:09 +02:00
text+="**nmcli -f SSID,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY device wifi list** \n"
2017-08-06 02:43:48 +02:00
text+='```\n'
text+="$nm_wifis \n"
text+='```\n'
echo -e "$text" >> "$fileOutput"
2017-08-02 01:16:24 +02:00
}
fi_reseau(){
2017-08-17 17:32:34 +02:00
local netcards="$(lspci -nnk | grep -iEA 3 'network|ethernet')"
# local netcards="$(lspci -nnvvv | grep -iEA 12 'network|ethernet')"
2017-08-18 11:29:40 +02:00
local 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-19 03:45:31 +02:00
if [ "$(which iwlist)" ]; then #paquet wireless-tools requis
local iwconfig="$(iwconfig 2>&1 | grep -v 'no wireless extensions' | grep -v '^$')"
fi
2017-08-18 00:14:09 +02:00
local interfaces="$(sed '/^#/d;s/^wpa-psk [[:graph:]]\+/wpa-psk <WPA key removed>/;/^$/d;s/\(.*\)/\1 /' /etc/network/interfaces)"
local route="$(ip route show)"
local resolv="$(grep -vE '#|^$' /etc/resolv.conf)"
2017-08-18 11:29:40 +02:00
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
2017-08-02 01:16:24 +02:00
done
2017-08-06 02:43:48 +02:00
local text="## réseau \n\n"
2017-08-19 03:45:31 +02:00
if [ "$(which iwlist)" ]; then # liste canaux wifi; paquet wireless-tools requis
2017-08-18 00:14:09 +02:00
local liste_canaux_wifi="$(iwlist chan 2>&1 | grep -vE 'no frequency information|^$')"
2017-08-06 02:43:48 +02:00
fi
2017-08-18 11:29:40 +02:00
###
2017-08-06 11:48:11 +02:00
get_ip; text+="**IP locale(s):** \n"
text+='```\n'
text+="$ip_local_type \n"
2017-08-18 11:29:40 +02:00
text+='```\n\n'
2017-08-06 19:10:10 +02:00
if grep -q 'wlx' <<< "$ifname"; then
2017-08-18 00:14:09 +02:00
text+="**Attention:** une interface wifi est en erreur: $(grep -o 'wlx' <<< $ifname) \n"
2017-08-06 19:10:10 +02:00
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
2017-08-06 11:48:11 +02:00
text+="**Passerelle(s):** \n"
text+='```\n'
2017-08-18 11:29:40 +02:00
text+="$gateway_type \n"
text+='```\n\n'
text+="l'IP publique peut être connue avec: "'`./getInfo --ip` ou `getInfo --ip` (script installé)\n\n'
2017-08-02 01:16:24 +02:00
text+="**lspci -nnk | grep -iEA 3 'network|ethernet'** \n"
text+='```\n'
text+="$netcards \n"
2017-08-18 11:29:40 +02:00
text+='```\n\n'
text+="**ip address** (ipv6 lien local, pas d'adresses MAC) \n"
2017-08-02 01:16:24 +02:00
text+='```\n'
2017-08-06 02:43:48 +02:00
text+="$ip_a \n"
2017-08-18 11:29:40 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
if [ "$iwconfig" ]; then
text+="**iwconfig** \n"
text+='```\n'
text+="$iwconfig \n"
2017-08-18 11:29:40 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
2017-08-02 01:16:24 +02:00
text+="**/etc/network/interfaces** \n"
text+='```\n'
text+="$interfaces \n"
2017-08-18 11:29:40 +02:00
text+='```\n\n'
2017-08-02 01:16:24 +02:00
text+="**ip route show** \n"
text+='```\n'
text+="$route \n"
2017-08-18 11:29:40 +02:00
text+='```\n\n'
2017-08-02 05:30:37 +02:00
text+="**/etc/resolv.conf** \n"
2017-08-02 01:16:24 +02:00
text+='```\n'
text+="$resolv \n"
2017-08-18 11:29:40 +02:00
text+='```\n\n'
2017-08-19 03:45:31 +02:00
if [ "$liste_canaux_wifi" ]; then
text+="**iwlist chan** \n"
text+='```\n'
text+="$liste_canaux_wifi \n"
text+='```\n\n'
fi
2017-08-18 11:29:40 +02:00
if [ "$netmgrinst" ]; then
2017-08-06 02:43:48 +02:00
text+="### network managers \n\n"
2017-08-18 11:29:40 +02:00
[ "$netmgrinst" ] && text+="installé(s): **$netmgrinst** \n" || text+="non trouvé parmi: ${netmgrnames[@]} \n"
2017-08-06 11:48:11 +02:00
text+="en fonctionnement: "
[ "$netmgrrun" ] && text+="**$netmgrrun** \n" || text+="non trouvé \n"
2017-08-06 02:43:48 +02:00
get_modules net; text+="$exportText"
fi
echo -e "$text" >> "$fileOutput"
}
fi_sources(){
2017-08-18 20:15:13 +02:00
[ "$(which apt)" ] || return 0 # retour si pas d'apt ? et aptitude...????
2017-08-19 03:45:31 +02:00
printf "."
2017-08-18 00:14:09 +02:00
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/)"
2017-08-19 03:45:31 +02:00
printf "."
2017-08-18 00:14:09 +02:00
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' ' ')"
2017-08-19 03:45:31 +02:00
printf "."
local httpredir="$(grep 'httpredir' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null)"
local upgradable="$(LC_ALL=C apt list --upgradable 2>/dev/null | sed 's/Listing...//' | grep -v '^$')"
printf "."
2017-08-18 00:14:09 +02:00
local dpkgArch="$(dpkg --print-architecture)"
local paquetBiz="$(dpkg -l | grep -v '^i' | grep "$dpkgArch" | awk '{print $1, $2, $3}')"
2017-08-19 03:45:31 +02:00
###
2017-08-06 02:43:48 +02:00
local text+="## sources list \n\n"
2017-08-19 03:45:31 +02:00
text+="**grep -rvE '^#|^$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null** \n"
2017-08-06 02:43:48 +02:00
text+='```\n'
text+="$sources \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
text+="dernière mise à jour **apt**: $dateMaj \n\n"
2017-08-19 03:45:31 +02:00
if [ "$autoremove" -ne 0 ] ; then
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'
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-17 10:49:12 +02:00
if [ "$httpredir" ]; then
text+="url **httpredir,** ces urls sont obsolètes, préférer http://deb.debian.org/debian/ ou un miroir local\n"
text+='```\n'
text+="$httpredir \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-17 10:49:12 +02:00
fi
if [ "$upgradable" ]; then
2017-08-19 03:45:31 +02:00
text+="**des paquets devraient être mis à jour.** "'`apt list --upgradable`'" \n"
2017-08-17 10:49:12 +02:00
text+='```\n'
text+="$upgradable \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-17 10:49:12 +02:00
fi
2017-08-06 02:43:48 +02:00
if [ "$paquetBiz" ]; then
2017-08-19 03:45:31 +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-06 02:43:48 +02:00
text+='```\n'
text+="$paquetBiz \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
fi
2017-08-02 01:16:24 +02:00
echo -e "$text" >> "$fileOutput"
}
2017-08-17 17:32:34 +02:00
fi_ssid(){ # affiche configurations ssid
2017-08-19 03:45:31 +02:00
[ "$(which nmcli)" ] || f__error "il manque NetworkManager"
[ $EUID -eq 0 ] || f__error "il manque les droits root"
2017-08-18 00:14:09 +02:00
local nm_ssid="$(grep -vE '#|^$' /etc/NetworkManager/system-connections/*)"
2017-08-17 17:32:34 +02:00
local text="## configuration(s) ssid networkmanager \n\n"
2017-08-19 03:45:31 +02:00
###
2017-08-17 17:32:34 +02:00
f__info="$RED""Attention, la clé du réseau wifi est visible $COLOR""aucun rapport n'a été créé"
text+='```\n'
text+="$nm_ssid \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-17 17:32:34 +02:00
echo -e "$text"
}
fi_system_analyse(){
2017-08-19 03:45:31 +02:00
[ -x "$(which systemd-analyze)" ] || return 0 # pas systemd
2017-08-18 00:14:09 +02:00
local bootTime="$(systemd-analyze time)"
local bootBlame="$(systemd-analyze blame | head -n 20)"
2017-08-19 03:45:31 +02:00
###
2017-08-17 17:32:34 +02:00
local text="## analyse boot \n\n"
2017-08-19 03:45:31 +02:00
text+="$(sed 's/Startup finished in /**durée de boot:** /; s/userspace/espace utilisateur/; s/= \(.*\)$/= **\1**/' <<< $bootTime) \n\n"
2017-08-17 17:32:34 +02:00
text+="**systemd-analyze blame | head -n 20** \n"
text+='```\n'
text+="$bootBlame \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-17 17:32:34 +02:00
echo -e "$text" >> "$fileOutput"
}
2017-08-03 02:44:53 +02:00
fi_systeme(){
2017-08-18 11:29:40 +02:00
[ -d /sys/firmware/efi ] && local mbr="**EFI boot**" || local mbr="**Legacy boot**"
2017-08-17 17:32:34 +02:00
[ -x "/usr/bin/lsb_release" ] && local description="$(lsb_release -ds)" #dépend de apt install lsb-release, sur debian, en standard, juste : lsb-base
local uname="$(uname -rmo)"
local bootImage="$(sed 's/root=[^ ]*//;s/[ ]\+/, /g' /proc/cmdline)"
local xorg="$XDG_SESSION_TYPE"
2017-08-06 11:48:11 +02:00
if [ -z "$xorg" ]; then
[ "$(ps -ef | grep -c 'wayland')" -gt 1 ] && xorg="wayland" || xorg="indéterminé"
fi
2017-08-17 17:32:34 +02:00
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)"
2017-08-18 11:29:40 +02:00
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)"
###
2017-08-06 02:43:48 +02:00
local text="## système \n\n"
2017-08-18 11:29:40 +02:00
get_cpu; text+="CPU: **$cpu** \n"
get_gpu; text+="GPU: **$gpu** \n"
text+="type de boot: $mbr \n"
2017-08-18 20:15:13 +02:00
get_distro; text+="distribution: **$distro** \n\n"
2017-08-06 02:43:48 +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-03 13:37:46 +02:00
text+='```\n'
2017-08-03 02:44:53 +02:00
text+="architecture: $architecture \n"
2017-08-17 17:32:34 +02:00
[ "$description" ] && text+="description: $description \n"
2017-08-03 02:44:53 +02:00
text+="uname: $uname \n"
2017-08-06 02:43:48 +02:00
text+="$bootImage \n"
2017-08-03 02:44:53 +02:00
get_resolution; text+="résolution: $resolution \n"
2017-08-06 19:10:10 +02:00
text+="serveur d'affichage: $xorg \n"
2017-08-06 02:43:48 +02:00
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"
2017-08-03 02:44:53 +02:00
text+="dernier boot: $lastboot, uptime: $uptime \n"
2017-08-18 11:29:40 +02:00
text+='```\n\n'
2017-08-03 13:37:46 +02:00
echo -e "$text" >> "$fileOutput"
}
2017-08-06 02:43:48 +02:00
fi_usb(){
2017-08-18 00:14:09 +02:00
local lsusb="$(lsusb)"
local lsusb_t="$(lsusb -t)"
2017-08-19 03:45:31 +02:00
###
2017-08-06 02:43:48 +02:00
local text="## périphériques USB \n\n"
text+="**lsusb** \n"
text+='```\n'
text+="$lsusb \n"
2017-08-19 03:45:31 +02:00
text+='```\n\n'
2017-08-06 02:43:48 +02:00
text+="**lsusb -t** \n"
text+='```\n'
text+="$lsusb_t \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-08-19 03:45:31 +02:00
paste(){
2017-08-17 10:49:12 +02:00
paste_curl_pastery "$fileOutput" "$PasteDuration" "$optDebug"
2017-08-06 02:43:48 +02:00
# à tester paste_curl_markdownshare "$fileOutput"
}
2017-08-19 03:45:31 +02:00
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)"
local id="$(echo $curl | cut -d '"' -f 4)"
f__info "\n\n votre paste:" "https://www.pastery.net/$id/"
[ "$3" == "debug" ] && echo -e "\n$curl\n"
# ?api_key=<api_key>
# &duration=<duration> en mn, 1 jour par défaut
# &language=autodetect possible
# &max_views=<max_views>
# 100ko max
}
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
#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-07-30 17:08:05 +02:00
# initialisation
2017-08-20 10:14:56 +02:00
PATH='/usr/sbin:/usr/bin:/sbin:/bin' ; IFS=' '; TERM=xterm
export PATH TERM
2017-08-03 02:44:53 +02:00
fileOutput="getInfo_rapport.md"
fileLogs="/var/log/sdeb_$script.log"
2017-08-17 10:49:12 +02:00
PasteDuration=7 # durée conservation du paste en jours
2017-08-07 11:47:09 +02:00
f__affichage
2017-08-21 19:07:08 +02:00
f__user && retourFUser=0 || retourFUser="$?"
[ "$retourFUser" -eq 1 ] && f__error "user indéterminé, pour contourner, lancer le script avec:\n USER_INSTALL=user $0 \n"
if [ "$retourFUser" -eq 2 ]; then
f__info "user détecté, mais pas de home: /home/$user_"
noHome="true"
fi
2017-08-18 20:15:13 +02:00
f__requis "gawk wget curl ip>iproute2" # pour fonctionnement programme
2017-08-17 10:49:12 +02:00
fi__context
2017-08-01 01:48:22 +02:00
2017-08-19 03:45:31 +02:00
prg_1(){ # début
2017-08-07 09:49:37 +02:00
rm "$fileOutput" &>/dev/null
touch "$fileOutput"
chown $user_: "$fileOutput"
2017-08-18 00:14:09 +02:00
os="$(uname -s)"
hote="$(uname -n)"
dateRapport="$(date +"%d %b %Y %H:%M %z")"
2017-08-07 11:47:09 +02:00
echo -e "# getInfo $version sur $hote / $os \n" > "$fileOutput"
2017-08-06 19:10:10 +02:00
echo -e "Rapport au $dateRapport \n" >> "$fileOutput"
}
2017-08-19 01:35:18 +02:00
prg_2(){ # traitements principaux
2017-08-17 10:49:12 +02:00
printf "."
fi_systeme; printf "."
fi_cpu; printf "."
fi_gpu; printf "."
fi_localisation; printf "."
fi_sources "."
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"
2017-08-03 02:44:53 +02:00
}
2017-08-06 02:43:48 +02:00
prg_3(){ # fin de traitements
2017-08-19 03:45:31 +02:00
echo -e "[rapport getInfo v$version]($urlNotice)\n" >> "$fileOutput"
fi__dialog_oui_non "non" "exporter sur un pastebin par défaut?" || paste
2017-08-06 02:43:48 +02:00
f__info "\n$GREEN le rapport est disponible en local, fichier: $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-17 10:49:12 +02:00
options="$@"
2017-08-08 12:48:49 +02:00
for i in "$options"; do
case $i in
2017-08-17 10:49:12 +02:00
--list | -l ) [ -e $fileOutput ] && cat $fileOutput || f__info "pas de rapport à afficher" ;; # afficher le rapport existant
--paste | -p ) fi_paste ;; # exporte le rapport existant
--ssid | -s ) fi_ssid ;; # affiche configurations ssid, root requis
--install | -i ) fscript_install ;; # installation du script dans le système
--remove | -r ) fscript_remove ;; # suppression du script dans le système
2017-08-19 03:45:31 +02:00
--upgrade | -u )
opType="upgrade"
fscript_get_version
fscript_dl ;; # upgrade script si maj possible
2017-08-17 10:49:12 +02:00
--version | -v ) fscript_get_version ;; # version du script, en ligne et exécuté
"" ) if [ $# -eq 0 ];then
2017-08-06 02:43:48 +02:00
prg_1
prg_2
prg_3
2017-08-03 02:44:53 +02:00
fi ;; # programme
2017-08-19 03:45:31 +02:00
--dmesg | -d )
fi_dmesg "dmesg"
prg_3 ;; # rapport dmesg only, root requis
2017-08-18 00:14:09 +02:00
--ip )
2017-08-08 12:48:49 +02:00
get_ip_public "IPv4"
2017-08-18 20:15:13 +02:00
[ "$ip_public" ] && f__info "raw" "$GREEN ip4: $ip_public"
2017-08-08 12:48:49 +02:00
get_ip_public "IPv6"
2017-08-19 03:45:31 +02:00
[ "$ip_public" ] && f__info "raw" "$BLUE ip6: $ip_public\n"
2017-08-18 20:15:13 +02:00
;; # affiche ip public
2017-08-19 03:45:31 +02:00
--help | -h | * ) fi_help ;; # affichage help
2017-08-03 02:44:53 +02:00
esac
done
2017-08-08 12:48:49 +02:00
2017-08-17 10:49:12 +02:00
exit 0
2017-08-02 01:16:24 +02:00
2017-08-06 02:43:48 +02:00
wget -O getInfo https://framagit.org/kyodev/kyopages/raw/master/scripts/getInfo
2017-08-02 01:16:24 +02:00
chmod +x getInfo && ./getInfo