getIp 2.1.0

This commit is contained in:
kyodev 2017-12-24 19:59:50 +01:00
parent 6a2a800ced
commit 2d67a75c9e
2 changed files with 11 additions and 26 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
version=2.00.0
version=2.1.0
date="24/12/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
@ -11,18 +11,6 @@ script="getIp"
# contributeurs: kyodev
#####
# $1=commande à tester, return localisation cmd si existe, return 1 si absent avec aucun message (ala debian)
# pour un test concis genre [ "$(f__cmd_exist $cmd)" ] && echo "$cmd existe"
# utilisation `type -p` pour le test, pour une bonne portabilité
f__cmd_exist(){ # 22/10/2017
# command -v
if type -p "$1" &>/dev/null ; then
echo $(type -p $1)
else
return 1
fi
}
f__color(){ # 08/10/2017
YELLOW=$(tput setaf 3) # question
GREEN=$(tput setaf 2) # ok
@ -216,16 +204,16 @@ f__wcv(){ # 09/11/2017
[ "$1" == "-wv" ] && echo "$2" | grep -o "$3" | grep -c .
}
# test wget, $1=url à tester, sortie du script (même si url testée ok) avec affichage erreur ou ok
# test wget, $1=url à tester, $2=''|print|loc|test
# par défaut, sortie du script (même si url testée ok) avec affichage erreur ou ok
# si $2=print affiche url testée & entêtes http & location, return 0
# si $2=loc affiche seulement location, return 0
# si $2=test return 0 si ok, return 1 si KO
f__wget_test(){ # 23/12/2017
local file_test_wget="/tmp/testWget-$script" retourWget retourHttp location wget_log="/tmp/testWget_$RANDOM.log"
f__wget_test(){ # 24/12/2017
local file_test_wget="/tmp/testWget-$script" retourWget retourHttp location
wget -Sq --timeout=5 --tries=2 --user-agent="$user_agent" -o "$wget_log" --spider --save-headers "$1" &>"$file_test_wget"
wget -Sq --timeout=5 --tries=2 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget"
retourWget="$?"
rm "$wget_log"
[ "$retourWget" == 1 ] && retourWget="1: code erreur générique"
[ "$retourWget" == 2 ] && retourWget="2: parse erreur (ligne de commande?)"
[ "$retourWget" == 3 ] && retourWget="3: erreur Entrée/sortie fichier"
@ -238,7 +226,6 @@ f__wget_test(){ # 23/12/2017
location=$( grep -i 'location' $file_test_wget | xargs )
if [ "$2" == "test" ]; then
rm -f "$file_test_wget"
rm -f "$wget_log"
# spécial maintenance frama.link, pas de redirection sur page status framalink
grep -q '303' <<< $retourHttp && return 1 # 303 See Other
[ "$retourWget" == "0" ] && return 0 || return 1
@ -253,15 +240,13 @@ f__wget_test(){ # 23/12/2017
echo "$STD"
fi
if [ "$2" == "print" ] || [ "$2" == "loc" ]; then
[ "$location" ] && echo -n "$YELLOW $location" || echo -n "$YELLOW no location"
[ "$location" ] && echo -n "$YELLOW$location" || echo -n "$YELLOW""no location"
echo "$STD"
rm -f "$file_test_wget"
rm -f "$wget_log"
return 0
fi
if [ "$retourWget" != "0" ]; then
rm "$file_test_wget"
rm -f "$wget_log"
rm -f "$file_test_wget"
f__error "wget, erreur $retourWget" "$1" "$YELLOW$retourHttp" "$location"
echo -e "$RED erreur wget, $retourWget \n $1 \n $YELLOW$retourHttp \n $location$STD" # pour les diags
return 1
@ -269,8 +254,7 @@ f__wget_test(){ # 23/12/2017
if grep -q '200' <<< $retourHttp; then
echo -e "$GREEN\ntout est ok, réessayer$STD\n"
fi
rm "$file_test_wget"
rm -f "$wget_log"
rm -f "$file_test_wget"
exit 0
}

View File

@ -1,10 +1,11 @@
# changelog getIp
## getIp 2.0.0 24/12/2017
## getIp 2.1.0 24/12/2017
* syncro: nouveau composants scripts
* révision: figet_ip_pub, wget, définition logs, pour cause de bug wget? sur testing
* fix: f__wget_test, incompatible avec redirection logs
## getIp 1.20.1 15/12/2017