From 3152e7f9f66517145ef37be3d6e614d79debbad4 Mon Sep 17 00:00:00 2001 From: kyodev Date: Fri, 18 Aug 2017 13:58:33 +0200 Subject: [PATCH] 0.7.2 --- scripts/getIp | 63 ++++++++++++++++++++--------------------- scripts/getIp_changelog | 9 ++++-- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/scripts/getIp b/scripts/getIp index f0a0e1f..3480f87 100755 --- a/scripts/getIp +++ b/scripts/getIp @@ -1,11 +1,12 @@ #!/bin/bash -version=0.7.1 -date="17/08/2017" +version=0.7.2 +date="18/08/2017" projet="simpledeb" contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues" script="getIp" urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/$script" +lognameDev="kyodev" ##### license LPRAB/WTFPL # auteur: simpledeb @@ -69,7 +70,7 @@ f__user(){ # v17/08/2017-4 } # inscription dans tache upgrade en anacron hebdomadaire, via cron horaire -fscript_cronAnacron(){ # v17/08/2017 +fscript_cronAnacron(){ # v18/08/2017 local dirAnacron="/home/$user_/.config/anacron" local dirSpool="$dirAnacron/spool" local fileAnacron="$dirAnacron/$script.anacrontab" @@ -79,7 +80,8 @@ fscript_cronAnacron(){ # v17/08/2017 mkdir -p "$dirAnacron" # table anacron echo "7 01 $script nice /opt/bin/$script --upgrade" > "$fileAnacron" - ## test: anacron journalier: echo "1 01 $script test nice /opt/bin/$script --upgrade 2>/dev/null" >> "$fileAnacron" + ## dev: anacron journalier: + [ "$LOGNAME" == "$lognameDev" ] && echo "1 01 $script test nice /opt/bin/$script --upgrade 1>/dev/null" >> "$fileAnacron" # création spool anacron utilisateur mkdir -p "$dirSpool" chown -R "$user_": "$dirAnacron" "$dirSpool" @@ -115,7 +117,6 @@ fscript_dl(){ # v17/08/2017 fscript_cronAnacron "upgrade" f__info "\n $script mis à jour en version $versionScript" f__log "$script mis à jour en version $versionScript" - $0 upgrade # spécifique getFlash, script mis à jour, on relance le script en upgrade pour le plugin exit 0 } @@ -172,11 +173,11 @@ fscript_remove(){ # v08/2017 f__log "$script $version supprimé du système" } -fi_help(){ +f_help(){ f__info "\n $GREEN $script $version$BLUE" cat << 'EOF' ---------------------------------------------------------------------- - ./getIo : exécution normale + ./getIp : exécution normale getIp : exécution normale si script installé dans le système ce script requiert une des commandes suivantes pour déterminer l'ip publique : @@ -197,15 +198,16 @@ EOF } get_ip() { # $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type, $ifname, $ifname_type - ip_local=$(ip route | awk '/proto.*src/ {print $9, "pour",$3}') - gateway=$(ip route | awk '/default.*via/ {print $3, "pour", $5}') - gateway_one=$(head -n 1 <<< $gateway | awk '{print $1}') - ifname=$(ip route | awk '/proto.*src/ {print $3}') - gateway_type=$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.µ)/\1 (ethernet)/' <<< $gateway) - ip_local_type=$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local) - ifname_type=$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname) + ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print $4,"(",$2,")"}')" + ip_local_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)" + 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}')" + ifname="$(ip -4 route | awk '/proto kernel/ {print $3}')" + ifname_type="$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname)" } + get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public list_ip4(){ @@ -220,7 +222,6 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public ip_test+=" api.infoip.io/ip" # http & https ip_test+=" api.ipify.org" # http & https ip_test+=" ipinfo.io/ip" # http & https - # ip_test+=" https://4.ifcfg.me" #down avec wget! } list_ip6(){ ip_test+=" http://ipv6.whatismyip.akamai.com" @@ -232,8 +233,6 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public ip_test+=" wgetip.com" # http & https ip_test+=" https://canhazip.com" ip_test+=" https://tnx.nl/ip" - # ip_test+=" http://smart-ip.net/myip" #down avec wget?! - # ip_test+=" https://6.ifcfg.me" #down avec wget?! } list_ip4_dig(){ dig_test+=" whoami.akamai.net/@ns1-1.akamaitech.net" @@ -262,7 +261,7 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public if which dig &>/dev/null && [ -z "$ip_public" ]; then for ii in $dig_test ; do - ip_public=$(dig +short $(sed 's;/; ;g' <<< $ii)) + ip_public="$(dig +short $(sed 's;/; ;g' <<< $ii))" [ "$ip_public" ] && break done fi @@ -270,7 +269,7 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public if which wget &>/dev/null && [ -z "$ip_public" ]; then cmd="wget --quiet --tries=1 --timeout=5 -O - " for ii in $ip_test ; do - ip_public=$($cmd $ii) + ip_public="$($cmd $ii)" [ "$ip_public" ] && break done fi @@ -278,21 +277,21 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public if which curl &>/dev/null && [ -z "$ip_public" ]; then cmd="curl --silent --location --retry 0 --max-time 5" #--location pour aider redirections for ii in $ip_test ; do - ip_public=$($cmd $ii) + ip_public="$($cmd $ii)" [ "$ip_public" ] && break done fi if which telnet &>/dev/null && [ -z "$ip_public" ]; then - ip_public=$(telnet $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4) + ip_public="$(telnet $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4)" fi if which nc &>/dev/null && [ -z "$ip_public" ] && [ "$1" != "IPv6" ]; then - ip_public=$(nc $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4) + ip_public="$(nc $ip_telnet 23 2>/dev/null | grep $1 | cut -d ' ' -f 4)" fi if [ -z "$ip_public" ]; then - f__info "il manque une des commandes suivantes:\n" \ + 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" \ @@ -314,27 +313,27 @@ fileLogs="/var/log/sdeb_$script.log" options="$@" for i in "$options"; do case $i in - --install | -i ) f__user && fscript_install ;; # installation du script dans le système - --remove | -r ) f__user && fscript_remove ;; # suppression du script dans le système - --upgrade | -u ) + --install | -i ) f__user && fscript_install ;; # installation du script dans le système + --remove | -r ) f__user && fscript_remove ;; # suppression du script dans le système + --upgrade | -u ) opType="upgrade" f__user || f__error "user indéterminé ou home inexistant" fscript_get_version fscript_dl ;; # upgrade script si maj possible - --ip4 | -4 ) + --ip4 | -4 ) get_ip_public "IPv4" echo "$ip_public" ;; # affiche ip v4 public - --ip6 | -6 ) + --ip6 | -6 ) get_ip_public "IPv6" echo "$ip_public" ;; # affiche ip v6 public --local | "" ) get_ip - echo "ip $ip_local" - echo "passerelle $gateway" ;; # affiche ips locales et passerelles - --version | -v ) + echo -e "\tip locale(s):\n$ip_local_type" + echo -e "\tpasserelle(s):\n$gateway_type" ;; # affiche ip locales + --version | -v ) f__info "$GREEN""version script en cours: $version" fscript_get_version ;; # version du script, en ligne et exécuté - --help | -h | * ) fi_help ;; # affichage help + --help | -h | * ) f_help ;; # affichage help esac done diff --git a/scripts/getIp_changelog b/scripts/getIp_changelog index da171e1..ca45bf1 100644 --- a/scripts/getIp_changelog +++ b/scripts/getIp_changelog @@ -1,11 +1,16 @@ # changelog getIp -## 0.7.1 17/08/2017 +## 0.7.2 18/08/2017 + +* maj fscript_cronAnacron pour dev +* révision ip locales + +## 0.7.1 17/08/2017 * test inscription crontab pour recherche bug siduction * test crontab et modif anacrontab lors upgrade -## 0.6.0 16/08/2017 +## 0.6.0 16/08/2017 * révision et homogénéisation des fonctions de script * lancement cron restart (bien que inutile?) à l'installation et à la suppression du script