From: Frank Brehm Date: Wed, 22 Apr 2020 06:06:04 +0000 (+0200) Subject: Adding bin/start-openfortivpn X-Git-Tag: 0.1.2~5^2~5 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=4d584386779ea4822a243cc814beb96a81b26542;p=pixelpark%2Fadmin-tools.git Adding bin/start-openfortivpn --- diff --git a/bin/start-openfortivpn b/bin/start-openfortivpn new file mode 100755 index 0000000..8feb7d3 --- /dev/null +++ b/bin/start-openfortivpn @@ -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