Add "admin.sh", a tool for easy administration tasks

This commit is contained in:
marc René Schädler 2013-11-13 11:59:55 +01:00 committed by Tim Niemeyer
parent b44caefc96
commit e55b2a7533
11 changed files with 118 additions and 2 deletions

View File

@ -0,0 +1,98 @@
#!/bin/ash
# input check functions
check_hostname() {
local STRING="$@"
[ -n "$STRING" ] || return 1
local STRING_VALID=$(echo -n "$STRING" | grep -E "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$")
[ "$STRING" == "$STRING_VALID" ] || return 1
}
check_integer() {
local STRING="$@"
[ -n "$STRING" ] || return 1
local STRING_VALID=$(echo -n "$STRING" | grep -E "^[0-9]+$")
[ "$STRING" == "$STRING_VALID" ] || return 1
}
check_httpurl() {
local STRING="$@"
[ -n "$STRING" ] || return 1
local STRING_VALID=$(echo -n "$STRING" | grep -E "http(s?):\/\/[^ \"\(\)\<\>]*")
[ "$STRING" == "$STRING_VALID" ] || return 1
}
check_contains() {
local STRING="$1"
local STRING2="$2"
local STRING_VALID=$(echo -n "$STRING" | grep -E "$STRING2")
[ "$STRING" == "$STRING_VALID" ] || return 1
}
# command implementations
set_hostname() {
local HOSTNAME="$1"
check_hostname "$HOSTNAME" || return 1
uci set system.@system[0].hostname="$HOSTNAME"
uci commit
echo "$HOSTNAME" > /proc/sys/kernel/hostname
}
set_wanratelimit() {
local UPLIMIT="$1"
local DOWNLIMIT="$2"
check_integer "$UPLIMIT" || return 1
check_integer "$DOWNLIMIT" || return 1
if [ "$UPLIMIT" -gt 0 ] && [ "$DOWNLIMIT" -gt 0 ]; then
uci set qos.wan.upload="$UPLIMIT"
uci set qos.wan.download="$DOWNLIMIT"
uci commit
/etc/init.d/qos stop
/etc/init.d/qos enable
/etc/init.d/qos start
else
/etc/init.d/qos stop
/etc/init.d/qos disable
fi
}
upgrade_firmware() {
local URL="$1"
local MD5SUM="$2"
local BOARDNAME=$(uci get board.model.name)
[ -n "$BOARDNAME" ] || return 1
if [ -z "$URL" ]; then
local UPGRADEPATH=$(uci get firmware.upgrade.path)
URL="${UPGRADEPATH}/${BOARDNAME}.bin"
fi
check_httpurl "$URL" || return 1
check_contains "$URL" "$BOARDNAME" || return 1
check_contains "$URL" "upgrade" || return 1
[ -n "$MD5SUM" ] || MD5SUM=$(wget -q -O - --no-check-certificate "$URL.md5" | cut -d" " -f1)
[ -n "$MD5SUM" ] || return 1
wget -q -O /tmp/firmware-sysupgrade.bin --no-check-certificate "$URL" || return 1
local MD5SUM_VALID=$(md5sum /tmp/firmware-sysupgrade.bin | cut -d" " -f1)
[ "$MD5SUM" == "$MD5SUM_VALID" ] || return 1
sysupgrade /tmp/firmware-sysupgrade.bin
}
ACTION="$1"
shift
case "$ACTION" in
hostname)
set_hostname $@
;;
wanratelimit)
set_wanratelimit $@
;;
upgrade)
upgrade_firmware $@
;;
*)
echo "unknown action"
;;
esac

View File

@ -0,0 +1,4 @@
config upgrade 'upgrade'
option path '${UPGRADE_PATH}'
option auto 0
option remote 1

View File

@ -0,0 +1,2 @@
config model 'model'
option name 'dir300'

View File

@ -0,0 +1,2 @@
config model 'model'
option name 'fonera'

View File

@ -0,0 +1,2 @@
config model 'model'
option name 'wr1043nd-v1'

View File

@ -0,0 +1,2 @@
config model 'model'
option name 'tl-wr741nd-v2'

View File

@ -0,0 +1,2 @@
config model 'model'
option name 'tl-wr741nd-v4'

View File

@ -0,0 +1,2 @@
config model 'model'
option name 'tl-wr841n-v8'

View File

@ -0,0 +1,2 @@
config model 'model'
option name 'tl-wr841nd-v7'

View File

@ -5,4 +5,4 @@ BSSID_MESH=02:CA:FF:EE:BA:BE
NETMON_IP=fe80::ff:feee:1
VPN_PROJECT=fff
NTPD_IP=fe80::ff:feee:1%br-mesh
UPGRADE_PATH=http://firmware.freifunk-franken.de/latest/upgrade/

View File

@ -5,4 +5,4 @@ BSSID_MESH=02:CA:FF:EE:BA:BE
NETMON_IP=fe80::201:2ff:fe03:405
VPN_PROJECT=ffol
NTPD_IP=fe80::201:2ff:fe03:405%br-mesh
UPGRADE_PATH=http://firmware.freifunk-ol.de/latest/upgrade/