mirror of https://framagit.org/kyodev/kyopages.git
1.6.0
This commit is contained in:
parent
329eb52df8
commit
e9b8c12a24
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
version=1.5.1
|
version=1.6.0
|
||||||
date="01/09/2017"
|
date="03/09/2017"
|
||||||
projet="simpledeb"
|
projet="simpledeb"
|
||||||
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
|
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
|
||||||
script="getIp"
|
script="getIp"
|
||||||
|
@ -18,7 +18,7 @@ f__affichage(){ # v27/08/2017 définition couleurs
|
||||||
BLUE="$(printf "\033[0;34m")" # info
|
BLUE="$(printf "\033[0;34m")" # info
|
||||||
RED="$(printf "\033[0;31m")" # alerte
|
RED="$(printf "\033[0;31m")" # alerte
|
||||||
COLOR="$(printf "\033[0m")" # standard
|
COLOR="$(printf "\033[0m")" # standard
|
||||||
echo
|
# echo
|
||||||
}
|
}
|
||||||
|
|
||||||
# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si $opType=upgrade
|
# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si $opType=upgrade
|
||||||
|
@ -151,8 +151,8 @@ f__wget_test(){ # v31/08/2017
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
f_help(){
|
f_help(){ # v03/09/2017
|
||||||
f__info "$GREEN$script $version$BLUE"
|
f__info "\n $GREEN$script $version$BLUE"
|
||||||
cat << 'EOF'
|
cat << 'EOF'
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
./getIp : exécution normale
|
./getIp : exécution normale
|
||||||
|
@ -165,7 +165,7 @@ cat << 'EOF'
|
||||||
-h, --help : affichage aide
|
-h, --help : affichage aide
|
||||||
-4, --ip4 : affiche ipv4 public
|
-4, --ip4 : affiche ipv4 public
|
||||||
-6, --ip6 : affiche ipv6 public
|
-6, --ip6 : affiche ipv6 public
|
||||||
"", --local : affiche ip / passerelle privées
|
'', --local : affiche ip / passerelle privées
|
||||||
|
|
||||||
-i, --install : installation du script dans le système
|
-i, --install : installation du script dans le système
|
||||||
-r, --remove : suppression du script dans le système
|
-r, --remove : suppression du script dans le système
|
||||||
|
@ -175,18 +175,20 @@ EOF
|
||||||
echo "$COLOR"
|
echo "$COLOR"
|
||||||
}
|
}
|
||||||
|
|
||||||
fgi_ip() { # $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type, $ifname, $ifname_type
|
# $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type, $ifname, $ifname_type
|
||||||
|
figet_ip() { # v03/09/2017
|
||||||
[ -z "$(which ip)" ] && return 1
|
[ -z "$(which ip)" ] && return 1
|
||||||
ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print $4,"(",$2,")"}')"
|
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)"
|
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="$(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_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $gateway)"
|
||||||
gateway_one="$(head -n 1 <<< $gateway | awk '{print $1}')"
|
gateway_one="$(head -n 1 <<< $gateway | awk '{print " ",$1}')"
|
||||||
ifname="$(ip -4 route | awk '/proto kernel/ {print $3}')"
|
ifname="$(ip -4 route | awk '/proto kernel/ {print " ",$3}')"
|
||||||
ifname_type="$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname)"
|
ifname_type="$(sed -E 's/(^wl.*)/\1 (wifi)/;s/(^en.*|^eth.*)/\1 (ethernet)/' <<< $ifname)"
|
||||||
}
|
}
|
||||||
|
|
||||||
fgi_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # v18/08/2017
|
# $1=4|6, assigne $ip_public
|
||||||
|
figet_ip_public(){ # v03/09/2017
|
||||||
|
|
||||||
list_ip4(){
|
list_ip4(){
|
||||||
ip_test+=" http://whatismyip.akamai.com"
|
ip_test+=" http://whatismyip.akamai.com"
|
||||||
|
@ -226,15 +228,17 @@ fgi_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public # v18/08/2017
|
||||||
|
|
||||||
unset ip_public
|
unset ip_public
|
||||||
local dig_test ip_test
|
local dig_test ip_test
|
||||||
if [ "$1" == "IPv4" ]; then
|
if [ "$1" == "4" ]; then
|
||||||
|
ping -4 -c1 google.com &>/dev/null || ping -4 -c1 free.fr &>/dev/null || return 1 # test connectivité
|
||||||
list_ip4_dig
|
list_ip4_dig
|
||||||
list_ip4
|
list_ip4
|
||||||
ip_telnet=4.ifcfg.me
|
ip_telnet=4.ifcfg.me
|
||||||
elif [ "$1" == "IPv6" ]; then
|
elif [ "$1" == "6" ]; then
|
||||||
|
ping -6 -c1 google.com &>/dev/null || ping -6 -c1 free.fr &>/dev/null || return 1 # test connectivité
|
||||||
list_ip6_dig
|
list_ip6_dig
|
||||||
list_ip6
|
list_ip6
|
||||||
ip_telnet=6.ifcfg.me
|
ip_telnet=6.ifcfg.me
|
||||||
else return 1; fi
|
fi
|
||||||
|
|
||||||
if [ "$(which dig)" ] && [ -z "$ip_public" ]; then
|
if [ "$(which dig)" ] && [ -z "$ip_public" ]; then
|
||||||
for ii in $dig_test ; do
|
for ii in $dig_test ; do
|
||||||
|
@ -416,18 +420,24 @@ f__requis "gawk wget ip>iproute2" # requis pour fonctionnement programme
|
||||||
options="$@"
|
options="$@"
|
||||||
for i in "$options"; do
|
for i in "$options"; do
|
||||||
case $i in
|
case $i in
|
||||||
--ip4 | -4 )
|
-4 | --ip4 )
|
||||||
fgi_ip_public "IPv4"
|
if figet_ip_public "4" ; then
|
||||||
echo "$ip_public"
|
echo "$ip_public"
|
||||||
|
else
|
||||||
|
echo "pas de connectivité ipv4"
|
||||||
|
fi
|
||||||
;; # affiche ip v4 public
|
;; # affiche ip v4 public
|
||||||
--ip6 | -6 )
|
-6 | --ip6 )
|
||||||
fgi_ip_public "IPv6"
|
if figet_ip_public "6" ; then
|
||||||
echo "$ip_public"
|
echo "$ip_public"
|
||||||
|
else
|
||||||
|
echo "pas de connectivité ipv6"
|
||||||
|
fi
|
||||||
;; # affiche ip v6 public
|
;; # affiche ip v6 public
|
||||||
--local | "" )
|
'' | --local )
|
||||||
fgi_ip || f__error "iproute2 doit être installé" "il remplace net-tools qui n'est plus développé"
|
figet_ip || f__error "iproute2 doit être installé" "il remplace net-tools qui n'est plus développé"
|
||||||
echo -e "\tip locale(s):\n$ip_local_type"
|
echo -e "\n ip locale(s):\n$BLUE$ip_local_type\n$COLOR"
|
||||||
echo -e "\tpasserelle(s):\n$gateway_type"
|
echo -e " passerelle(s):\n$BLUE$gateway_type\n$COLOR"
|
||||||
;; # affiche ip locales
|
;; # affiche ip locales
|
||||||
-i | --install )
|
-i | --install )
|
||||||
testuser
|
testuser
|
||||||
|
@ -441,7 +451,7 @@ for i in "$options"; do
|
||||||
testuser
|
testuser
|
||||||
opType="upgrade"
|
opType="upgrade"
|
||||||
fscript_update || f_help
|
fscript_update || f_help
|
||||||
exit ;; # upgrade script si maj possible
|
exit ;; # upgrade script si maj possible
|
||||||
-v | --version )
|
-v | --version )
|
||||||
fscript_get_version
|
fscript_get_version
|
||||||
;; # version du script, en ligne et exécuté
|
;; # version du script, en ligne et exécuté
|
||||||
|
@ -455,4 +465,3 @@ exit 0
|
||||||
|
|
||||||
wget -O getIp https://framagit.org/kyodev/kyopages/raw/master/scripts/getIp
|
wget -O getIp https://framagit.org/kyodev/kyopages/raw/master/scripts/getIp
|
||||||
chmod +x getIp && ./getIp
|
chmod +x getIp && ./getIp
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
# changelog getIp
|
# changelog getIp
|
||||||
|
|
||||||
|
|
||||||
|
## 1.6.0 03/09/2017
|
||||||
|
|
||||||
|
* mieux: test connectivité avant recherche ip public pour éviter timeout, figet_ip_public
|
||||||
|
* révision figet_ip: 2 espaces préliminaires pour meilleure présentation
|
||||||
|
|
||||||
## 1.5.1 01/09/2017
|
## 1.5.1 01/09/2017
|
||||||
|
|
||||||
* révision mineure f__wget_test
|
* révision mineure f__wget_test
|
||||||
|
|
||||||
## 30/08/2017
|
## 1.5.0 30/08/2017
|
||||||
|
|
||||||
* révision f__requis, f__user, f__wget_test, fscript_cronAnacron
|
* révision f__requis, f__user, f__wget_test, fscript_cronAnacron
|
||||||
* révision déclaration local
|
* révision déclaration local
|
||||||
|
|
Loading…
Reference in New Issue