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
2018-08-21 14:09:39 -04:00

46 lines
1.8 KiB
Django/Jinja
Executable file

#!/bin/bash -x
# Small daemon to identify this machine to the OpenVPN server
HANDLE=
UUID=
if [ -f /etc/iiab/openvpn_handle ]; then
# Option #1: Source directly from /etc/iiab/local_vars.yml in future?
# Option #2
HANDLE=`cat /etc/iiab/openvpn_handle`
# Sourcing a variable from ~4 different places is a recipe for total confusion
# (or worse!) Far better to make variable openvpn_handle and file
# /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...)
# CLARIF: "systemctl restart openvpn@xscenet" still runs even if the above is
# defied. e.g. if an implementer deletes /etc/iiab/openvpn_handle by accident.
#else
# # Option #3: Dangerous to invoke hypothetical variables :(
# source /etc/iiab/iiab.env
# # Option #4: CAUSED FAILURES IN AUGUST 2018, invoking stale variable from /etc/iiab/iiab.ini, but safer now that relegated to #4 ?
# if [ -z "$HANDLE" ]; then
# HANDLE=`cat /etc/iiab/iiab.ini | gawk \
# '{ if((toupper($1) == "HANDLE") && ($2 == "=")) { print $3;}}'`
# fi
fi
HANDLE=${HANDLE// /_}
if [ -f /etc/iiab/uuid ]; then
UUID=`cat /etc/iiab/uuid`
fi
SERVER=/usr/bin/ncat
ID=`printf "HANDLE = %s|UUID = %s" $HANDLE $UUID`
# August 2018: Removal of trailing slash tested on Raspbian, Ubuntu 18.04 & Ubuntu 16.04
#ID=`printf "HANDLE = %s|UUID = %s|" $HANDLE $UUID`
# Start the daemon which will serve the handle on demand
{% if is_debuntu %}
$SERVER -l -k -p1705 --exec "/bin/echo $ID" &
{% else %}
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)\"" &
{% endif %}