allow no script, refactor systemd service
[vpn-setup] / client-cert-helper
index a1708134bd1eaf59e7bb481f1fb831fc664280d2..d5bdcdce2aee363eaaf9dc2f19647873c95a7d5b 100755 (executable)
@@ -6,11 +6,18 @@ set -eE -o pipefail
 rm -f /tmp/vpn-mk-client-cert.log
 exec 2>/tmp/vpn-mk-client-cert.log
 
+
+if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
+shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?. PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
+
+date >&2
+set -x
+
 name=$1
 common_name=$2
 
-echo common_name=$common_name >&2
-
 server_dir=/etc/openvpn
 if [[ -e /etc/openvpn/server ]]; then
   server_dir=/etc/openvpn/server
@@ -35,7 +42,7 @@ fi
 ### end section roughly copied from vpn-server-setup
 
 if [[ ! -e $cafile ]]; then
-  echo: error no cafile found at $cafile >/tmp/errors
+  echo error: no cafile found at $cafile >&2
   exit 1
 fi