diff --git a/etherswitch.sh b/etherswitch.sh index cc62727..2c808b7 100755 --- a/etherswitch.sh +++ b/etherswitch.sh @@ -5,28 +5,35 @@ switch_state=0 function check_fn { type $1 &> /dev/null || { - echo "$1 is undefined" + >&2 echo "$1 is undefined" exit 1 } } -source $conf +function load_config { + unset -f on_switch_close + unset -f on_switch_open + source $conf + if [ -z "$device" ] + then + >&2 echo "device is not set" + exit 1 + fi + # check if $device is a network device + ip link show $device > /dev/null + if [ $? -eq 1 ]; then exit 1; fi + + check_fn "on_switch_close" + check_fn "on_switch_open" +} # handle SIGTERM trap 'exit' 15 -if [ -z "$device" ] -then - echo "device is not set" - exit 1 -fi +# handle SIGHUP (config reload) +trap 'load_config' 1 -# check if $device is a network device -ip link show $device > /dev/null -if [ $? -eq 1 ]; then exit 1; fi - -check_fn "on_switch_close" -check_fn "on_switch_open" +load_config while : do