#!/bin/sh

/etc/init.d/xsmartqos stop

[ -f /tmp/speedtest ] && {
       rm /tmp/speedtest
}

/usr/bin/speedtest

[ $? -eq 0 ] && [ -f /tmp/speedtest ] && {
        up=`awk '{print $2}' /tmp/speedtest`
        down=`awk '{print $1}' /tmp/speedtest`
        uci set smartqos.qos.upband=$up
        uci set smartqos.qos.downband=$down
        uci commit
}

/etc/init.d/xsmartqos start
