getInfo 2.53.0

This commit is contained in:
kyodev 2017-12-02 18:24:34 +01:00
parent 2a0fce4b6d
commit d4ee75cf63
2 changed files with 98 additions and 71 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
version=2.52.0
version=2.53.0
date="02/12/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
@ -195,40 +195,41 @@ f__sudo(){ # 22/10/2017
# return 1 sur échec identification user, return 2 sur absence home/
# gestion variable environnement user avec: USER_INSTALL=<user> script
f__user(){ # 2/12/2017
local user_id test root_login
local user userid test root_login
root_login="$(grep ':0:' /etc/passwd | cut -d':' -f1)" || root_login="root"
if [ "$USER_INSTALL" ]; then # user_ via variable environnement, moyen d'injecter root
user_="$USER_INSTALL";
if [ "$USER_INSTALL" ]; then # user via variable environnement, moyen d'injecter root
user="$USER_INSTALL";
return 0
elif [[ "$TERM" =~ linux ]]; then #debian 9 recovery ou nomodeset TERM=linux
if [ "$USER" ]; then
user_="$USER"
user="$USER"
elif [ "$EUID" -eq 0 ]; then
user_="$root_login"
user="$root_login"
return 0
fi
fi
if [ "$SUDO_UID" ]; then
user_id="$SUDO_UID";
userid="$SUDO_UID";
elif grep -qEo '[0-9]+' <<< "$XDG_RUNTIME_DIR" ; then
user_id="$(grep -Eo '[0-9]+' <<< $XDG_RUNTIME_DIR | cut -d'/' -f4)"
userid="$(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)"
userid="$(grep -Eo '[0-9]+' <<< $XAUTHORITY | cut -d'/' -f4)"
fi
[ "$user_id" ] && user_="$(grep $user_id /etc/passwd | cut -d ":" -f 1 )"
if [ "$user_" ] && [ "$user_" != "$root_login" ]; then
[ "$userid" ] && user="$(grep $userid /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";
user="$SUDO_USER";
elif grep -qv 'root' <<< "$(who)"; then
user_="$(grep -v 'root' <<< $(who) | head -n1 | cut -d ' ' -f1)"; # grep -v 'root' <<< $(who) | gawk 'FNR==1{print $1}'
user="$(grep -v 'root' <<< $(who) | head -n1 | cut -d ' ' -f1)"; # grep -v 'root' <<< $(who) | gawk 'FNR==1{print $1}'
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)"; # grep 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | gawk 'FNR==1{print $2}
user="$(grep 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | head -n1 | cut -d' ' -f2)"; # grep 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | gawk 'FNR==1{print $2}
fi
fi
if [ -z "$user_" ]; then return 1; fi
if [ ! -d "/home/$user_" ]; then return 2; fi
fu_user="$user"
if [ -z "$fu_user" ]; then return 1; fi
if [ ! -d "/home/$fu_user" ]; then return 2; fi
return 0
}
@ -450,16 +451,16 @@ f_dspl_scandir(){ # 21/10/2017
echo -e "$text" >> "$fileOutput" # flush fonction
}
# $1=liste fichier(s) à grepper, [$2]: largeur 1ère colonne &| nofile &| novide &| ligneVide
# si aucun fichier dans la liste retour: 'nofile|vide|inexistant
# si novide pas d'indication vide
# si 'notitre' pas d'énumération de fichier greppé (destiné à un seul fichier)
# si 'noinexist' pas de titre si fichier inexistant
# si lignevide, pas de suppression des lignes vides
# si date, date de modification du fichier
# $1=liste fichier(s) à grepper, [$2]: largeur 1ère colonne &| nofile &| novide &| ligneVide &| date
# si aucun fichier dans la liste retour: 'nofile|vide|inexistant'
# option 'novide' pas d'indication vide
# option 'notitre' pas d'énumération de fichier greppé (destiné à un seul fichier)
# option 'noinexist' pas de titre si fichier inexistant
# option 'lignevide', pas de suppression des lignes vides
# option 'date', date de modification du fichier
# ex. cumul option: "10 novide nofile lignevide"
# cmd de base: grep -Ersv '^#|^$' file|dossier
f_grep_file(){ # 27/11/2017
f_grep_file(){ # 27/11/2017
local file content display
for file in $1; do
# contenu
@ -533,6 +534,15 @@ toDisplay=(
echo -e "$STD\n plus d'infos: $GREEN$urlNotice\n$STD"
}
# f_pr "1|1|2|l1|l2|l3|titre1|titre2|hl|quote|flush" "texte" "[CONDITION test]"
# $1:
# 1|2|3 indentation, liste à puce
# l1|l2|l3 indentation, avec espaces
# titre1|titre2|titre3
# quote|hl|flush
# $2 texte à afficher
# $3 test éventuel, CONDITION ok pour afficher
# flush (f_pr flush) inutile si f_d(x) final
# $1 type, $2 texte, [$3] test /!\ assigne la variable parent $text
f_pr(){ # 01/12/2017
local preline='' line='' endline=" \n"
@ -640,7 +650,7 @@ fi_batt(){ # 1/12/2017
f_di sans "fg_batt"
}
# $1=silent (pas d'affichage), assigne $fe_nb_bluez, $fe_cards_bluez
# [$1=silent] (pas d'affichage), assigne $fe_nb_bluez, $fe_cards_bluez
fi_bluez(){ # 1/12/2017
local bluez cmd_bluez cmt_bluez mod cmd_mod cmt_mod srch_mod pluriel text
local alert_na
@ -678,8 +688,8 @@ fi_bluez(){ # 1/12/2017
f_di var "srch_mod" "" "* recherche parmi:"
}
fi_conf(){ # 1/12/2017
local confs file toScrut=(
fi_conf(){ # 2/12/2017
local confs toScrut=(
/etc/sysctl.conf
'/etc/sysctl.d/*.conf'
'/etc/hostname' # debian
@ -840,7 +850,7 @@ fi_disk(){ # 1/12/2017
f_dspl_alrt "alert_uuidResume" "alert"
}
fi_dmesg(){ # 1/12/2017
fi_dmesg(){ # 2/12/2017
local dmesg_err dmesg_warn dmesg_crit file info_ucode alert_firmBug text nb_lignes=25
local alert_firmBug
@ -853,7 +863,7 @@ fi_dmesg(){ # 1/12/2017
dmesg -Hk --nopager -l warn > $file-warn ; \
dmesg -Hk --nopager -l info | grep -i 'microcode: .*updated early' > $file-ucode ; \
dmesg -Hk --nopager | grep -i 'Firmware Bug' > $file-firmBug ; \
chown $user_: $file-*"
chown $fu_user: $file-*"
if [ "$?" != "0" ]; then
f__info "\n les commandes$GREEN dmesg$RED ont échoué $BLUE(droits root requis, échec authentification?)" \
"vous pouvez relancer le script complet$RED en root$BLUE pour voir les erreurs du noyau via dmesg" \
@ -904,7 +914,7 @@ fi_efi(){ # 1/12/2017
f_di cmd "efiboot" "efibootmgr -v" "config EFI boot"
}
# assigne $fg_gpu (liste des gpu), $fe_nb_gpu, fe_Xorg
# assigne $fg_gpu (liste des gpu), $fe_nb_gpu, fe_Xorg, si [$1=silent|xorgOnly], sortie après configs xorg complete
fi_gpu(){ # 2/12/2017
local cards cmd_cards prefixCmd openGl pluriel text
local stck_glxinfo glx_dvc cmd_glx_dvc stck_glxinfoOpt stck_glxinfoDri glx_dvc_temp
@ -931,8 +941,29 @@ fi_gpu(){ # 2/12/2017
[ "$( grep 'XWAYLAND' <<< $xScreens )" ] && fe_Xorg+=" {Xwayland}"
fi
[ "$1" == "silent" ] && return
[ "$1" == "silent" ] && return 0
[ "$fe_nb_gpu" -eq 0 ] && return 0 # pas de gpu, rien à voir
###
# config Xorg
local toScrut confs ifile fileConfs cmd_confs cmt_confs
toScrut=(
'/etc/X11/xorg.conf '
'/etc/X11/xorg.conf.d/*.conf'
)
[ "$1" == "xorgOnly" ] && toScrut=( "${toScrut[@]}" "/usr/share/X11/xorg.conf.d/*" )
for ifile in ${toScrut[*]}; do
[ -e "$ifile" ] && fileConfs+="$ifile "
done
[ "$fileConfs" ] && fileConfs="Aucun fichier trouvé"
confs=$( f_grep_file "${toScrut[*]}" "" )
cmd_confs="grep -Ersv '^#|^$' $fileConfs"
cmt_confs="configuration Xorg"
info_config="les configurations par défaut de Xorg se trouve dans **/usr/share/X11/xorg.conf.d/**, "
info_config+="non sorties ici pour cause de place."
if [ "$1" == "xorgOnly" ]; then
f_di cmd "confs" "$cmd_confs" "$cmt_confs"
return 0
fi
###
# lspci
cmd_cards="lspci -nnv -s $(gawk '/VGA |Display |3D / {print $1}' <<< $( lspci ))"
@ -1020,18 +1051,7 @@ fi_gpu(){ # 2/12/2017
srch_modVid=${fg_modMotif//|/ } # fg_modMotif motif de recherche, avec |
# fonctions externes
[ "$fg_resolution" ] || figet_screen
local conf file
toScrut=(
/etc/sysctl.conf
'/etc/X11/xorg.conf '
'/etc/X11/xorg.conf.d/*.conf'
'/usr/share/X11/xorg.conf.d/'
)
confs=$( f_grep_file "${toScrut[*]}" "noinexist" )
###
###
f_pr titre2 "graphisme"
f_pr l "$( sed -E 's/(.*)/**\1** /' <<< $fg_gpu )" # mise en gras
f_pr
@ -1059,6 +1079,9 @@ fi_gpu(){ # 2/12/2017
f_di var "srch_modGpu" "" "* recherche parmi:"
f_di cmd "modVid" "$cmd_modVid" "$cmt_modVid"
f_di var "srch_modVid" "" "* recherche parmi:"
# Xorg config
f_di cmd "confs" "$cmd_confs" "$cmt_confs"
f_dspl_alrt "info_config" "info"
}
# $1="[opt|dri]", assigne $openGl, sous fonction de fi_gpu
@ -1098,7 +1121,7 @@ fi_hw(){ # 1/12/2017
f_pr flush
}
fi_journal(){ # 1/12/2017
fi_journal(){ # 2/12/2017
local jctl_boot jctl_alert_k jctl_crit_k jctl_err_k jctl_warn_k jctl_warn_nok jctl_last jctl_size file
local info_ucode text nb_lignes=25
local alert_jctl_persist alert_firmBug
@ -1119,7 +1142,7 @@ fi_journal(){ # 1/12/2017
LC_ALL=C journalctl --disk-usage > $file-size ; \
LC_ALL=C journalctl --no-pager --no-hostname -o short-monotonic --boot 0 -k -p6 | grep -i 'microcode: .*updated early' > $file-ucode ; \
[ $( type -p dmesg 2>/dev/null ) ] && dmesg -Hk --nopager | grep -i 'Firmware Bug' > $file-firmBug ; \
chown $user_: $file-*"
chown $fu_user: $file-*"
if [ "$?" != "0" ]; then
f__info "\n les commandes$GREEN journalctl$RED ont échoué $BLUE(droits root requis, échec authentification?)" \
"vous pouvez relancer le script complet$RED en root$BLUE pour voir les erreurs des journaux" \
@ -1254,14 +1277,14 @@ fi_locale(){ # 1/12/2017
f_di cmd "xKeyboardMap" "setxkbmap -query"
}
fi_log_xorg(){ # 1/12/2017
fi_log_xorg(){ # 2/12/2017
local toScrut xfile xfileTest="" logXorg cmd_logXorg="" cmt_logXorg extract dateFile text nb_lignes=50
local info_logs
[[ "$ENV_SSH" || "$ENV_DISPLAY" ]] && return 0
toScrut=(
/var/log/Xorg.0.log
/home/$user_/.local/share/xorg/Xorg.0.log
/home/$fu_user/.local/share/xorg/Xorg.0.log
/var/lib/gdm3/.local/share/xorg/Xorg.0.log
)
# checkpoint
@ -1994,7 +2017,7 @@ fi_system(){ # 2/12/2017
f_pr flush
}
fi_system_analyse(){ #v 1/12/2017
fi_system_analyse(){ #v 2/12/2017
[ $( f__which systemd ) ] || return 0 # pas systemd
local bootTime cmd_bootTime cmt_bootTime pluriel text
local srvcFail cmd_srvcFail cmt_srvcFail qte_srvcFail isrvc srvcFail_list info_services
@ -2047,7 +2070,7 @@ fi_system_analyse(){ #v 1/12/2017
touch "$file" 2>/dev/null
[ -w "$file" ] || file="/tmp/getInfo-graph-$RANDOM.svg"
systemd-analyze plot > "$file" 2>/dev/null
chown $user_: "$file"
chown $fu_user: "$file"
bootGraph="en console: **xdg-open $file** \n"
bootGraph+="* dans un navigateur: copier/coller ce lien dans la barre d'adresses "
bootGraph+="file:///$file \n" # résultat avec 4 /, ok
@ -3504,10 +3527,10 @@ fipaste_curl_markdownshare(){ # à tester/finir
}
# inscription dans tache upgrade en anacron hebdomadaire, via cron horaire, $1=upgrade|install|remove
fscript_cronAnacron(){ # 06/11/2017
fscript_cronAnacron(){ # 2/12/2017
local dirAnacron dirSpool fileAnacron
[ "$(type -t fscript_cronAnacron_special)" ] && fscript_cronAnacron_special # test, si fonction spécifique, appel
dirAnacron="/home/$user_/.config/anacron"
dirAnacron="/home/$fu_user/.config/anacron"
dirSpool="$dirAnacron/spool"
fileAnacron="$dirAnacron/$script.anacrontab"
[ "$EUID" -eq 0 ] && sed -i "/$script.anacrontab/d" /etc/crontab
@ -3522,10 +3545,10 @@ fscript_cronAnacron(){ # 06/11/2017
fi
# création spool anacron utilisateur
mkdir -p "$dirSpool"
chown -R "$user_:" "$dirAnacron" "$dirSpool"
chown -R "$fu_user:" "$dirAnacron" "$dirSpool"
if [ "$EUID" -eq 0 ]; then
# crontab pour activation horaire anacron
echo "@hourly $user_ /usr/sbin/anacron -t $fileAnacron -S $dirSpool" >> /etc/crontab
echo "@hourly $fu_user /usr/sbin/anacron -t $fileAnacron -S $dirSpool" >> /etc/crontab
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"
@ -3558,7 +3581,7 @@ fscript_get_version(){ # 06/11/2017
}
# installation du script dans le système
fscript_install(){ # 10/11/2017
fscript_install(){ # 2/12/2017
if grep -q 'bin' <<< "$(dirname $0)" ; then
f__info "$RED""l'installation dans le système doit se faire depuis un script local $GREEN(./$script -i )"
return 1
@ -3574,13 +3597,13 @@ fscript_install(){ # 10/11/2017
mkdir -p /opt/bin/
cp -d "$(basename $0)" "$fileInstall"
ln -s "$fileInstall" "/usr/bin/$script" &>/dev/null
chmod 775 "$fileInstall" # rwx rwx r-x, proprio user_
chmod 775 "$fileInstall" # rwx rwx r-x, proprio fu_user
# cron/anacron install
fscript_cronAnacron "install"
# création fichier log
touch "$fileLogs"
chmod 664 "$fileLogs" # rw- rw- r--, proprio user_
chown "$user_:" "$fileLogs" "$fileInstall"
chmod 664 "$fileLogs" # rw- rw- r--, proprio fu_user
chown "$fu_user:" "$fileLogs" "$fileInstall"
[ -e "$fileDev" ] || rm "$(basename $0)" &>/dev/null ## on efface pas si fileDev (dev)
f__info "log" "$script $version installé dans le système." "maintenant, appel du script par: $GREEN$script$BLUE (sans ./)"
}
@ -3610,7 +3633,7 @@ fscript_remove(){ # 06/11/2017
}
# mise à jour script si dispo, v2, +update spécifique
fscript_update(){ # 06/11/2017
fscript_update(){ # 2/11/2017
local dirTemp="/tmp/$script-$RANDOM"
[ $(type -t fscript_update_special) ] && fscript_update_special # test, si fonction spécifique, appel
if [ -z "$updateSpecial" ] && ! grep -q 'bin' <<< "$(dirname $0)" ; then
@ -3627,8 +3650,8 @@ fscript_update(){ # 06/11/2017
if [ "$?" != "0" ]; then f__wget_test "$urlScript"; fi
if grep -q '#!/bin/bash' "$dirTemp/$script" ; then
cp -d "$dirTemp/$script" "$fileInstall"
chmod 775 "$fileInstall" # rwx rwx r-x, proprio user_
chown "$user_:" "$fileInstall"
chmod 775 "$fileInstall" # rwx rwx r-x, proprio fu_user
chown "$fu_user:" "$fileInstall"
[ -z "$updateSpecial" ] && fscript_cronAnacron "upgrade"
f__info "log" "$script mis à jour en version $versionScript $updateSpecial"
else
@ -3638,7 +3661,7 @@ fscript_update(){ # 06/11/2017
rm -rf "$dirTemp/"
}
prg_init(){ # 01/12/2017
prg_init(){ # 2/12/2017
PATH='/usr/sbin:/usr/bin:/sbin:/bin'
TERM=xterm
IFS_INI="$IFS"
@ -3684,7 +3707,7 @@ prg_init(){ # 01/12/2017
[ "$retourFUser" -eq 1 ] && f__error "user indéterminé" \
"pour contourner, lancer le script avec:\n$GREEN USER_INSTALL=<user> $0 \n"
if [ "$retourFUser" -eq 2 ]; then
[ "$EUID" -eq 0 ] && user_="root" || f__error "user détecté, mais pas de home: /home/$user_"
[ "$EUID" -eq 0 ] && fu_user="root" || f__error "user détecté, mais pas de home: /home/$fu_user"
f__info "user root"
fi
@ -3694,15 +3717,15 @@ prg_init(){ # 01/12/2017
# detect rapide systeme deb pour f_requis debOnly, en attendant mieux
[ $( f__which dpkg ) ] && ENV_DEBIAN="oui"
}
prg_1(){ # début
prg_1(){ # début 2/12/2017
echo > "$fileOutput"
chown $user_: "$fileOutput" &>/dev/null
chown $fu_user: "$fileOutput" &>/dev/null
chmod 666 "$fileOutput" &>/dev/null # rw-rw-rw-, si root permet écriture & effacement à tous
echo -e "* **$script** sur *$(uname -n)* \n" > "$fileOutput"
echo -e "$ligneRapport \n" >> "$fileOutput"
echo -e "--- \n" >> "$fileOutput"
}
prg_2(){ # traitements principaux 21/11/2017
prg_2(){ # traitements principaux 1/12/2017
if [[ "$1" == all || "$1" =~ s ]]; then #systeme, matériel -cs
echo -e "# ▷ Système" >> "$fileOutput"
for i in fi_system fi_cpu fi_mem fi_hw fi_batt fi_gpu fi_net fi_audio fi_bluez fi_usb fi_disk ; do
@ -3831,7 +3854,6 @@ for j in $options; do
prg_1 "$*"
echo -n "•"
fi_gpu
fi_system
echo; f_dspl_md "$fileOutput"
exit ;; # test
-c* | all )
@ -3841,6 +3863,11 @@ for j in $options; do
prg_2 "$j"
prg_3
exit ;; # rapport complet ou par catégorie
-dx )
prg_1 "$*"
fi_gpu "xorgOnly"
f_dspl_md "$fileOutput"
exit ;; # essai détail, xorgOnly
-j )
prg_1 "$*"
prg_2 "a"

View File

@ -1,18 +1,18 @@
# changelog getInfo
* f__wcv, f_display_grep, f_dspl_md, f__wget_test, fscript_get_version, fscript_update
* ! f__requis (debOnly), f__architecture, fscript_install, f__scandir
## 2.53.0 02/12/2017
* révision: fi_dmeg, fi_journal, fu_user, fi_system_analyse, fscript_cronAnacron,
fscript_install, fscript_update : renommage variable publique fu_user
* révision: fi_gpu, confs particulières Xorg
## 2.52.0 02/12/2017
* nouveau: figet_wm, ajout compositors
* révision: fi_gpu, recherche server Worg
* révision: fi_gpu, recherche server Xorg
* révision: fi_system (serverX)
* révision: f__architecture, renommage variable publique
* révision:
* révision:
## 2.51.2 01/12/2017