]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding bin/start-openfortivpn
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 22 Apr 2020 06:06:04 +0000 (08:06 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 22 Apr 2020 06:06:04 +0000 (08:06 +0200)
bin/start-openfortivpn [new file with mode: 0755]

diff --git a/bin/start-openfortivpn b/bin/start-openfortivpn
new file mode 100755 (executable)
index 0000000..8feb7d3
--- /dev/null
@@ -0,0 +1,101 @@
+#!/bin/bash
+
+set -e
+set -u
+
+BASE_NAME="$( basename ${0} )"
+MY_REAL_NAME=$( readlink -f $0 )
+BIN_DIR=$( dirname "${MY_REAL_NAME}" )
+BASE_DIR=$( dirname "${BIN_DIR}" )
+LIB_DIR="${BASE_DIR}/lib"
+CONF_DIR="${BASE_DIR}/etc"
+
+if [[ -f "${LIB_DIR}/functions.rc" ]] ; then
+    . "${LIB_DIR}/functions.rc"
+else
+    echo "Bash resource file '${LIB_DIR}/functions.rc' not found" >&2
+    exit 5
+fi
+
+RESOLV_CONF_DPX="/etc/resolv.conf.dpx"
+RESOLV_CONF_NON_DPX="/etc/resolv.conf.non-dpx"
+
+detect_color
+
+DESCRIPTION=$( cat <<-EOF
+       Starts openfortivpn and sets before a /etc/resolv.conf valid
+       inside the Pixelpark VPN, and after finishing it sets a resolv.conf,
+       which is valid outside the VPN.
+
+       It uses for this the mandatory files '${GREEN}${RESOLV_CONF_DPX}${NORMAL}' and '${GREEN}${RESOLV_CONF_NON_DPX}${NORMAL}'."
+
+       EOF
+)
+
+#------------------------------------------------------------------------------
+usage() {
+    cat <<-EOF
+       Usage: ${BASE_NAME} [Common Options]
+              ${BASE_NAME} [-h|--help]
+              ${BASE_NAME} [-V|--version]
+
+           Common Options:
+       ${STD_USAGE_MSG}
+       EOF
+
+}
+
+#------------------------------------------------------------------------------
+get_options() {
+
+    local tmp=
+    local base_dir=
+
+    set +e
+    tmp=$( getopt -o ${STD_SHORT_OPTIONS} --long ${STD_LONG_OPTIONS} -n "${BASE_NAME}" -- "$@" )
+    if [[ $? != 0 ]] ; then
+        echo "" >&2
+        usage >&2
+        exit 1
+    fi
+    set -e
+
+    # Note the quotes around `$TEMP': they are essential!
+    eval set -- "${tmp}"
+    eval_common_options "$@"
+    if [[ "${DEBUG}" == 'y' ]] ; then
+        declare -p REMAINING_OPTS
+        declare -p REMAINING_ARGS
+    fi
+
+    if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then
+        error "Unknown options: ${REMAINING_OPTS[*]}"
+        echo >&2
+        usage >&2
+        exit 2
+    fi
+
+    if [[ "${#REMAINING_ARGS[@]}" -gt 0 ]] ; then
+        error "Invalid arguments: ${REMAINING_ARGS[*]}"
+        echo >&2
+        usage >&2
+        exit 2
+    fi
+
+    check_for_root
+
+}
+
+#------------------------------------------------------------------------------
+main() {
+
+    get_options "$@"
+    umask 0022
+
+}
+
+main "$@"
+
+exit 0
+
+# vim: et list