diff --git a/scripts/getIp b/scripts/getIp index bdb8630..8ac3e27 100755 --- a/scripts/getIp +++ b/scripts/getIp @@ -1,7 +1,7 @@ #!/bin/bash -version=1.19.0 -date="11/12/2017" +version=1.20.0 +date="14/12/2017" projet="simpledeb" contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/" script="getIp" @@ -36,6 +36,36 @@ f__color(){ # 08/10/2017 SOUL=$(tput smul) } + # $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 + # -lc: liste en colonne des noms de fichiers seuls + # si joker (*?) sur chemin, le motif d'exclusion ne s'applique pas à un répertoire listé, juste sur le nom du fichier + # attention, les jokers sont interprétés à l'appel de la fonction + # exemple: f__dir -l "$dir" "lock|partial" ou "\.list" +f__dir(){ # 12/12/2017 + local i=0 action="-c" stock='' + + [[ "$1" =~ - ]] && action="$1" || action="-c" # si option en erreur: -c + while read -r ; do + if [[ ! "$REPLY" =~ $3 ]] || [ -z "$3" ]; then + REPLY=${REPLY#*:} # suppression du titre de répertoire listé + [ -z "$REPLY" ] && continue # ligne vide, on passe + ((i++)) + stock+="$REPLY " +#echo "$REPLY $i" + fi + done <<< $( ls $2 2>/dev/null ) + if [ "$action" == "-c" ]; then + echo "$i" + elif [ "$action" == "-l" ]; then + echo ${stock% } + elif [ "$action" == "-lc" ]; then + stock=${stock% } + echo -e "${stock// /$'\n'}" + fi +} + # affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si $opType=upgrade f__error(){ # 4/12/2017 local depart=1 i @@ -326,10 +356,26 @@ f_pr(){ # 10/12/2017 fi } - # assigne $fg_ip, $fg_gws6, $fg_ifn, $fg_mac -figet_ip(){ #v 11/12/2017 + # $1=-4|-6|-46 protocole +fi_ip_pub(){ #v 14/12/2017 + local itest option="$1" + + option=${option//46/4 6} + for itest in $option; do + itest=-${itest//-} + if figet_ip_pub "$itest" ; then + echo "$BOLD$fg_ip_pub$STD" + else + echo "pas de connectivité ipv${itest#-}" + fi + done +} + + # $1=-4|-6, assigne $fg_ip, $fg_gws6, $fg_ifn, $fg_mac +figet_ip(){ # 14/12/2017 local target ifn + x_ip=1 [ $( f__which ip ) ] || return 1 [ "$1" ] && proto="$1" || proto="-4" # adresses ip @@ -367,7 +413,7 @@ figet_ip(){ #v 11/12/2017 fi # ifnames & mac fg_ifn="" fg_mac="" - for ifn in $( ls /sys/class/net/ ) ; do + for ifn in $( f__dir -l /sys/class/net/ ) ; do if [ "$ifn" != "lo" ]; then fg_ifn+="$ifn " fg_mac+="$ifn: $( cat /sys/class/net/$ifn/address )"$'\n' @@ -378,10 +424,10 @@ figet_ip(){ #v 11/12/2017 } # $1=-4|-6, assigne $fg_ip_pub -figet_ip_pub(){ #v 11/12/2017 +figet_ip_pub(){ #v 14/12/2017 local dig_test ip_test iip - list_ip4(){ # testé 12/2017 + list_ip4(){ # testé 11/12/2017 ip_test=( # pas de https http://whatismyip.akamai.com @@ -396,7 +442,8 @@ figet_ip_pub(){ #v 11/12/2017 ) } - list_ip4_dig(){ # testé 12/2017 + list_ip4_dig(){ # testé 11/12/2017 + dig_test=( whoami.akamai.net/@ns1-1.akamaitech.net myip.opendns.com/@resolver1.opendns.com @@ -406,7 +453,8 @@ figet_ip_pub(){ #v 11/12/2017 ) } - list_ip6(){ # testé 12/2017 + list_ip6(){ # testé 11/12/2017 + ip_test=( http://ipv6.whatismyip.akamai.com ip.tyk.nu # http & https @@ -420,13 +468,15 @@ figet_ip_pub(){ #v 11/12/2017 ) } - list_ip6_dig(){ # testé 12/2017 + list_ip6_dig(){ # testé 11/12/2017 + dig_test=( -6/myip.opendns.com/aaaa/@resolver1.ipv6-sandbox.opendns.com -6/myip.opendns.com/aaaa/@resolver2.ipv6-sandbox.opendns.com ) } + x_ip_pub=1 option="$1" unset fg_ip_pub # assignation variables @@ -648,21 +698,6 @@ print_local(){ #v 11/12/2017 echo -en "$text\n" #>> "$fileOutput" } - # $1=-4|-6|-46 -print_public(){ #v 11/12/2017 - local itest option="$1" - - option=${option//46/4 6} - for itest in $option; do - itest=-${itest//-} - if figet_ip_pub "$itest" ; then - echo "$fg_ip_pub" - else - echo "pas de connectivité ipv${itest#-}" - fi - done -} - testuser(){ # 4/12/2017 f__user retourFUser="$?" @@ -731,13 +766,13 @@ fi for j in "$options"; do case $j in -4 | --ip4 ) - print_public "-4" + fi_ip_pub "-4" ;; # affiche ip v4 public -6 | --ip6 ) - print_public "-6" + fi_ip_pub "-6" ;; # affiche ip v6 public -46 | --public ) - print_public "-46" + fi_ip_pub "-46" ;; # ip v4 & v6 "" | --local ) print_local diff --git a/scripts/getIp_changelog.md b/scripts/getIp_changelog.md index 89ed962..351f03a 100644 --- a/scripts/getIp_changelog.md +++ b/scripts/getIp_changelog.md @@ -1,6 +1,11 @@ # changelog getIp +## getIp 1.20.0 14/12/2017 + +* révision: figer_ip + f__dir +* syncro getInfo + ## getIp 1.19.0 11/12/2017 * révision: figet_ip_pub