change config loading method...first decent version yay!
This commit is contained in:
parent
197a9c5708
commit
43c9296a94
1 changed files with 20 additions and 13 deletions
|
@ -5,28 +5,35 @@ switch_state=0
|
||||||
|
|
||||||
function check_fn {
|
function check_fn {
|
||||||
type $1 &> /dev/null || {
|
type $1 &> /dev/null || {
|
||||||
echo "$1 is undefined"
|
>&2 echo "$1 is undefined"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function load_config {
|
||||||
|
unset -f on_switch_close
|
||||||
|
unset -f on_switch_open
|
||||||
source $conf
|
source $conf
|
||||||
|
|
||||||
# handle SIGTERM
|
|
||||||
trap 'exit' 15
|
|
||||||
|
|
||||||
if [ -z "$device" ]
|
if [ -z "$device" ]
|
||||||
then
|
then
|
||||||
echo "device is not set"
|
>&2 echo "device is not set"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if $device is a network device
|
# check if $device is a network device
|
||||||
ip link show $device > /dev/null
|
ip link show $device > /dev/null
|
||||||
if [ $? -eq 1 ]; then exit 1; fi
|
if [ $? -eq 1 ]; then exit 1; fi
|
||||||
|
|
||||||
check_fn "on_switch_close"
|
check_fn "on_switch_close"
|
||||||
check_fn "on_switch_open"
|
check_fn "on_switch_open"
|
||||||
|
}
|
||||||
|
|
||||||
|
# handle SIGTERM
|
||||||
|
trap 'exit' 15
|
||||||
|
|
||||||
|
# handle SIGHUP (config reload)
|
||||||
|
trap 'load_config' 1
|
||||||
|
|
||||||
|
load_config
|
||||||
|
|
||||||
while :
|
while :
|
||||||
do
|
do
|
||||||
|
|
Loading…
Reference in a new issue