This commit is contained in:
kyodev 2017-08-18 16:15:09 +02:00
parent 3152e7f9f6
commit dd4ccd127b
3 changed files with 16 additions and 13 deletions

View File

@ -19,7 +19,7 @@ chmod +x getIp
getIp 0.7.0 getIp 0.7.0
---------------------------------------------------------------------- ----------------------------------------------------------------------
./getIo : exécution normale ./getIp : exécution normale
getIp : exécution normale si script installé dans le système getIp : exécution normale si script installé dans le système
ce script requiert une des commandes suivantes pour déterminer l'ip publique : ce script requiert une des commandes suivantes pour déterminer l'ip publique :

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
version=0.7.2 version=0.7.3
date="18/08/2017" date="18/08/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"
@ -81,7 +81,7 @@ fscript_cronAnacron(){ # v18/08/2017
# table anacron # table anacron
echo "7 01 $script nice /opt/bin/$script --upgrade" > "$fileAnacron" echo "7 01 $script nice /opt/bin/$script --upgrade" > "$fileAnacron"
## dev: anacron journalier: ## dev: anacron journalier:
[ "$LOGNAME" == "$lognameDev" ] && echo "1 01 $script test nice /opt/bin/$script --upgrade 1>/dev/null" >> "$fileAnacron" [ "$user_" == "$lognameDev" ] && echo "1 01 $script test nice /opt/bin/$script --upgrade 1>/dev/null" >> "$fileAnacron"
# création spool anacron utilisateur # création spool anacron utilisateur
mkdir -p "$dirSpool" mkdir -p "$dirSpool"
chown -R "$user_": "$dirAnacron" "$dirSpool" chown -R "$user_": "$dirAnacron" "$dirSpool"
@ -198,6 +198,7 @@ EOF
} }
get_ip() { # $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type, $ifname, $ifname_type get_ip() { # $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_local_type, $ifname, $ifname_type
[ -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,")"}')"
@ -207,7 +208,6 @@ get_ip() { # $ip_local, $gateway, $gateway_type, $gateway_one, $ip_local, $ip_lo
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)"
} }
get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public
list_ip4(){ list_ip4(){
@ -313,27 +313,27 @@ fileLogs="/var/log/sdeb_$script.log"
options="$@" options="$@"
for i in "$options"; do for i in "$options"; do
case $i in case $i in
--install | -i ) f__user && fscript_install ;; # installation du script dans le système --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 --remove | -r ) f__user && fscript_remove ;; # suppression du script dans le système
--upgrade | -u ) --upgrade | -u )
opType="upgrade" opType="upgrade"
f__user || f__error "user indéterminé ou home inexistant" f__user || f__error "user indéterminé ou home inexistant"
fscript_get_version fscript_get_version
fscript_dl ;; # upgrade script si maj possible fscript_dl ;; # upgrade script si maj possible
--ip4 | -4 ) --ip4 | -4 )
get_ip_public "IPv4" get_ip_public "IPv4"
echo "$ip_public" ;; # affiche ip v4 public echo "$ip_public" ;; # affiche ip v4 public
--ip6 | -6 ) --ip6 | -6 )
get_ip_public "IPv6" get_ip_public "IPv6"
echo "$ip_public" ;; # affiche ip v6 public echo "$ip_public" ;; # affiche ip v6 public
--local | "" ) --local | "" )
get_ip get_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 "\tip locale(s):\n$ip_local_type"
echo -e "\tpasserelle(s):\n$gateway_type" ;; # affiche ip locales echo -e "\tpasserelle(s):\n$gateway_type" ;; # affiche ip locales
--version | -v ) --version | -v )
f__info "$GREEN""version script en cours: $version" f__info "$GREEN""version script en cours: $version"
fscript_get_version ;; # version du script, en ligne et exécuté fscript_get_version ;; # version du script, en ligne et exécuté
--help | -h | * ) f_help ;; # affichage help --help | -h | * ) f_help ;; # affichage help
esac esac
done done

View File

@ -1,9 +1,12 @@
# changelog getIp # changelog getIp
## 0.7.2 18/08/2017
## 0.7.3 18/08/2017
* maj fscript_cronAnacron pour dev * maj fscript_cronAnacron pour dev
* révision ip locales * révision ip locales
* protection absence iproute
## 0.7.1 17/08/2017 ## 0.7.1 17/08/2017