Created
July 14, 2016 13:24
-
-
Save marvin/7292f8ebb0f7bfb98e20dc563e9588a0 to your computer and use it in GitHub Desktop.
Freifunk Gluon Throttle Speed via Cron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ash | |
# | |
#Check if Mesh-VPN shall be limited | |
# | |
# 1. Edit DownloadRate and UploadRate | |
# 2. save via vi in /etc/throttle.sh | |
# 3. make executable "chmod a+x /etc/throttle.sh" | |
# 4. add to cron to check every 15min "*/15 * * * * /etc/throttle.sh >/dev/null 2>&1" | |
# 5. edit /etc/sysupgrade.conf to protect from sysupgrade | |
# add line "/etc/throttle.sh" | |
# 6. Run and check /var/log/throttle.log | |
# throttle download rate to (Bit/s) | |
DownloadRate=2000 | |
# throttle upload rate to (Bit/s) | |
UploadRate=1000 | |
logfile="/tmp/log/throttle.log" | |
#logfile=/dev/null | |
echo "$(date): Throttle invoked" >> $logfile | |
CurrentHour="$(date +%H)" | |
CurrentDayOfWeek="$(date +%w)" | |
CurrentThrottleState=$(uci get simple-tc.mesh_vpn.enabled) | |
DoLimit=1 | |
case $CurrentDayOfWeek in | |
0) | |
#echo "Sonntag" | |
DoLimit=0 | |
;; | |
[1-5]) | |
#echo "Mo,Di,Mi,Do,Fr" | |
if [ $CurrentHour -lt 8 ]; then DoLimit=0; fi; | |
if [ $CurrentHour -ge 18 ]; then DoLimit=0; fi; | |
;; | |
6) | |
#echo "Samstag" | |
if [ $CurrentHour -lt 8 ]; then DoLimit=0; fi; | |
if [ $CurrentHour -ge 12 ]; then DoLimit=0; fi; | |
;; | |
*) | |
#echo Fallback | |
DoLimit=0 | |
;; | |
esac | |
if [ "$DoLimit" -ne "$CurrentThrottleState" ]; then | |
if [ "$DoLimit" = "1" ]; then | |
echo "$(date): Meshlimit wird aktiviert, Down=$DownloadRate, Up=$UploadRate" >> $logfile | |
uci set simple-tc.mesh_vpn.limit_ingress=$DownloadRate | |
uci set simple-tc.mesh_vpn.limit_egress=$UploadRate | |
uci set simple-tc.mesh_vpn.enabled=1 | |
else | |
echo "$(date): Meshlimit wird deaktiviert" >> $logfile | |
uci set simple-tc.mesh_vpn.enabled=0 | |
fi; | |
uci commit simple-tc | |
/etc/init.d/fastd restart | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment