From 92df8b95faf2167e04b08b2bfe896661c59818c8 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 15 Jun 2021 09:09:57 +0200 Subject: [PATCH] Notification on shutting down VPN --- bin/start-openfortivpn | 51 +++++++++++++++++++++++++++++++++--------- lib/functions.rc | 2 +- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/bin/start-openfortivpn b/bin/start-openfortivpn index 196ab71..dfb9045 100755 --- a/bin/start-openfortivpn +++ b/bin/start-openfortivpn @@ -104,13 +104,16 @@ check_preferences() { local sample_file= local gateway_ip= - debug "Checking for openfortivpn ..." - if type -p openfortivpn >/dev/null ; then - debug "Found openfortivpn in '$( type -p openfortivpn )'." - else - all_ok="n" - error "Did not found openfortivpn. Maybe not installed?" - fi + local -a tools=('openfortivpn' 'zenity' ) + for tool in "${tools[@]}" ; do + debug "Checking for '${CYAN}${tool}${NORMAL}' ..." + if type -p ${tool} >/dev/null ; then + debug "Found '${CYAN}${tool}${NORMAL} in '${CYAN}$( type -p ${tool} )${NORMAL}'." + else + all_ok="n" + error "Did not found '${RED}${tool}${NORMAL}'. Maybe not installed?" + fi + done if [[ ! -f "${OFVPN_CONFIG}" ]] ; then error "Config file '${RED}${OFVPN_CONFIG}${NORMAL}' not found." @@ -173,8 +176,13 @@ restore_normal_conf() { #------------------------------------------------------------------------------ emerge_exit() { - warn "${YELLOW}Emergency exit${NORMAL}." + local signal="$1" + + local msg="Emergency exit by signal '${signal}'." + + warn "${YELLOW}${msg}${NORMAL}" restore_normal_conf + zenity --warning --title "${BASE_NAME}" --no-wrap --text "${msg}" debug "Deactivating trap ..." trap - INT TERM EXIT ABRT @@ -184,11 +192,34 @@ emerge_exit() { } +#------------------------------------------------------------------------------ +exit_abrt() { + emerge_exit 'ABRT' +} + +#------------------------------------------------------------------------------ +exit_exit() { + emerge_exit 'EXIT' +} + +#------------------------------------------------------------------------------ +exit_int() { + emerge_exit 'INT' +} + +#------------------------------------------------------------------------------ +exit_term() { + emerge_exit 'TERM' +} + #------------------------------------------------------------------------------ start_vpn() { - debug "Activating trap ..." - trap emerge_exit INT TERM EXIT ABRT + debug "Activating traps ..." + trap exit_abrt ABRT + trap exit_exit EXIT + trap exit_int INT + trap exit_term TERM info "Enabling special ${CYAN}/etc/resolv.conf${NORMAL} by ${CYAN}${RESOLV_CONF_DPX}${NORMAL} ..." CP -p "${RESOLV_CONF_DPX}" /etc/resolv.conf diff --git a/lib/functions.rc b/lib/functions.rc index d124156..045f5a7 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -10,7 +10,7 @@ BLUE="" CYAN="" NORMAL="" -VERSION="0.4.1" +VERSION="0.4.2" STD_SHORT_OPTIONS="sdvqhV" STD_LONG_OPTIONS="simulate,debug,verbose,quiet,nocolor,help,version" -- 2.39.5