Browse Source

Change echo to printf for better sh compatibility

pull/9/head
Julien Escario 3 years ago
parent
commit
2b8ad027e3
  1. 40
      monitoring/altinea_monitoring_request.sh

40
monitoring/altinea_monitoring_request.sh

@ -11,7 +11,7 @@ DEBUG() {
VPNIF="vpnaltinea" VPNIF="vpnaltinea"
if ! [ -x "$(command -v jq)" ]; then if ! [ -x "$(command -v jq)" ]; then
echo "jq could not be found, I'll install it for you"
printf "%s" "jq could not be found, I'll install it for you\n"
apt install -y jq apt install -y jq
fi fi
@ -33,13 +33,13 @@ if [ $(hostname -I |grep -c $EXTIP4) -ne 0 ]; then
IP4=$EXTIP4 IP4=$EXTIP4
else else
# Let see if we can find an ip address on the configured VPN interface # Let see if we can find an ip address on the configured VPN interface
DEBUG echo "Couldn't find a public IPv4 address on this host"
DEBUG echo "Let see if we find a $VPNIF wireguard interface"
DEBUG printf "Couldn't find a public IPv4 address on this host\n"
DEBUG printf "Let see if we find a $VPNIF wireguard interface\n"
VPNIP4=`ip -j addr show dev $VPNIF | jq -r '.[0].addr_info | map(select(.family == "inet"))[0].local'` VPNIP4=`ip -j addr show dev $VPNIF | jq -r '.[0].addr_info | map(select(.family == "inet"))[0].local'`
if [ -z "$VPNIP4" ]; then if [ -z "$VPNIP4" ]; then
DEBUG echo "Can't find an IPv4 address on $VPNIF interface"
DEBUG printf "%s" "Can't find an IPv4 address on $VPNIF interface\n"
else else
DEBUG echo "Found VPN IPv4 : $VPNIP4. Using it for monitoring purposes"
DEBUG printf "%s" "Found VPN IPv4 : $VPNIP4. Using it for monitoring purposes\n"
IP4=$VPNIP4 IP4=$VPNIP4
fi fi
fi fi
@ -48,33 +48,28 @@ fi
if [ $(hostname -I |grep -c $EXTIP6) -ne 0 ]; then if [ $(hostname -I |grep -c $EXTIP6) -ne 0 ]; then
IP6=$EXTIP6 IP6=$EXTIP6
else else
DEBUG echo "Couldn't find a public IPv6 address on this host"
DEBUG echo "Let see if we find an IPv6 on $VPNIF interface"
DEBUG printf "%s" "Couldn't find a public IPv6 address on this host\n"
DEBUG printf "%s" "Let see if we find an IPv6 on $VPNIF interface\n"
VPNIP6=`ip -j addr show dev $VPNIF | jq -r '.[0].addr_info | map(select(.family == "inet6"))[0].local'` VPNIP6=`ip -j addr show dev $VPNIF | jq -r '.[0].addr_info | map(select(.family == "inet6"))[0].local'`
if [ -z "$VPNIP6" ]; then if [ -z "$VPNIP6" ]; then
DEBUG echo "Can't find an IPv6 address on $VPNIF interface"
DEBUG printf "%s" "Can't find an IPv6 address on $VPNIF interface"
else else
DEBUG echo "Found VPN IPv6 : $VPNIP6. Using it for monitoring purposes"
DEBUG printf "%s" "Found VPN IPv6 : $VPNIP6. Using it for monitoring purposes"
IP6=$VPNIP6 IP6=$VPNIP6
fi fi
fi fi
#RANDOMNB=`date +%S | grep -o .$ | sed s/0/10/`
#ARTURL="https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ascii/$RANDOMNB.txt"
#ASCIIART=`curl -s $ARTURL`
ASCIIART=""
printf "Password for sendmail@it-nea.eu: "
printf "%s" "Password for sendmail@it-nea.eu: "
stty -echo stty -echo
IFS= read -r mailpassword
read -r mailpassword
stty echo stty echo
printf "\n" printf "\n"
AUTHLOGIN=`echo -ne "\0sendmail@it-nea.eu\0$mailpassword"|base64`
AUTHLOGIN=`printf "\0sendmail@it-nea.eu\0$mailpassword"|base64`
# Generate first part on the command # Generate first part on the command
echo "ehlo `hostname -f`
printf "%s" "ehlo `hostname -f`
AUTH PLAIN AUTH PLAIN
$AUTHLOGIN $AUTHLOGIN
MAIL FROM: noc@altinea.fr MAIL FROM: noc@altinea.fr
@ -85,13 +80,12 @@ To: support@altinea.fr
Subject: Nouvelle demande de monitoring Subject: Nouvelle demande de monitoring
Content-Type: text/plain; charset=UTF-8 Content-Type: text/plain; charset=UTF-8
Nouvelle IP à monitorer : `hostname -f`\r
IPv4 : $IP4\r
IPv6 : $IP6\r
Nouvelle IP à monitorer : `hostname -f`
IPv4 : $IP4
IPv6 : $IP6
$ASCIIART
. .
quit quit
" |openssl s_client -connect smtp.it-nea.eu:465 -quiet -verify_quiet > /dev/null || err_exit
" |openssl s_client -connect smtp.it-nea.eu:465 -verify_quiet -quiet > /dev/null || err_exit
exit 1; exit 1;
Loading…
Cancel
Save