mirror of https://framagit.org/kyodev/kyopages.git
0.7.2
This commit is contained in:
parent
3ef893d8dd
commit
3152e7f9f6
|
@ -1,11 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
version=0.7.1
|
version=0.7.2
|
||||||
date="17/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"
|
||||||
script="getIp"
|
script="getIp"
|
||||||
urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/$script"
|
urlScript="https://framagit.org/kyodev/kyopages/raw/master/scripts/$script"
|
||||||
|
lognameDev="kyodev"
|
||||||
|
|
||||||
##### license LPRAB/WTFPL
|
##### license LPRAB/WTFPL
|
||||||
# auteur: simpledeb
|
# auteur: simpledeb
|
||||||
|
@ -69,7 +70,7 @@ f__user(){ # v17/08/2017-4
|
||||||
}
|
}
|
||||||
|
|
||||||
# inscription dans tache upgrade en anacron hebdomadaire, via cron horaire
|
# 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 dirAnacron="/home/$user_/.config/anacron"
|
||||||
local dirSpool="$dirAnacron/spool"
|
local dirSpool="$dirAnacron/spool"
|
||||||
local fileAnacron="$dirAnacron/$script.anacrontab"
|
local fileAnacron="$dirAnacron/$script.anacrontab"
|
||||||
|
@ -79,7 +80,8 @@ fscript_cronAnacron(){ # v17/08/2017
|
||||||
mkdir -p "$dirAnacron"
|
mkdir -p "$dirAnacron"
|
||||||
# table anacron
|
# table anacron
|
||||||
echo "7 01 $script nice /opt/bin/$script --upgrade" > "$fileAnacron"
|
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
|
# création spool anacron utilisateur
|
||||||
mkdir -p "$dirSpool"
|
mkdir -p "$dirSpool"
|
||||||
chown -R "$user_": "$dirAnacron" "$dirSpool"
|
chown -R "$user_": "$dirAnacron" "$dirSpool"
|
||||||
|
@ -115,7 +117,6 @@ fscript_dl(){ # v17/08/2017
|
||||||
fscript_cronAnacron "upgrade"
|
fscript_cronAnacron "upgrade"
|
||||||
f__info "\n $script mis à jour en version $versionScript"
|
f__info "\n $script mis à jour en version $versionScript"
|
||||||
f__log "$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
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,11 +173,11 @@ fscript_remove(){ # v08/2017
|
||||||
f__log "$script $version supprimé du système"
|
f__log "$script $version supprimé du système"
|
||||||
}
|
}
|
||||||
|
|
||||||
fi_help(){
|
f_help(){
|
||||||
f__info "\n $GREEN $script $version$BLUE"
|
f__info "\n $GREEN $script $version$BLUE"
|
||||||
cat << 'EOF'
|
cat << 'EOF'
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
./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 :
|
||||||
|
@ -197,15 +198,16 @@ 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
|
||||||
ip_local=$(ip route | awk '/proto.*src/ {print $9, "pour",$3}')
|
ip_local="$(sed '/lo.*inet/d; /inet6.*scope global/d' <<< "$(ip -o a)" | awk '{print $4,"(",$2,")"}')"
|
||||||
gateway=$(ip route | awk '/default.*via/ {print $3, "pour", $5}')
|
ip_local_type="$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)"
|
||||||
gateway_one=$(head -n 1 <<< $gateway | awk '{print $1}')
|
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,")"}')"
|
||||||
ifname=$(ip route | awk '/proto.*src/ {print $3}')
|
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}')"
|
||||||
ip_local_type=$(sed -E 's/(^.*wl.*)/\1 (wifi)/;s/(^.*en.*|^.*eth.*)/\1 (ethernet)/' <<< $ip_local)
|
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)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public
|
get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public
|
||||||
|
|
||||||
list_ip4(){
|
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.infoip.io/ip" # http & https
|
||||||
ip_test+=" api.ipify.org" # http & https
|
ip_test+=" api.ipify.org" # http & https
|
||||||
ip_test+=" ipinfo.io/ip" # http & https
|
ip_test+=" ipinfo.io/ip" # http & https
|
||||||
# ip_test+=" https://4.ifcfg.me" #down avec wget!
|
|
||||||
}
|
}
|
||||||
list_ip6(){
|
list_ip6(){
|
||||||
ip_test+=" http://ipv6.whatismyip.akamai.com"
|
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+=" wgetip.com" # http & https
|
||||||
ip_test+=" https://canhazip.com"
|
ip_test+=" https://canhazip.com"
|
||||||
ip_test+=" https://tnx.nl/ip"
|
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(){
|
list_ip4_dig(){
|
||||||
dig_test+=" whoami.akamai.net/@ns1-1.akamaitech.net"
|
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
|
if which dig &>/dev/null && [ -z "$ip_public" ]; then
|
||||||
for ii in $dig_test ; do
|
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
|
[ "$ip_public" ] && break
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
@ -270,7 +269,7 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public
|
||||||
if which wget &>/dev/null && [ -z "$ip_public" ]; then
|
if which wget &>/dev/null && [ -z "$ip_public" ]; then
|
||||||
cmd="wget --quiet --tries=1 --timeout=5 -O - "
|
cmd="wget --quiet --tries=1 --timeout=5 -O - "
|
||||||
for ii in $ip_test ; do
|
for ii in $ip_test ; do
|
||||||
ip_public=$($cmd $ii)
|
ip_public="$($cmd $ii)"
|
||||||
[ "$ip_public" ] && break
|
[ "$ip_public" ] && break
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
@ -278,21 +277,21 @@ get_ip_public(){ # $1=IPv4|IPv6, assigne $ip_public
|
||||||
if which curl &>/dev/null && [ -z "$ip_public" ]; then
|
if which curl &>/dev/null && [ -z "$ip_public" ]; then
|
||||||
cmd="curl --silent --location --retry 0 --max-time 5" #--location pour aider redirections
|
cmd="curl --silent --location --retry 0 --max-time 5" #--location pour aider redirections
|
||||||
for ii in $ip_test ; do
|
for ii in $ip_test ; do
|
||||||
ip_public=$($cmd $ii)
|
ip_public="$($cmd $ii)"
|
||||||
[ "$ip_public" ] && break
|
[ "$ip_public" ] && break
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if which telnet &>/dev/null && [ -z "$ip_public" ]; then
|
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
|
fi
|
||||||
|
|
||||||
if which nc &>/dev/null && [ -z "$ip_public" ] && [ "$1" != "IPv6" ]; then
|
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
|
fi
|
||||||
|
|
||||||
if [ -z "$ip_public" ]; then
|
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" \
|
"dig / wget / curl / telnet / nc \n" \
|
||||||
"ou les ip de test sont devenues défaillantes\n" \
|
"ou les ip de test sont devenues défaillantes\n" \
|
||||||
"réessayer après avoir installé dig (dnsutils) et wget\n" \
|
"réessayer après avoir installé dig (dnsutils) et wget\n" \
|
||||||
|
@ -314,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
|
||||||
echo "ip $ip_local"
|
echo -e "\tip locale(s):\n$ip_local_type"
|
||||||
echo "passerelle $gateway" ;; # affiche ips locales et passerelles
|
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 | * ) fi_help ;; # affichage help
|
--help | -h | * ) f_help ;; # affichage help
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
# changelog getIp
|
# 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 inscription crontab pour recherche bug siduction
|
||||||
* test crontab et modif anacrontab lors upgrade
|
* 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
|
* révision et homogénéisation des fonctions de script
|
||||||
* lancement cron restart (bien que inutile?) à l'installation et à la suppression du script
|
* lancement cron restart (bien que inutile?) à l'installation et à la suppression du script
|
||||||
|
|
Loading…
Reference in New Issue