1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 19:52:06 +00:00
iiab/roles/openvpn/templates/announcer.j2

48 lines
1.9 KiB
Text
Raw Normal View History

2017-05-27 18:09:50 +00:00
#!/bin/bash -x
2018-08-14 09:34:15 +00:00
# Small daemon to identify this machine to the OpenVPN server
2017-05-27 18:09:50 +00:00
HANDLE=
UUID=
2018-08-14 00:29:05 +00:00
if [ -f /etc/iiab/openvpn_handle ]; then
2018-08-21 18:01:15 +00:00
# Option #1: Source directly from /etc/iiab/local_vars.yml in future?
# Option #2
2018-08-14 00:29:05 +00:00
HANDLE=`cat /etc/iiab/openvpn_handle`
2018-08-16 03:36:03 +00:00
# Sourcing a variable from ~4 different places is a recipe for total confusion
# (or worse!) Far better to make variable openvpn_handle and file
2018-08-21 18:09:39 +00:00
# /etc/iiab/openvpn_handle "obligatory" (EMPTY STRING "" IS TOLERATED, IN WHICH
# CASE OPENVPN SERVER TRIES TO USE /etc/iiab/uuid BELOW, IN LIEU OF HANDLE...)
2018-08-16 03:36:03 +00:00
2018-09-05 15:53:38 +00:00
# CLARIF: "systemctl restart openvpn" still works tolerably even if the above
# is defied, auto-starting child service openvpn@xscenet per usual
# (e.g. if /etc/iiab/openvpn_handle is deleted by accident!)
2018-08-16 03:41:04 +00:00
2018-08-15 18:20:11 +00:00
#else
# # Option #3: Dangerous to invoke hypothetical variables :(
# source {{ iiab_env_file }}
# # Option #4: CAUSED FAILURES IN AUGUST 2018, invoking stale variable from {{ iiab_ini_file }}, but safer now that relegated to #4 ?
2018-08-15 18:20:11 +00:00
# if [ -z "$HANDLE" ]; then
# HANDLE=`cat {{ iiab_ini_file }} | gawk \
2018-08-15 18:20:11 +00:00
# '{ if((toupper($1) == "HANDLE") && ($2 == "=")) { print $3;}}'`
# fi
2017-05-27 18:09:50 +00:00
fi
2018-08-14 08:55:15 +00:00
HANDLE=${HANDLE// /_}
if [ -f /etc/iiab/uuid ]; then
UUID=`cat /etc/iiab/uuid`
2017-05-27 18:09:50 +00:00
fi
2018-08-14 08:55:15 +00:00
2017-05-27 18:09:50 +00:00
SERVER=/usr/bin/ncat
2018-08-14 08:55:15 +00:00
ID=`printf "HANDLE = %s|UUID = %s" $HANDLE $UUID`
2018-08-14 09:34:15 +00:00
# August 2018: Removal of trailing slash tested on Raspbian, Ubuntu 18.04 & Ubuntu 16.04
2018-08-14 08:55:15 +00:00
#ID=`printf "HANDLE = %s|UUID = %s|" $HANDLE $UUID`
2018-08-14 09:05:23 +00:00
2018-08-14 09:34:15 +00:00
# Start the daemon which will serve the handle on demand
2018-08-14 09:05:23 +00:00
{% if is_debuntu %}
2017-05-27 18:09:50 +00:00
$SERVER -l -k -p1705 --exec "/bin/echo $ID" &
{% else %}
2018-08-14 08:55:15 +00:00
source /etc/init.d/functions
PID_FILE=/var/run/openvpn/announce.pid
daemon --pidfile=${PID_FILE} $SERVER "-l -k -p1705 --exec \"/usr/bin/echo $ID\"" &
#daemon --pidfile=${PID_FILE} $SERVER "-l -k -p1705 --exec \"/usr/bin/echo $(printf 'HANDLE = %s|UUID = %s' $HANDLE $UUID)\"" &
2017-05-27 18:09:50 +00:00
{% endif %}