From b509c5fae8025574a32de9dd41e60637229fea30 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 2 Feb 2021 09:40:22 +0100 Subject: [PATCH] Completing logging of bin/start-openfortivpn --- bin/start-openfortivpn | 25 ++++++++++++++++++++++--- lib/functions.rc | 10 +++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/bin/start-openfortivpn b/bin/start-openfortivpn index 5e762af..196ab71 100755 --- a/bin/start-openfortivpn +++ b/bin/start-openfortivpn @@ -12,6 +12,8 @@ CONF_DIR="${BASE_DIR}/etc" DNS_DIR="${BASE_DIR}/dns" OFVPN_CONFIG="/etc/openfortivpn/config" +FINISHED='n' + if [[ -f "${LIB_DIR}/functions.rc" ]] ; then . "${LIB_DIR}/functions.rc" else @@ -168,24 +170,41 @@ restore_normal_conf() { } +#------------------------------------------------------------------------------ +emerge_exit() { + + warn "${YELLOW}Emergency exit${NORMAL}." + restore_normal_conf + + debug "Deactivating trap ..." + trap - INT TERM EXIT ABRT + + info "Finished." + exit 5 + +} + #------------------------------------------------------------------------------ start_vpn() { debug "Activating trap ..." - trap restore_normal_conf INT TERM EXIT ABRT + trap emerge_exit INT TERM EXIT ABRT info "Enabling special ${CYAN}/etc/resolv.conf${NORMAL} by ${CYAN}${RESOLV_CONF_DPX}${NORMAL} ..." CP -p "${RESOLV_CONF_DPX}" /etc/resolv.conf + info "Starting openfortivpn ..." local cmd="openfortivpn --no-dns --pppd-no-peerdns" - debug "Executing: ${cmd}" - eval ${cmd} + info "Executing: ${cmd}" + eval ${cmd} 2>&1 | tee -a "${LOGFILE}" debug "Deactivating trap ..." trap - INT TERM EXIT ABRT restore_normal_conf + info "Finished." + } #------------------------------------------------------------------------------ diff --git a/lib/functions.rc b/lib/functions.rc index 38e4ab3..4b44c67 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -10,7 +10,7 @@ BLUE="" CYAN="" NORMAL="" -VERSION="0.3.9" +VERSION="0.4.0" STD_SHORT_OPTIONS="sdvhV" STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version" @@ -270,7 +270,7 @@ debug() { fi local ts=$(my_date) if [[ -n "${LOGFILE}" ]] ; then - echo "[${ts}] [${BASE_NAME}DEBUG]: $@" >>"${LOGFILE}" + echo -e "[${ts}] [${BASE_NAME}:${CYAN}DEBUG${NORMAL}]: $@" >>"${LOGFILE}" fi echo -e " * [${ts}] [${BASE_NAME}:${CYAN}DEBUG${NORMAL}]: $@" >&2 } @@ -279,7 +279,7 @@ debug() { info() { local ts=$(my_date) if [[ -n "${LOGFILE}" ]] ; then - echo "[${ts}] [${BASE_NAME}INFO] : $@" >>"${LOGFILE}" + echo -e "[${ts}] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $@" >>"${LOGFILE}" fi echo -e " ${GREEN}*${NORMAL} [${ts}] [${BASE_NAME}:${GREEN}INFO${NORMAL}] : $@" >&2 } @@ -288,7 +288,7 @@ info() { warn() { local ts=$(my_date) if [[ -n "${LOGFILE}" ]] ; then - echo "[${ts}] [${BASE_NAME}WARN] : $@" >>"${LOGFILE}" + echo -e "[${ts}] [${BASE_NAME}:${YELLOW}WARN${NORMAL}] : $@" >>"${LOGFILE}" fi echo -e " ${YELLOW}*${NORMAL} [${ts}] [${BASE_NAME}:${YELLOW}WARN${NORMAL}] : $@" >&2 } @@ -297,7 +297,7 @@ warn() { error() { local ts=$(my_date) if [[ -n "${LOGFILE}" ]] ; then - echo "[${ts}] [${BASE_NAME}ERROR]: $@" >>"${LOGFILE}" + echo -e "[${ts}] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $@" >>"${LOGFILE}" fi echo -e " ${RED}*${NORMAL} [${ts}] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $@" >&2 } -- 2.39.5