diff --git a/docs/scripts/getFirefox.md b/docs/scripts/getFirefox.md index a9c0772..b495166 100644 --- a/docs/scripts/getFirefox.md +++ b/docs/scripts/getFirefox.md @@ -109,7 +109,7 @@ getFirefox i-canal * les canaux par ordre croissant de versions: ` ESR <= release < beta = developer edition < nightly ` * le canal **all** est fictif et comprend _esr+latest+beta+nightly_ pour l'installation (pas de _dev_ donc) -* le canal **all** comprend toutes les versions installées pour les autres opérations +* le canal **all** comprend toutes les versions installées, pour les autres opérations * pour chaque canal, une option permet de **copier** un éventuel profil _.default_. le profil _.default_ existant est laissé en place. diff --git a/docs/scripts/getInfo.md b/docs/scripts/getInfo.md index 9e5e2ed..a07d6c8 100644 --- a/docs/scripts/getInfo.md +++ b/docs/scripts/getInfo.md @@ -1,6 +1,6 @@ # getInfo -![version: 4.6.0](https://img.shields.io/badge/version-4.6.0-blue.svg?longCache=true&style=for-the-badge) +![version: 4.7.0](https://img.shields.io/badge/version-4.7.0-blue.svg?longCache=true&style=for-the-badge) ![bash langage](https://img.shields.io/badge/bash-4-brightgreen.svg?longCache=true&style=for-the-badge) ![license LPRAB / WTFPL](https://img.shields.io/badge/license-LPRAB%20%2F%20WTFPL-blue.svg?longCache=true&style=for-the-badge) @@ -38,7 +38,7 @@ chmod +x getInfo / _' |/ _ \ __|| || '_ \| |_ / _ \ | (_| | __/ |_ | || | | | _| (_) | \__, |\___|\__|___|_| |_|_| \___/ - |___/ version 4.6.0 - 16/06/2018 + |___/ version 4.7.0 - 16/06/2018 •ø••••••••••••••••◇◇◇••••• @@ -145,8 +145,8 @@ chmod +x getInfo __ _ ___| |_|_ _|_ __ / _| ___ / _' |/ _ \ __|| || '_ \| |_ / _ \ | (_| | __/ |_ | || | | | _| (_) | - \__, |\___|\__|___|_| |_|_| \___/ - |___/ version 4.6.0 - 16/06/2018 + \__, |\___|\__|___|_| |_|_| \___/ -h + |___/ version 4.7.0 - 16/06/2018 ./getInfo : exécution script getInfo : exécution script installé dans le système @@ -165,6 +165,7 @@ chmod +x getInfo getInfo --ssid : affiche configurations ssid, pas de rapport markdown, root & NetworkManager requis --debug : messages d'erreur (stderr) logués et exportés avec le rapport + --dev : une version de dev du script (si existante) est recherchée -tn : durée de conservation du paste de n jour(s) ----------------------------------------------------------------------- ./getInfo -i : installation du script dans le système (root) @@ -173,7 +174,7 @@ chmod +x getInfo getInfo -r, --remove : désinstallation du script (root) getInfo --rrc : désinstallation gfetch (root) getInfo -u, --upgrade : mise à jour script - getInfo -v, --version : version du script + getInfo -v, --version : version du script, installée et en ligne ----------------------------------------------------------------------- plus d'infos: https://framaclic.org/h/doc-getinfo diff --git a/docs/scripts/getInfo_plus.md b/docs/scripts/getInfo_plus.md index ecf26b0..9c64395 100644 --- a/docs/scripts/getInfo_plus.md +++ b/docs/scripts/getInfo_plus.md @@ -13,7 +13,7 @@ de téléchargement) seront alors sous la forme `getInfo ...`. / _' |/ _ \ __|| || '_ \| |_ / _ \ | (_| | __/ |_ | || | | | _| (_) | \__, |\___|\__|___|_| |_|_| \___/ - |___/ version 4.6.0 - 16/06/2018 + |___/ version 4.7.0 - 16/06/2018 getInfo -h : afficher l'aide diff --git a/docs/scripts/getIp.md b/docs/scripts/getIp.md index 99760fd..f34fd26 100644 --- a/docs/scripts/getIp.md +++ b/docs/scripts/getIp.md @@ -1,7 +1,7 @@ # getIp -![version: 2.13.0](https://img.shields.io/badge/version-2.13.0-blue.svg?longCache=true&style=for-the-badge) +![version: 2.14.2](https://img.shields.io/badge/version-2.14.2-blue.svg?longCache=true&style=for-the-badge) ![bash langage](https://img.shields.io/badge/bash-4-brightgreen.svg?longCache=true&style=for-the-badge) ![license LPRAB / WTFPL](https://img.shields.io/badge/license-LPRAB%20%2F%20WTFPL-blue.svg?longCache=true&style=for-the-badge) diff --git a/scripts/getFirefox b/scripts/getFirefox index b89070e..47f758b 100755 --- a/scripts/getFirefox +++ b/scripts/getFirefox @@ -6,7 +6,7 @@ script="getFirefox" #contact="IRC ##sdeb@freenode.net ou https://framagit.org/sdeb/getFirefox/issues" ##### license LPRAB/WTFPL -# auteur: simpledeb +# auteur: sdeb # contributeurs: kyodev ##### diff --git a/scripts/getFlashPlayer b/scripts/getFlashPlayer index 5b8eb38..f595bf4 100755 --- a/scripts/getFlashPlayer +++ b/scripts/getFlashPlayer @@ -6,7 +6,7 @@ script="getFlashPlayer" # contact="IRC ##sdeb@freenode.net ou https://framagit.org/sdeb/getFlashPlayer/issues" ##### license LPRAB/WTFPL -# auteur: simpledeb +# auteur: sdeb # contributeurs: kyodev, coyotus, naguam ##### diff --git a/scripts/getInfo b/scripts/getInfo index 55fc4f5..fbe8827 100755 --- a/scripts/getInfo +++ b/scripts/getInfo @@ -7,7 +7,7 @@ # SC2009 Consider using pgrep instead of grepping ps output # SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting). -version=4.6.0 +version=4.7.0 date="16/06/2018" script="getInfo" contact="IRC freenode.net ##sdeb@freenode.net ou https://framagit.org/sdeb/getInfo/issues" @@ -141,6 +141,59 @@ f__dialog_oui_non(){ # 14/06/2018 fi } + # use dig or drill according to availability, options: hostname [@server|type|nostd|host], display ip | n/a (equivalent + short) + # if option --host, diplay hostname: ip + # dig has priority over dril if the two command are presents + # type : aaaa | a | txt | soa | any | mx | AAAA | A | TXT | SOA | ANY | MX + # option nostd for dig only: +timeout=1 +retry=1 +f__dig(){ # 16/06/2018 + local ini options type host server hostname dig ip domain ttl class typ ipx z + + ini=$( shopt -p nocasematch ) + if (( $# == 0 )); then + echo "f__dig: argument manquant" + return 1 + fi + shopt -s nocasematch + while (( $# )) ; do + case "$1" in + nostd ) options+=( '+timeout=1' '+retry=1' ) ;; + aaaa | a | txt | soa | any | mx ) type="$1" ;; + host ) host='yes' ;; + @* ) server=( "$1" ) ;; + * ) hostname="$1" ;; + esac + shift + done + type="${type:=A}" + if type -p dig &>/dev/null; then + dig=$( dig "${options[@]}" "$hostname" "${server[@]}" "$type" ) + elif type -p drill &>/dev/null; then + dig=$( drill "$hostname" "${server[@]}" "${type[@]}" ) + else + echo "dig or drill command unavailable" + eval "$ini" + return 1 + fi + if [[ $dig =~ answer:\ 0 ]]; then + dig='n/a' + elif [[ $dig =~ answer:\ 1 ]]; then + # shellcheck disable=SC2034 + while read -r domain ttl class typ ipx z; do + if [[ $domain$class$typ == ${hostname}\.IN$type ]]; then + ip+="$ipx " + fi + done <<< "$dig" + dig="$ip" + fi + [ "$host" ] && echo -n "$hostname: " + echo "$dig" + eval "$ini" + if [ "$dig" == "n/a" ]; then + return 1 + fi +} + # $1=-c|-l|-lc, $2 répertoire, [$3] motif exclusion sur nom fichier, affiche 0|null si répertoire inexistant # -c: compte du nombre de fichiers dans un répertoire # -l: liste inline des noms de fichiers seuls (sans chemin) (similaire ls) @@ -466,7 +519,7 @@ f_affichage(){ # 15/06/2018 __ _ ___| |_|_ _|_ __ / _| ___ / _' |/ _ \ __|| || '_ \| |_ / _ \ | (_| | __/ |_ | || | | | _| (_) | - \__, |\___|\__|___|_| |_|_| \___/ + \__, |\___|\__|___|_| |_|_| \___/ $STD$script_options |___/ ${YELLOW}version $version - $date$STD end @@ -613,7 +666,7 @@ f_grep_file(){ # 08/03/2018 echo -en "$display" } -f_help(){ # 15/06/2018 +f_help(){ # 16/06/2018 tput cuu1 # une ligne plus haut cat <<- end @@ -635,6 +688,7 @@ f_help(){ # 15/06/2018 $BLUE$script --ssid :$STD affiche configurations ssid, pas de rapport markdown,$RED root & NetworkManager$STD requis $GREEN --debug :$STD messages d'erreur (stderr) logués et exportés avec le rapport + $GREEN --dev :$STD une version de dev du script (si existante) est recherchée $GREEN -tn :$STD durée de conservation du paste de$GREEN n$STD jour(s) ----------------------------------------------------------------------- $BLUE./$script -i$STD : installation du script dans le système $RED(root)$STD @@ -643,7 +697,7 @@ f_help(){ # 15/06/2018 $BLUE$script -r$STD, --remove : désinstallation du script $RED(root)$STD $BLUE$script --rrc$STD : désinstallation gfetch $RED(root)$STD $BLUE$script -u$STD, --upgrade : mise à jour script - $BLUE$script -v$STD, --version : version du script + $BLUE$script -v$STD, --version : version du script, installée et en ligne ----------------------------------------------------------------------- plus d'infos: $GREEN$url_notice$STD @@ -651,8 +705,8 @@ f_help(){ # 15/06/2018 } # $1 [-4|-6], par défaut -4, affiche ip pub, return 1 on failure - # requiert f__cnx & f_ip_validate & f__random & f__log -f_ip_pub(){ # 16/06/2018 + # requiert f__cnx & f_ip_validate & f__random & f__log & f__dig +f_ip_pub(){ # 16/06/2018-2 local proto="-4" ip_pub base_size cmd sequence xyz server user_agent="Mozilla/5.0 Firefox" declare -a base cmds raw4 raw6 dns4 dns6 @@ -707,18 +761,18 @@ f_ip_pub(){ # 16/06/2018 [[ "$1" == '-6' || "$1" == '6' ]] && proto="-6" type -p host &>/dev/null && cmds+=( "host -R0 -W1 -t " ) # deprecated - type -p dig &>/dev/null && cmds+=( "dig +short +timeout=1 +retry=1 " ) + type -p dig &>/dev/null || type -p drill &>/dev/null && cmds+=( "f__dig nostd " ) type -p wget &>/dev/null && cmds+=( "wget --user-agent=$user_agent --quiet --timeout=1 --tries=1 -o /dev/null -O - " ) type -p curl &>/dev/null && cmds+=( "curl --silent --location --retry 0 --max-time 1 " ) if (( ${#cmds[@]} == 0 )); then - echo "f_ip_pub(): no available commands (host|dig|wget|curl)" >&2 + echo "f_ip_pub(): no available commands (host|dig|drill|wget|curl)" >&2 return fi for cmd in "${cmds[@]}"; do - if [[ "$proto" == '-4' && "$cmd" =~ ^(host|dig) ]] ; then + if [[ "$proto" == '-4' && "$cmd" =~ ^(host|f__dig) ]] ; then base=( "${dns4[@]}" ) - elif [[ "$proto" == '-6' && "$cmd" =~ ^(host|dig) ]] ; then + elif [[ "$proto" == '-6' && "$cmd" =~ ^(host|f__dig) ]] ; then base=( "${dns6[@]}" ) elif [[ "$proto" == '-4' && "$cmd" =~ ^(wget|curl) ]] ; then base=( "${raw4[@]}" ) @@ -1046,13 +1100,15 @@ fi_batt(){ # 06/03/2018 } # [$1=silent], assigne $fe_nb_bluez, $fe_cards_bluez -fi_bluez(){ # 06/03/2018 +fi_bluez(){ # 16/06/2018 local bluez cmd_bluez cmt_bluez mod cmd_mod cmt_mod pluriel text x_bluez=1 if type -p hcitool &>/dev/null ; then fe_nb_bluez=$( hcitool dev | grep -c 'hci[[:digit:]]' ) - fe_cards_bluez=$( hcitool dev | grep -Eo 'hci[0-9]+' | tr '\n' ' ' ) + fe_cards_bluez=$( hcitool dev | grep -Eo 'hci[0-9]+' ) + fe_cards_bluez=${fe_cards_bluez//$'\n'/ } + fe_cards_bluez=${fe_cards_bluez%$'\n'} else fe_nb_bluez=-99 fe_cards_bluez="n/a" @@ -1252,29 +1308,26 @@ fi_disk(){ # 13/03/2018 f_dspl_alrt "$alert_uuidResume" "alert" } -# shellcheck disable=SC2181 -# SC2181 Check exit code directly -fi_dmesg(){ # 08/03/2018 +fi_dmesg(){ # 16/06/2018 local dmesg_err dmesg_warn dmesg_crit file info_ucode alert_firmBug text nb_lignes=25 local alert_firmBug file="/tmp/$script-dmesg" [ "$EUID" -eq 0 ] || echo - f__sudo "dmesg -Hk --nopager -l emerg > $file-emerg ; \ + if ! f__sudo "dmesg -Hk --nopager -l emerg > $file-emerg ; \ dmesg -Hk --nopager -l alert > $file-alert ; \ dmesg -Hk --nopager -l crit > $file-crit ; \ dmesg -Hk --nopager -l err > $file-err ; \ 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 $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" \ - "ou juste la partie journaux avec $GREEN$DIRNAME""getInfo -j" - text+="* les commandes \`dmesg\` ont échoué, relancer avec les droits root \n\n" - echo -e "$text" >> "$file_output" - return 0 + chown $fu_user: $file-*"; 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" \ + "ou juste la partie journaux avec $GREEN$DIRNAME""getInfo -j" + text+="* les commandes \`dmesg\` ont échoué, relancer avec les droits root \n\n" + echo -e "$text" >> "$file_output" + return 0 fi dmesg_emerg=$( sed -n 1,"$nb_lignes"p $file-emerg ) dmesg_alert=$( sed -n 1,"$nb_lignes"p $file-alert ) @@ -1318,8 +1371,6 @@ fi_efi(){ # 06/03/2018 } # [$1=silent|xorgOnly], assigne $fe_gpu (liste des gpu), $fe_nb_gpu, fe_Xorg (peut être null) -# shellcheck disable=SC2086 -# SC2086 Double quote to prevent globbing and word splitting fi_gpu(){ # 08/04/2018 local toScrut confs ifile fileConfs cmd_confs cmt_confs info_config local cards cmd_cards openGl pluriel text @@ -1528,9 +1579,7 @@ fi_ip_pub(){ # 16/06/2018 SPÉCIFIQUE done } -# shellcheck disable=SC2181 -# SC2181 Check exit code directly -fi_journal(){ # 06/03/2018 +fi_journal(){ # 16/06/2018 local file options_jctl jctl_boot jctl_alert_k jctl_crit_k jctl_err_k jctl_warn_k jctl_warn_nok jctl_last jctl_size local info_ucode text nb_lignes=25 local alert_jctl_persist alert_firmBug @@ -1551,7 +1600,7 @@ fi_journal(){ # 06/03/2018 f__info "raw" "[sudo] nécessite le mot de passe utilisateur si celui peut obtenir les privilèges administrateur" f__info "à défaut de saisie valide, les journaux n'apparaîtront pas dans le rapport final" fi - f__sudo "LC_ALL=C journalctl $options_jctl --boot -1 &>$file-persistant ; \ + if ! f__sudo "LC_ALL=C journalctl $options_jctl --boot -1 &>$file-persistant ; \ LC_ALL=C journalctl --no-pager $options_jctl -b0 -k -p 1 > $file-alert ; \ LC_ALL=C journalctl --no-pager $options_jctl -b0 -k -p 2..2 > $file-crit ; \ LC_ALL=C journalctl --no-pager $options_jctl -b0 -p 3..3 > $file-err ; \ @@ -1560,14 +1609,13 @@ fi_journal(){ # 06/03/2018 LC_ALL=C journalctl --disk-usage > $file-size ; \ LC_ALL=C journalctl --no-pager $options_jctl -o short-monotonic --boot 0 -k -p6 | grep -i 'microcode: .*updated early' > $file-ucode ; \ type -p dmesg &>/dev/null && dmesg -Hk --nopager | grep -i 'Firmware Bug' > $file-firmBug ; \ - 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" \ - "ou juste la partie journaux avec $GREEN$DIRNAME""getInfo -j" - text+="* les commandes \`journalctl\` ont échoué, relancer avec les droits root \n\n" - echo -e "$text" >> "$file_output" - return 0 + chown $fu_user: $file-*"; 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" \ + "ou juste la partie journaux avec $GREEN$DIRNAME""getInfo -j" + text+="* les commandes \`journalctl\` ont échoué, relancer avec les droits root \n\n" + echo -e "$text" >> "$file_output" + return 0 fi # début des logs, extraction à partir de file-last (toujours lignes) pour début des logs jctl_boot=$( awk -F '--|,' 'FNR==1 {print $2}' $file-last ) @@ -2456,9 +2504,7 @@ fi_ssid(){ # 06/03/2018 rm "$file_output" } -# shellcheck disable=SC2010 -# SC2010 Don't use ls | grep. Use a glob ... to allow non-alphanumeric filenames. -fi_system(){ # 15/06/2018 +fi_system(){ # 16/06/2018 local mbr uname bootImage initDaemon upstart date_install lastboot uptime uptimePure loadAverage pluriel text local enum_batt nb_desktop serverX serverType local alimentation alim_total @@ -2566,7 +2612,7 @@ fi_system(){ # 15/06/2018 fi # alimentation - if ls -1 "/sys/class/power_supply/" | grep -iq '^AC' ; then + if grep -iq '/AC' <<< "$( echo /sys/class/power_supply/* )" ; then alim_total=$( grep -cs '1' /sys/class/power_supply/AC*/online ) alimentation=$( awk -v "alim_total=$alim_total" ' { alim_on=sprintf("%d", $1); if (alim_on>1) pllo="s" } @@ -2574,7 +2620,6 @@ fi_system(){ # 15/06/2018 if ( alim_total != alim_on ) print ", " alim_on " branchée" pllo; else print "" } ' /sys/class/power_supply/AC*/online ) fi - # batterie(s) enum_batt=$( grep -E '[A-Z][A-Z]' <<< "$fg_batt" ) ### @@ -3831,9 +3876,7 @@ figet_dmi(){ # 06/03/2018 } # infos température et fan via acpi, assigne $fg_hw -# shellcheck disable=SC2010 -# SC2010 Don't use ls | grep. Use a glob ... to allow non-alphanumeric filenames. -figet_hw(){ # 05/03/2018 +figet_hw(){ # 16/06/2018 local name labelF inputF labelT inputT critT hystT maxiT fan temp ihw x_hw=1 @@ -3842,11 +3885,11 @@ figet_hw(){ # 05/03/2018 return 1 fi for ihw in /sys/class/hwmon/* ; do - ihw=${ihw%\*} # fix à la rache, quand /sys/class/hwmon/* est vide, le développement du chemin ne se fait pas (vbox), reste * finale, et erreur sir ls suivants + ihw=${ihw%\*} # fix à la rache, quand /sys/class/hwmon/* est vide, le développement du chemin ne se fait pas (vbox), reste * finale, et erreur sur ls suivants name=$( cat "$ihw/name" 2>/dev/null ) name=${name:-indéfini} # indéfini si null ## TEMPÉRATURE - if ls "$ihw" | grep -Eq 'temp[0-9]+' ; then # tempX dans un nom de fichier + if grep -Eq 'temp[0-9]+' <<< "$( ls "$ihw" )" ; then # tempX dans un nom de fichier # extraction label labelT=$( cat "$ihw"/temp*_label 2>/dev/null | tr ' ' '-' | tr '\n' '/' ) # extraction températures @@ -3878,7 +3921,7 @@ figet_hw(){ # 05/03/2018 fi fi ## FAN - if ls "$ihw" | grep -Eq 'fan[0-9]+' ; then # fanX dans un nom de fichier + if grep -Eq 'fan[0-9]+' <<< "$( ls "$ihw" )" ; then # fanX dans un nom de fichier # extraction label (si existe?) labelF=$( cat "$ihw"/fan*_label 2>/dev/null | tr ' ' '-' | tr '\n' '/' ) # extraction vitesse fan @@ -3960,9 +4003,7 @@ figet_ip(){ # 06/03/2018 # $2=name: device(s) (name) -> assigne ${lspci[name]} ${lspci[nb_card]} # $2=raw: détail lspci (-nnv) -> assigne ${lspci[card]} [${lspci[prefix_gpu]}] # $2=module: (module kernel) -> assigne ${lspci[module]} ${lspci[srch_mod]} ${lspci[card]} [${lspci[prefix_gpu]}] -# shellcheck disable=SC2034 -# SC2034 foo appears unused. Verify it or export it. -figet_lspci(){ # 07/03/2018 +figet_lspci(){ # 16/06/2018 local motif field1 pci slots nb_slots pci modLspci mod_file if [ "$1" = "audio" ]; then @@ -3980,6 +4021,7 @@ figet_lspci(){ # 07/03/2018 # les devices if [ "$2" == "name" ]; then unset 'lspci[name]' + # shellcheck disable=SC2034 while read -r field1 pci; do pci=${pci%(rev *)} lspci[name]+="$pci "$'\n' @@ -4042,12 +4084,11 @@ figet_lspci(){ # 07/03/2018 # $1=mem|swap [total|notitle|nocoltitle], assigne $fg_mem # indépendant de procps, affichage plus clair que free, mais résultats identiques -# shellcheck disable=SC2034 -# SC2034 foo appears unused. Verify it or export it. -figet_mem(){ # 06/03/2018 +figet_mem(){ # 16/06/2018 local MemTotal MemFree MemAvailable Buffers Cached SReclaimable Shmem MemUsed local SwapTotal SwapFree SwapCached col a b c MemLibre + # shellcheck disable=SC2034 while read -r a b c; do [ "$a" == "MemTotal:" ] && MemTotal="$b" #echo "$a $(( ${b/kB}/1024 ))" ! partie entière ! [ "$a" == "MemAvailable:" ] && MemAvailable="$b" @@ -4715,14 +4756,14 @@ prg_init(){ # 08/04/2018 # définition couleurs f__color } -prg_1(){ # 02/12/2017 début +prg_1(){ # 16/06/2018d début echo > "$file_output" chown $fu_user: "$file_output" &>/dev/null chmod 666 "$file_output" &>/dev/null # rw-rw-rw-, si root permet écriture & effacement à tous - echo -e "* **$script** sur *$(uname -n)* \n" > "$file_output" - echo -e "$ligneRapport \n" >> "$file_output" - echo -e "--- \n" >> "$file_output" + echo -e "* **$script** sur *$( uname -n )* \\n" > "$file_output" + echo -e "$ligneRapport \\n" >> "$file_output" + echo -e "--- \\n" >> "$file_output" } prg_2(){ # 08/03/2018 traitements principaux @@ -4817,14 +4858,11 @@ function prg_menu_display { # 06/03/2018 # tests au démarrage prg_init - # logo et définition couleurs -[ "$1" != "--rc" ] && f_affichage - # paramètres script user_agent="Mozilla/5.0 Firefox" fileDev="/opt/bin/fileDev" file_output="getInfo_rapport.md" -debug_output="/tmp/$script.log" +debug_output="$script.log" script_install="/opt/bin/$script" script_logs="/var/log/sdeb_$script.log" url_script="https://framagit.org/sdeb/getInfo/raw/master/getInfo" @@ -4835,94 +4873,82 @@ spc5=$'\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0' ligneRapport="Rapport du $(date '+%d/%m/%Y %H:%M %z')$spc5◇$spc5$0 $*$spc5◇${spc5}[$script $version]($url_notice)" declare -A lspci # sortie figet_lspci +script_options="$*" + # logo +[ "$1" != "--rc" ] && f_affichage -options="$*" - -for j in $options; do # première passe options - case $j in + # options +while (( $# )) ; do + case "$1" in + -c ) options+=( "menu" ) ;; + -c* ) categorie+=${1#-c} ;; --debug-paste ) # si debug, retour json de pastery.net - optDebug="debugPaste" - ;; + optDebug="debugPaste" ;; --debug ) # enregistrement stderr dans $script.log debugScript="ok" echo > "$debug_output" chmod 666 "$debug_output" &>/dev/null exec 4>&2 # sauvegarde exec 2> "$debug_output" # redirection - echo -e "$ligneRapport \n" 1>&2 - ;; + echo -e "$ligneRapport \\n" 1>&2 ;; + --dev ) url_script=${url_script//\/master\///dev/} ;; + -t ) options+=( "$1" ) ;; -t* ) # durée de conservation standard du paste en jours - pasteDuration=$(( $( sed -En 's/-t([0-9]+)/\1/p' <<< "$j" ) )) - ;; - -i | --install | -r | --remove | --irc | --rrc ) # root requis si install ou remove script - if [ "$EUID" -ne 0 ]; then - f__info "vous devez être$RED ROOT$BLUE pour cette opération" - f__sudo "exec $0 $*" - exit - fi - ;;& + pasteDuration=$(( ${1#-t} )) + (( pasteDuration == 0 )) && pasteDuration=1 ;; + * ) options+=( "$1" ) ;; esac + shift done -options=$( sed -E 's/--debug-paste//g; s/-t[0-9]+//g; s/--debug//g' <<< "$options" | xargs ) # nettoyage options +[ "$categorie" ] && options+=( -c"$categorie" ) +(( ${#options[@]} == 0 )) && options=( all ) -[ "$options" ] || options="all" + #actions +for i in "${!options[@]}"; do + # shellcheck disable=SC2221,SC2222 + case ${options[$i]} in + -i | --install | -r | --remove | --irc | --rrc ) + if [ "$EUID" -ne 0 ]; then + f__info raw "vous devez être$RED ROOT$BLUE pour cette opération" + f__sudo "exec $0 $script_options" + exit + fi ;;& - -for k in $options; do # traitement options menu catégories - categorie+=$( sed -En 's/-c([a-z]+)/\1/p' <<< "$k" ) - options=$( sed -E 's/-c[a-z]+//' <<< "$k" | xargs ) -done -[ "$categorie" ] && options+=" -c$categorie" - -for j in $options; do # deuxième passe options, actions - case $j in -t | --test ) # test ORIGIN='test' - prg_1 "$*" - echo -n "•" + prg_1 # fi_system fi_cpu fi_mem fi_hw fi_batt fi_gpu fi_net fi_audio fi_touchpad fi_bluez fi_usb fi_disk # fi_efi fi_locale fi_conf fi_vrms fi_packagers # fi_reseau fi_nm # fi_system_analyse fi_journal_xorg fi_journal fi_system echo - if [ "$DISPLAY" ]; then f_prnt_md "$file_output"; else pager "$file_output"; fi - ;; + if [ "$DISPLAY" ]; then f_prnt_md "$file_output"; else pager "$file_output"; fi ;; + -c ) exec "$0" "menu" ;; # menu catégorie -c* | all ) # rapport complet ou par catégorie - [ "$j" == "-c" ] && exec "$0" "menu" - prg_1 "$*" - j=$( sed -E 's/-c//' <<< "$j" ) - prg_2 "$j" - prg_3 - ;; + prg_1 + prg_2 "${options[$i]#-c}" + prg_3 ;; -dx ) # essai détail, xorgOnly - prg_1 "$*" + prg_1 fi_gpu "xorgOnly" - if [ "$DISPLAY" ]; then f_prnt_md "$file_output"; else pager "$file_output"; fi - exit ;; + if [ "$DISPLAY" ]; then f_prnt_md "$file_output"; else pager "$file_output"; fi ;; -dp ) # essai util source/apt confOnly - prg_1 "$*" + prg_1 fi_pkg_apt "confOnly" - if [ "$DISPLAY" ]; then f_prnt_md "$file_output"; else pager "$file_output"; fi - ;; + if [ "$DISPLAY" ]; then f_prnt_md "$file_output"; else pager "$file_output"; fi ;; -j ) # analyse, catégorie -ca - prg_1 "$*" - prg_2 "a" - ;; + prg_1 + prg_2 "a" ;; -l ) # afficher le rapport existant - if [ "$DISPLAY" ]; then f_prnt_md "$file_output"; else pager "$file_output"; fi - ;; + if [ "$DISPLAY" ]; then f_prnt_md "$file_output"; else pager "$file_output"; fi ;; -p ) # exporte le rapport existant - fipaste - ;; + fipaste ;; --ip ) # affiche ip public (ipv4&6) - fi_ip_pub - echo - ;; + fi_ip_pub ; echo ;; --mac ) # affiche adresses mac figet_ip - f__info "adresses MAC:\n$STD$BOLD$fg_mac" - ;; + f__info "adresses MAC:\n$STD$BOLD$fg_mac" ;; --rc ) # gfetch operation="rc" file_output="/tmp/getInfo.rc" @@ -4932,26 +4958,20 @@ for j in $options; do # deuxième passe options, actions f_prnt_md "$file_output" exit ;; --serial ) # affiche n° série - fi_serial - ;; + fi_serial ;; --ssid ) # affiche configurations ssid - fi_ssid - ;; + fi_ssid ;; -h ) # affichage help - f_help - ;; + f_help ;; + -i | --install ) # installation script - fscript_install - ;; + fscript_install ;; -r | --remove ) # remove script - fscript_remove - ;; + fscript_remove ;; --irc ) # install gfetch only - fscript_install_special - ;; + fscript_install_special ;; --rrc ) # remove gfetch only - fscript_remove_special - ;; + fscript_remove_special ;; -u | --upgrade ) # upgrade script operation="upgrade" # log si f__error fscript_update std # std argument obligatoire pour upgrade normal @@ -4962,9 +4982,9 @@ for j in $options; do # deuxième passe options, actions fscript_update "update en place" # redéfinition répertoire install avec celui du script exit ;; -v | --version ) # version du script, en ligne et en place - fscript_get_version - ;; - menu | * ) # affichage help + fscript_get_version ;; + + menu | * ) # affichage menu catégorie prg_1 "$*" prg_menu exit ;; @@ -4980,3 +5000,4 @@ curl -L -o getInfo https://framaclic.org/h/getinfo chmod +x getInfo && ./getInfo wget -nv -O getInfo https://framagit.org/sdeb/getInfo/raw/master/getInfo +curl -OL https://framagit.org/sdeb/getInfo/raw/master/getInfo diff --git a/scripts/getIp b/scripts/getIp index f65e322..64a11a6 100755 --- a/scripts/getIp +++ b/scripts/getIp @@ -1,10 +1,9 @@ #!/bin/bash -# shellcheck disable=SC2016,SC1117 +# shellcheck disable=SC2016 # SC2016 Expressions don't expand in single quotes -# SC1117: Backslash is literal in "\n". Prefer explicit escaping: "\\n". -version=2.13.0 +version=2.14.2 date="16/06/2018" script="getIp" # contact="IRC ##sdeb@freenode.net ou https://framagit.org/sdeb/getIp/issues" @@ -81,6 +80,59 @@ f__color(){ # 29/05/2018 fi } + # use dig or drill according to availability, options: hostname [@server|type|nostd|host], display ip | n/a (equivalent + short) + # if option --host, diplay hostname: ip + # dig has priority over dril if the two command are presents + # type : aaaa | a | txt | soa | any | mx | AAAA | A | TXT | SOA | ANY | MX + # option nostd for dig only: +timeout=1 +retry=1 +f__dig(){ # 16/06/2018 + local ini options type host server hostname dig ip domain ttl class typ ipx z + + ini=$( shopt -p nocasematch ) + if (( $# == 0 )); then + echo "f__dig: argument manquant" + return 1 + fi + shopt -s nocasematch + while (( $# )) ; do + case "$1" in + nostd ) options+=( '+timeout=1' '+retry=1' ) ;; + aaaa | a | txt | soa | any | mx ) type="$1" ;; + host ) host='yes' ;; + @* ) server=( "$1" ) ;; + * ) hostname="$1" ;; + esac + shift + done + type="${type:=A}" + if type -p dig &>/dev/null; then + dig=$( dig "${options[@]}" "$hostname" "${server[@]}" "$type" ) + elif type -p drill &>/dev/null; then + dig=$( drill "$hostname" "${server[@]}" "${type[@]}" ) + else + echo "dig or drill command unavailable" + eval "$ini" + return 1 + fi + if [[ $dig =~ answer:\ 0 ]]; then + dig='n/a' + elif [[ $dig =~ answer:\ 1 ]]; then + # shellcheck disable=SC2034 + while read -r domain ttl class typ ipx z; do + if [[ $domain$class$typ == ${hostname}\.IN$type ]]; then + ip+="$ipx " + fi + done <<< "$dig" + dig="$ip" + fi + [ "$host" ] && echo -n "$hostname: " + echo "$dig" + eval "$ini" + if [ "$dig" == "n/a" ]; then + return 1 + fi +} + # $1=-c|-l|-lc, $2 répertoire, [$3] motif exclusion sur nom fichier, affiche 0|null si répertoire inexistant # -c: compte du nombre de fichiers dans un répertoire # -l: liste inline des noms de fichiers seuls (sans chemin) (similaire ls) @@ -228,6 +280,15 @@ f__sudo(){ # 11/06/2018 fi } + # $1=NOM de la variable à trimer (variable et non $variable), [$2=left|right|all], all si vide +f__trim(){ # 07/03/2018 + local trim=${!1} + + [[ "$2" == right || "$2" == all || -z "$2" ]] && trim="${trim%${trim##*[^[:space:]]}}" # fin right + [[ "$2" == left || "$2" == all || -z "$2" ]] && trim="${trim#${trim%%[^[:space:]]*}}" # début left + eval "$1=\"$trim\"" +} + # user ayant initié la session graphique, assigne $fu_user # return 1 sur échec identification user, return 2 sur absence home/ # gestion variable environnement user avec: USER_INSTALL= script @@ -343,7 +404,8 @@ f__wget_test(){ # 07/06/2018 exit 0 } -f_affichage(){ # 15/06/2018 +# shellcheck disable=SC1117 +f_affichage(){ # 16/06/2018 (( x_logo == 1 )) && return x_logo=1 clear 2>/dev/null || tput clear 2>/dev/null @@ -363,7 +425,7 @@ f_affichage(){ # 15/06/2018 echo -e "$date$STD\n" } -f_help(){ # 15/06/2018 +f_help(){ # 16/06/2018 cat <<- end ${GREEN}./getIp :$STD exécution script @@ -377,12 +439,14 @@ f_help(){ # 15/06/2018 $BLUE$script -46$STD --public : affiche ipv4 & ipv6 public $BLUE$script ''$STD, --local : affiche adresses mac / ip privées / passerelle $BLUE$script -us$STD : upgrade spécial du script en place (sans être installé) + + $GREEN --dev :$STD une version de dev du script (si existante) est recherchée ----------------------------------------------------------------------- $BLUE./$script -i$STD : installation du script dans le système $RED(root)$STD $BLUE$script -h$STD, --help : affichage aide $BLUE$script -r$STD, --remove : désinstallation du script $RED(root)$STD $BLUE$script -u$STD, --upgrade : mise à jour script - $BLUE$script -v$STD, --version : version du script + $BLUE$script -v$STD, --version : version du script, installée et en ligne ----------------------------------------------------------------------- plus d'infos: $GREEN$url_notice$STD @@ -391,8 +455,8 @@ f_help(){ # 15/06/2018 } # $1 [-4|-6], par défaut -4, affiche ip pub, return 1 on failure - # requiert f__cnx & f_ip_validate & f__random & f__log -f_ip_pub(){ # 16/06/2018 + # requiert f__cnx & f_ip_validate & f__random & f__log & f__dig +f_ip_pub(){ # 16/06/2018-2 local proto="-4" ip_pub base_size cmd sequence xyz server user_agent="Mozilla/5.0 Firefox" declare -a base cmds raw4 raw6 dns4 dns6 @@ -447,18 +511,18 @@ f_ip_pub(){ # 16/06/2018 [[ "$1" == '-6' || "$1" == '6' ]] && proto="-6" type -p host &>/dev/null && cmds+=( "host -R0 -W1 -t " ) # deprecated - type -p dig &>/dev/null && cmds+=( "dig +short +timeout=1 +retry=1 " ) + type -p dig &>/dev/null || type -p drill &>/dev/null && cmds+=( "f__dig nostd " ) type -p wget &>/dev/null && cmds+=( "wget --user-agent=$user_agent --quiet --timeout=1 --tries=1 -o /dev/null -O - " ) type -p curl &>/dev/null && cmds+=( "curl --silent --location --retry 0 --max-time 1 " ) if (( ${#cmds[@]} == 0 )); then - echo "f_ip_pub(): no available commands (host|dig|wget|curl)" >&2 + echo "f_ip_pub(): no available commands (host|dig|drill|wget|curl)" >&2 return fi for cmd in "${cmds[@]}"; do - if [[ "$proto" == '-4' && "$cmd" =~ ^(host|dig) ]] ; then + if [[ "$proto" == '-4' && "$cmd" =~ ^(host|f__dig) ]] ; then base=( "${dns4[@]}" ) - elif [[ "$proto" == '-6' && "$cmd" =~ ^(host|dig) ]] ; then + elif [[ "$proto" == '-6' && "$cmd" =~ ^(host|f__dig) ]] ; then base=( "${dns6[@]}" ) elif [[ "$proto" == '-4' && "$cmd" =~ ^(wget|curl) ]] ; then base=( "${raw4[@]}" ) @@ -528,8 +592,8 @@ f_ip_validate(){ # 17/05/2018 # "[ \"$1\" != \"notitre\" ]" ou "[ $1 != notitre ]" (attention au manque de ") # flush (f_pr flush) inutile si f_d(x) final # $1 type, $2 texte, [$3] test /!\ assigne la variable parent $text -f_pr(){ # 09/03/2018 - local preline='' line='' endline=" \n" +f_pr(){ # 16/06/2018 + local preline='' line='' endline=" \\n" [[ "$1" == 'titre1' ]] && preline=" $GREEN" [[ "$1" == 'titre1' ]] && endline+="$STD" @@ -544,16 +608,16 @@ f_pr(){ # 09/03/2018 eval "$3" || return 0 # évaluation de la CONDITION, si erreur: sortie fi if [[ "$1" == "hl" ]]; then # - text+="\n---\n\n" + text+="\\n---\\n\\n" elif [[ "$1" ]]; then text+="$preline$line$endline" # ligne formatée else - text+="\n" # newline + text+="\\n" # newline fi } # affichage ip, local -fi_ip(){ # 09/03/2018 +fi_ip(){ # 16/06/2018 local ifn_p4 text figet_ip "-4" || f__error "iproute2 doit être installé" "il remplace net-tools qui n'est plus développé" @@ -584,7 +648,7 @@ fi_ip(){ # 09/03/2018 f_pr l2 "$fg_ip_deprec" '[ "$fg_ip_deprec" ]' f_pr '[ "$fg_ip_deprec" ]' - echo -en "$text\n" #>> "$fileOutput" + echo -en "$text\\n" #>> "$fileOutput" } # $1=-4|-6|-46 protocole, affichage ip publiques @@ -816,7 +880,7 @@ test_user(){ # 09/03/2018 f__user retourFUser="$?" [ "$retourFUser" -eq 1 ] && f__error "user indéterminé" \ - "pour contourner, lancer le script avec:\n$GREEN USER_INSTALL= $0 \n" + "pour contourner, lancer le script avec:\\n$GREEN USER_INSTALL= $0 \\n" if [ "$retourFUser" -eq 2 ]; then if [ "$EUID" -eq 0 ]; then fu_user="root" @@ -861,24 +925,33 @@ script_logs="/var/log/sdeb_$script.log" url_script="https://framagit.org/sdeb/getIp/raw/master/getIp" url_notice="https://framaclic.org/h/doc-getip" -options="$*" -[ "$options" ] || options="--local" +script_options="$*" + # options +while (( $# )) ; do + case "$1" in + --dev ) url_script=${url_script//\/master\///dev/} ;; + * ) options+=( "$1" ) ;; + esac + shift +done +(( ${#options[@]} == 0 )) && options=( --local ) # vide help (si fileDev), sinon install -for j in $options; do + #actions +for i in "${!options[@]}"; do # shellcheck disable=SC2221,SC2222 - case $j in + case ${options[$i]} in + -i | --install | -r | --remove ) + if [ "$EUID" -ne 0 ]; then + f__info raw "vous devez être$RED ROOT$BLUE pour cette opération" + f__sudo "exec $0 $script_options" + exit + fi ;;& !(--public|-4|-6|-46|-64) ) f_affichage echo ;;& - -i | --install | -r | --remove ) - if [ "$EUID" -ne 0 ]; then - f__info "vous devez être$RED ROOT$BLUE pour cette opération" - f__sudo "exec $0 $*" - exit - fi - ;;& -i | --install | -r | --remove | -u | --upgrade | -us ) test_user ;;& + -4 | --ip4 ) # affiche ip v4 public fi_ip_pub "-4" ;; -6 | --ip6 ) # affiche ip v6 public @@ -886,7 +959,8 @@ for j in $options; do -46 | -64 | --public ) # ip v4 & v6 fi_ip_pub "-46" ;; --local ) # affiche ip locales - fi_ip ;; + fi_ip ;; + -i | --install ) # installation du script dans le système fscript_install ;; -r | --remove ) # suppression du script dans le système diff --git a/scripts/getThunderbird b/scripts/getThunderbird index 47621c8..949d433 100755 --- a/scripts/getThunderbird +++ b/scripts/getThunderbird @@ -6,7 +6,7 @@ script="getThunderbird" # contact="IRC ##sdeb@freenode.net ou https://framagit.org/sdeb/getThunderbird/issues" ##### license LPRAB/WTFPL -# auteur: simpledeb +# auteur: sdeb # contributeurs: kyodev ##### diff --git a/scripts/getXfox b/scripts/getXfox index 8a28f7a..fa579ba 100755 --- a/scripts/getXfox +++ b/scripts/getXfox @@ -6,7 +6,7 @@ script="getXfox" #contact="IRC ##sdeb@freenode.net ou https://framagit.org/sdeb/getXfox/issues" ##### license LPRAB/WTFPL -# auteur: simpledeb +# auteur: sdeb # contributeurs: kyodev #####