This commit is contained in:
kyodev 2017-08-03 02:44:53 +02:00
parent 5be3053523
commit 29d487249f
1 changed files with 447 additions and 258 deletions

View File

@ -1,11 +1,11 @@
#!/bin/bash
version=0.5.0
version=0.6.0
date="08/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues"
script="getInfo"
urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/getInfo"
urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/$script"
urlNotice=""
##### license LPRAB/WTFPL
@ -23,7 +23,7 @@ f__affichage(){
RED="$(printf "\033[0;31m")" # alerte
COLOR="$(printf "\033[0m")" # standard
# clear
clear
printf "$BLUE"
cat << 'EOF'
_ ___ __
@ -36,11 +36,32 @@ EOF
echo -e "$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(){
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
}
# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur
f__error() {
echo -e "\n$RED Erreur critique: $1 $COLOR"
for (( i=2 ; i<=$# ; i++ )); do echo -e " $BLUE${!i}"; done
echo "$COLOR"
if [ "$opType" == "upgrade" ]; then f__log "$script $version: $1"; fi
exit 1
}
@ -50,24 +71,15 @@ f__info() {
echo "$COLOR"
}
# detect system architecture, assign $architecture : i386 | x86_64, return 1 on unknown architecture
# remarque, debian: dpkg --print-architecture affiche i386
f__architecture(){
case "$(uname -m)" in
amd64 | x86_64 )
architecture="x86_64";;
i?86 | x86 )
architecture="i686";;
* )
case "$(getconf LONG_BIT)" in
64 )
architecture="x86_64";;
32 )
architecture="i686";;
*)
return 1
esac ;;
esac
# log spécifique, fichier log limité à 10000octets, $1 message à loguer
f__log(){
if [ -w "$fileLogs" ]; then
if [ "$(stat -c %s $fileLogs)" -ge "10000" ]; then
echo "$(date +%Y%m%d\ %H%M%S) $1" &>/dev/null > "$fileLogs"
else
echo "$(date +%Y%m%d\ %H%M%S) $1" &>/dev/null >> "$fileLogs"
fi
fi
}
# test dépendances (commandes disponibles), $1 liste commandes ou $1...$x, si manquant, avertissement des paquets manquants
@ -83,94 +95,169 @@ f__requis(){
"apt install $dependsFail"
}
fi_start(){
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"
# root? return 0 else 1
f__root(){
[ $EUID -eq "0" ] && return 0 || return 1
}
trim_quotes() { # thanks neofetch
trim_output="${1//\'}"
trim_output="${trim_output//\"}"
printf "%s" "$trim_output"
}
get_de() { # thanks neofetch, assigne $de
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_distro() { # thanks neofetch, assigne $distro
[[ "$distro" ]] && return
case "$os" in
"Linux" | "GNU")
if type -p lsb_release >/dev/null; then
case "$distro_shorthand" in
"on") lsb_flags="-sir" ;;
"tiny") lsb_flags="-si" ;;
*) lsb_flags="-sd" ;;
esac
distro="$(lsb_release $lsb_flags)"
elif type -p guix >/dev/null; then
distro="GuixSD"
elif type -p crux >/dev/null; then
distro="$(crux)"
case "$distro_shorthand" in
"on") distro="${distro//version}" ;;
"tiny") distro="${distro//version*}" ;;
esac
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
# Format the distro name.
case "$distro_shorthand" in
"on") distro="${NAME:-${DISTRIB_ID}} ${VERSION_ID:-${DISTRIB_RELEASE}}" ;;
"tiny") distro="${NAME:-${DISTRIB_ID:-${TAILS_PRODUCT_NAME}}}" ;;
"off") distro="${PRETTY_NAME:-${DISTRIB_DESCRIPTION}} ${UBUNTU_CODENAME}" ;;
esac
# 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)"
fi
# for debian, add version
grep -qi 'Debian' /etc/issue && distro="$(sed 's/"//g' <<< $distro) $(cat /etc/debian_version)"
distro="$(trim_quotes "$distro")"
;;
esac
[[ -z "$distro" ]] && distro="$os (Unknown)"
}
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)"
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")"
# user ayant initié la session graphique, assigne $user_, testé avec mate, gnome, xfce. manque KDE
# sortie script sur erreur, gestion variable environnement pour personnaliser l'user avec:
# USER_INSTALL=user script
f__user(){
[ "$USER_INSTALL" ] && user_="$USER_INSTALL" # user_ via variable en environnement
if [ -z "$user_" ]; then # priorité à $USER_INSTALL
[ "$SUDO_UID" ] && user_id="$SUDO_UID" # sudo-gnome
echo "$XAUTHORITY" | grep -Eo '[0-9]+' && user_id="$(echo $XAUTHORITY | grep -Eo '[0-9]+')" || \
user_id="$(echo $XDG_RUNTIME_DIR | grep -Eo '[0-9]+')"
[ "$user_id" ] && user_="$(grep $user_id /etc/passwd | cut -d ":" -f 1 )" || \
user_="$(echo $XAUTHORITY | cut -d "/" -f 3)"
fi
[ "$user_" ] && [ -d "/home/$user_" ] && return 0 || echo " répertoire '/home/$user_' INEXISTANT"
f__error " user indéterminé, lancer le script avec:\n USER_INSTALL=user $0" \
"merci contacter $projet $contact pour corriger ça"
}
# test wget, $1 url à tester, sortie script sur erreur
f__wget_test(){
echo " $1"
wget -Sq --tries=1 --timeout=15 --user-agent="$user_agent" -O /dev/null "$1"
f__error "Erreur wget" " réessayer et si persistance, contacter $projet $contact" " en indiquant les messages précédents."
}
# install du script dans le système
fscript_install(){
f__root || f__error "vous devez être ROOT pour installer ce script dans le système"
# install /opt
mkdir -p /opt/bin/
cp -d "$(basename $0)" "/opt/bin/$script"
chmod a+rwx "/opt/bin/$script"
chown "$user_": "/opt/bin/$script"
ln -s "/opt/bin/$script" "/usr/bin/$script" &>/dev/null
# cron/anacron install
fscript_cronAnacron "install"
# création fichier log
touch "$fileLogs"
chmod a+rwx "$fileLogs"
chown "$user_": "$fileLogs"
[ -f "$script"_changelog.md ] || rm "$(basename $0)" &>/dev/null ## on efface pas si changelog (dev)
f__info "$GREEN$script installé dans le système." "maintenant, appel du script par:$GREEN $script$BLUE (sans ./)"
f__log "$script $version installé dans le système"
}
# suppression du script dans le système
fscript_remove(){
f__root || f__error "vous devez être ROOT pour supprimer ce script dans le système"
# suppression de /opt
rm /opt/bin/"$script" &>/dev/null
unlink /usr/bin/"$script" &>/dev/null
unlink /usr/local/bin/"$script" &>/dev/null # ancienne localisation
# cron/anacron remove
fscript_cronAnacron remove
f__info "$GREEN$script supprimé du système."
f__log "$script $version supprimé du système"
}
# version script en ligne, assigne $versionScript, $script_aJour=ok|ko
fscript_get_version(){
versionScript="$(wget -q --tries=2 --timeout=15 --user-agent="$user_agent" -O - "$urlScript" | grep '^version=' | cut -d '=' -f 2)"
if [ "$version" != "$versionScript" ]; then
f__info "version script en ligne: $versionScript, mise à jour possible"
script_aJour="ko"
else script_aJour="ok"; fi
}
# mise à jour script si dispo
fscript_dl(){
if [ "$script_aJour" == "ok" ]; then return 0; fi
local dirTemp="/tmp/$script-$RANDOM/"
mkdir -p "$dirTemp"
opType="upgrade"
wget -q --show-progress --tries=2 --timeout=15 --user-agent="$user_agent" -O "$dirTemp$script" "$urlScript"
if [ "$?" != "0" ]; then f__wget_test "$urlScript"; fi
chmod a+rwx "$dirTemp$script"
chown "$user_": "$dirTemp$script"
cp -d "$dirTemp$script" /opt/bin/"$script"
rm -rf "$dirTemp"
f__info "\n $script mis à jour en version $versionScript"
f__log "$script mis à jour en version $versionScript"
exit 0
}
# inscription dans tache upgrade en anacron hebdomadaire, via cron horaire
fscript_cronAnacron(){
local dirAnacron="/home/$user_/.config/anatest"
local dirSpool="$dirAnacron/spool"
local fileAnacron="$dirAnacron/$script.anacrontab"
case "$1" in
install )
mkdir -p "$dirAnacron"
# table anacron
echo "1 05 $script nice /opt/bin/$script --upgrade &>/dev/null" > "$fileAnacron"
## test: anacron journalier: echo "1 05 ""$script""test nice /opt/bin/$script --upgrade &>/dev/null" > "$fileAnacron"
chown -R --no-preserve-root "$user_": "$dirAnacron"
chmod -R --no-preserve-root ug+xw "$dirAnacron"
# création spool anacron utilisateur
mkdir -p "$dirSpool"
chown -R --no-preserve-root "$user_": "$dirSpool"
chmod -R --no-preserve-root ug+xw "$dirSpool"
# cron tab pour activation horaire anacron
grep -q ".*$script.anacrontab" /etc/crontab || \
echo "@hourly $user_ /usr/sbin/anacron -t $fileAnacron -S $dirSpool" >> /etc/crontab
;;
remove )
rm "$dirSpool/$script"* &>/dev/null
sed -i "/$script.anacrontab/d" /etc/crontab
rm "$fileAnacron" &>/dev/null
rm "$dirSpool/$script" &>/dev/null
rmdir "$dirSpool" "$dirAnacron" &>/dev/null
;;
esac
}
# 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
}
# $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
fi
shopt -u nocasematch
}
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")"
# 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"
}
get_cpu() { # thanks neofetch, assigne $cpu
@ -216,56 +303,20 @@ get_cpu() { # thanks neofetch, assigne $cpu
cpu="${cpu/@/(${cores})(${coresT}) @}"
}
get_gpu() { # thanks neofetch, assigne $gpu
gpu="$(PATH="/sbin:$PATH" lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}')"
case "$gpu" in
*"advanced"*)
gpu="${gpu//Intel*$'\n'}"
gpu="${gpu/'[AMD/ATI]' }"
gpu="${gpu/'[AMD]' }"
gpu="${gpu/OEM }"
gpu="${gpu/ \/ *}"
gpu="${gpu/*\[}"
gpu="${gpu/\]*}"
gpu="AMD $gpu"
;;
*"nvidia"*)
gpu="${gpu//Intel*$'\n'}"
gpu="${gpu/*\[}"
gpu="${gpu/\]*}"
gpu="NVIDIA $gpu"
;;
*"virtualbox"*)
gpu="VirtualBox Graphics Adapter"
;;
get_de() { # thanks neofetch, assigne $de
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
[[ "$gpu" =~ "intel" ]] && gpu="Intel Integrated Graphics"
}
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"
}
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%,*}"
}
get_disk() { # thanks neofetch, assigne $disk
@ -283,23 +334,104 @@ get_disk() { # thanks neofetch, assigne $disk
disk="${disk_used} / ${disk_total} (${disk_total_per})"
}
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")"
# 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"
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)"
fi
# for debian, add version
grep -qi 'Debian' /etc/issue && distro="$(sed 's/"//g' <<< $distro) $(cat /etc/debian_version)"
[[ -z "$distro" ]] && distro="$os (Unknown)"
}
get_gpu() { # thanks neofetch, assigne $gpu
gpu="$(PATH="/sbin:$PATH" lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}')"
case "$gpu" in
*"advanced"*)
gpu="${gpu//Intel*$'\n'}"
gpu="${gpu/'[AMD/ATI]' }"
gpu="${gpu/'[AMD]' }"
gpu="${gpu/OEM }"
gpu="${gpu/ \/ *}"
gpu="${gpu/*\[}"
gpu="${gpu/\]*}"
gpu="AMD $gpu" ;;
*"nvidia"*)
gpu="${gpu//Intel*$'\n'}"
gpu="${gpu/*\[}"
gpu="${gpu/\]*}"
gpu="NVIDIA $gpu" ;;
*"virtualbox"*)
gpu="VirtualBox Graphics Adapter" ;;
esac
[[ "$gpu" =~ "intel" ]] && gpu="Intel Integrated Graphics"
}
get_local_ip() { # thanks neofetch, assigne $local_ip
local_ip="$(ip route get 1 | awk '{print $NF;exit}')"
}
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"
}
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"
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
}
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%,*}"
}
get_shell(){ # thanks neofetch, assigne $shell
shell="${SHELL##*/}"
case "${SHELL##*/}" in
@ -320,34 +452,73 @@ get_shell(){ # thanks neofetch, assigne $shell
esac
}
fi_systeme(){
local uname=$(uname -rmo)
#dépend de apt install lsb-release, debian standard juste : lsb-base
[ -x "/usr/bin/lsb_release" ] && local description=$(lsb_release -ds)
local uptime=$(uptime -p)
uptime=$(sed 's/days/jours/; s/hours/heures/; s/minutes/mn/' <<< $uptime)
local lastboot=$(last -R -n 1 --time-format iso reboot | head -n 1 | grep -o '[0-9:T+-]*' | sed 's/T/ /')
local bootImage=$(sed 's/root=[^ ]*//;s/[ ]\+/, /g' /proc/cmdline)
local shells=$(grep -v "^#" /etc/shells | sed 's/\/bin\///' | tr '\n' ' ')
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)"
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
}
local text="\n## système\n\n"
get_distro; text+="$distro \n"
text+="$bootImage \n"
text+="dernier boot: $lastboot, uptime: $uptime \n"
[ $description ] && text+="description: $description \n"
text+="uname: $uname \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_gpu; text+="GPU: $gpu \n"
get_memory; text+="mémoire utilisée/totale: $memory \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"
echo -e "$text" >> "$fileOutput"
# $1 fichier à exporter, $2 durée de conservation en jour; $3 debug
fi_curl_pastery(){
[ -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
}
fi_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
}
fi_help(){
printf $BLUE
cat << 'EOF'
----------------------------------------------------------------------
./getInfo : exécution normale
getInfo : exécution normale si script installé dans le système
options:
--debug, -d : affichage résultat complet de l'export paste
--help, -h : affichage aide
--list, -l : afficher le rapport existant
--paste, -p : exporte le rapport existant
--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
exemple
./getInfo construit un rapport et propose un export final
./getInfo --debug si export final, le résultat complet de l'export sera affiché
./getInfo -p -d si export du rapport existant, le résultat complet de l'export sera affiché
EOF
printf "$COLOR\n"
}
fi_paste(){
fi_curl_pastery "$fileOutput" "$dureePaste" "$option"
# à tester fi_curl_markdownshare "$fileOutput"
}
fi_reseau(){
@ -395,84 +566,102 @@ fi_reseau(){
echo -e "$text" >> "$fileOutput"
}
fi_nm_wifi_autour(){
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
}
fi_systeme(){
local bootImage=$(sed 's/root=[^ ]*//;s/[ ]\+/, /g' /proc/cmdline)
[ -x "/usr/bin/lsb_release" ] && local description=$(lsb_release -ds)
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 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)
fi_NetworkManager(){
# 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
}
fi_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"
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'
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"
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_gpu; text+="GPU: $gpu \n"
get_memory; text+="mémoire utilisée/totale: $memory \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"
text+="dernier boot: $lastboot, uptime: $uptime \n"
echo -e "$text" >> "$fileOutput"
# grep -v '^#' /etc/modules
}
fi_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
}
# $1 fichier à exporter, $2 durée de conservation en jour; $3 debug
fi_curl_pastery(){
[ -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/"
f__info "$GREEN le rapport est aussi disponible en local, fichier: $fileOutput"
[ "$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
}
# initialisation
f__affichage
f__architecture || f__error "Architecture non supportée" \
"vous pouvez contacter contacter $projet $contact pour parfaire le script"
f__requis "curl"
fileOutput="getInfo_rapport.md"
fileLogs="/var/log/sdeb_$script.log"
dureePaste=1
fi_start
fi_systeme
fi_reseau
fi_modules "net"
fi_main1(){ # début
f__requis "curl"
fi__context
f__user
}
fi_main2(){ # traitements principaux
os=$(uname -s)
hote=$(uname -n)
dateRapport=$(date +"%d %b %Y %H:%M %z")
#cat $fileOutput
fi_curl_pastery "$fileOutput" 1
echo -e "# getInfo $version sur $hote / $os \n" > "$fileOutput"
echo -e "Rapport au $dateRapport" >> "$fileOutput"
fi_systeme
fi_reseau
get_modules "net"
}
fi_main3(){ # 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"
}
# a tester fi_curl_markdownshare "$fileOutput"
echo
for i in $@; do
case $i in
--debug )
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 )
f__log="tests mise à jour"
fscript_get_version
fscript_dl ;; # upgrade script si maj possible
$0 ) if [ $# -eq 0 ];then
fi_main1
fi_main2
fi_main3
fi ;; # programme
--help | -h | * ) fi_help ;; # affichage help
esac
done
printf $COLOR
exit
{
"raw":"https://markdownshare.com/raw/b837c09d-d5ec-4d0b-afb8-a01efe31f350",
{ "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",