54 lines
921 B
Bash
54 lines
921 B
Bash
#!/bin/sh
|
|
|
|
help() {
|
|
echo 'up/down [DEVICE]'
|
|
echo 'status [DEVICE]'
|
|
}
|
|
|
|
is_available() {
|
|
uci show pbr | grep -q "pbr.$1=policy"
|
|
}
|
|
|
|
|
|
# EXIT_SUCCESS if enabled
|
|
# EXIT_FAILURE if disabled
|
|
status() {
|
|
uci get pbr."$1".enabled >/dev/null 2>&1
|
|
}
|
|
|
|
up() {
|
|
is_available "$1" || exit 1
|
|
status "$1" || exit 1
|
|
uci del pbr."$1".enabled >/dev/null
|
|
uci commit >/dev/null
|
|
/etc/init.d/pbr reload > /dev/null
|
|
}
|
|
|
|
down() {
|
|
is_available "$1" || exit 1
|
|
status "$1" && exit 1
|
|
uci set pbr."$1".enabled=0 >/dev/null
|
|
uci commit >/dev/null
|
|
/etc/init.d/pbr reload > /dev/null
|
|
}
|
|
|
|
toggle() {
|
|
is_available "$1" || exit 1
|
|
if status "$1"; then
|
|
up "$1"
|
|
else
|
|
down "$1"
|
|
fi
|
|
}
|
|
|
|
if [ $# -lt 2 ]; then
|
|
help >&2
|
|
exit 1
|
|
fi
|
|
|
|
case "$1" in
|
|
"up") up "$2";;
|
|
"down") down "$2" ;;
|
|
"toggle") toggle "$2" ;;
|
|
"status") status "$2" && echo '0' || echo '1' ;;
|
|
esac
|