change config loading method...first decent version yay!

This commit is contained in:
encrypt 2015-03-25 02:59:02 +01:00
parent 197a9c5708
commit 43c9296a94

View file

@ -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