#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2015 IPFire Network Development Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### TRIGGER_ACTIONS="init up down online" trigger_execute() { local trigger="$1" shift local environment=$@ if [ ! -x "${trigger}" ]; then log WARNING "Trigger is not executable: ${trigger}" return ${EXIT_ERROR} fi log DEBUG "Executing trigger ${trigger}..." cmd ${environment} "${trigger}" &>/dev/null local ret=${?} if [ ${ret} -ne ${EXIT_OK} ]; then log WARNING "Trigger ${trigger} exited with exit code: ${ret}" log WARNING " Environment: ${environment}" fi return ${ret} } triggers_execute_all() { local action="${1}" shift # Check if the action is valid assert list_match "${action}" ${TRIGGER_ACTIONS} local environment=$@ # Check if the directory exists [ -d "${NETWORK_TRIGGERS_DIR}" ] || return ${EXIT_ERROR} local trigger for trigger in ${NETWORK_TRIGGERS_DIR}/*; do # Check if the trigger can be executed if [ ! -x "${trigger}" ]; then log DEBUG "Trigger is not executable: ${trigger}" continue fi # Execute the trigger trigger_execute "${trigger}" ${environment} ACTION="${action}" done return ${EXIT_OK} }