This commit is contained in:
commit
c7c1ff32a0
4 changed files with 250 additions and 0 deletions
54
openwrt_pbr.sh
Normal file
54
openwrt_pbr.sh
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#!/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
|
||||
Loading…
Add table
Add a link
Reference in a new issue