From 93223dc82ad9d0911cde5d6e6318a6b378e6d274 Mon Sep 17 00:00:00 2001 From: Adamm <28355318+Adamm00@users.noreply.github.com> Date: Mon, 29 Jun 2020 19:54:09 +1000 Subject: [PATCH 1/9] Add seperate upload/download options | Remove Cake_Stop from start function --- cake-qos.sh | 68 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/cake-qos.sh b/cake-qos.sh index a688a0f..ed45825 100644 --- a/cake-qos.sh +++ b/cake-qos.sh @@ -15,7 +15,7 @@ ## |_| ## ## ## ## https://github.com/ttgapers/cakeqos-merlin ## -## v1.0.1 ## +## v1.0.2 ## ## ## ######################################################### @@ -69,7 +69,8 @@ Write_Config(){ printf '%s="%s"\n' "dlspeed" "$dlspeed" printf '%s="%s"\n' "upspeed" "$upspeed" printf '%s="%s"\n' "queueprio" "$queueprio" - printf '%s="%s"\n' "extraoptions" "$extraoptions" + printf '%s="%s"\n' "optionsdl" "$optionsdl" + printf '%s="%s"\n' "optionsup" "$optionsup" printf '\n%s\n' "##############################################" } > "$SCRIPT_CFG" } @@ -175,6 +176,13 @@ Cake_Start(){ exit 1 fi + # Migrate universal options to individual + if [ -n "${extraoptions:=}" ] && [ -z "$optionsdl" ] && [ -z "$optionsup" ]; then + optionsdl="${extraoptions:=}" + optionsup="${extraoptions:=}" + Write_Config + fi + # Cleanup old script entries rm -rf "/jffs/addons/$SCRIPT_NAME.d" 2> /dev/null sed -i '\~# cake-qos~d' /jffs/scripts/firewall-start /jffs/scripts/services-start /jffs/scripts/services-stop 2>/dev/null @@ -239,11 +247,9 @@ Cake_Start(){ ln -s "${SCRIPT_DIR}/${SCRIPT_NAME}" "/opt/bin/${SCRIPT_NAME}" fi - Cake_Stop - cru a "$SCRIPT_NAME_FANCY" "0 * * * * ${SCRIPT_DIR}/${SCRIPT_NAME} checkrun" - Print_Output "true" "Starting - ( ${dlspeed}Mbit | ${upspeed}Mbit | $queueprio | $extraoptions )" "$PASS" + Print_Output "true" "Starting - ( ${dlspeed}Mbit | ${upspeed}Mbit | $queueprio | $optionsdl | $optionsup )" "$PASS" runner disable 2>/dev/null fc disable 2>/dev/null fc flush 2>/dev/null @@ -251,12 +257,12 @@ Cake_Start(){ nvram set fc_disable="1" nvram commit insmod /opt/lib/modules/sch_cake.ko 2>/dev/null - /opt/sbin/tc qdisc replace dev eth0 root cake bandwidth "${upspeed}Mbit" nat "$queueprio" $extraoptions # options needs to be left unquoted to support multiple extra parameters + /opt/sbin/tc qdisc replace dev eth0 root cake bandwidth "${upspeed}Mbit" nat "$queueprio" $optionsup # options needs to be left unquoted to support multiple extra parameters ip link add name ifb9eth0 type ifb /opt/sbin/tc qdisc del dev eth0 ingress 2>/dev/null /opt/sbin/tc qdisc add dev eth0 handle ffff: ingress /opt/sbin/tc qdisc del dev ifb9eth0 root 2>/dev/null - /opt/sbin/tc qdisc add dev ifb9eth0 root cake bandwidth "${dlspeed}Mbit" nat wash ingress "$queueprio" $extraoptions # options needs to be left unquoted to support multiple extra parameters + /opt/sbin/tc qdisc add dev ifb9eth0 root cake bandwidth "${dlspeed}Mbit" nat wash ingress "$queueprio" $optionsdl # options needs to be left unquoted to support multiple extra parameters ifconfig ifb9eth0 up /opt/sbin/tc filter add dev eth0 parent ffff: protocol all prio 10 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb9eth0 } @@ -323,11 +329,12 @@ Cake_Menu(){ printf '%-35s | %-40s\n' "[1] --> Download Speed" "$(if [ -n "$dlspeed" ]; then echo "[${dlspeed} Mbit]"; else echo "[Unset]"; fi)" printf '%-35s | %-40s\n' "[2] --> Upload Speed" "$(if [ -n "$upspeed" ]; then echo "[${upspeed} Mbit]"; else echo "[Unset]"; fi)" printf '%-35s | %-40s\n' "[3] --> Queue Priority" "$(if [ -n "$queueprio" ]; then echo "[${queueprio}]"; else echo "[Unset]"; fi)" - printf '%-35s | %-40s\n' "[4] --> Extra Options" "$(if [ -n "$extraoptions" ]; then echo "[${extraoptions}]"; else echo "[Unset]"; fi)" + printf '%-35s | %-40s\n' "[4] --> Extra Download Options" "$(if [ -n "$optionsdl" ]; then echo "[${optionsdl}]"; else echo "[Unset]"; fi)" + printf '%-35s | %-40s\n' "[5] --> Extra Upload Options" "$(if [ -n "$optionsup" ]; then echo "[${optionsup}]"; else echo "[Unset]"; fi)" echo printf '%-35s\n' "[e] --> Exit" echo - printf "[1-4]: " + printf "[1-5]: " read -r "menu2" echo case "$menu2" in @@ -405,8 +412,16 @@ Cake_Menu(){ break ;; 4) - option2="extraoptions" - echo "Please enter your extra options:" + option2="optionsdl" + echo "Please enter your extra download options:" + printf "[Options]: " + read -r "option3" + echo + break + ;; + 5) + option2="optionsup" + echo "Please enter your extra upload options:" printf "[Options]: " read -r "option3" echo @@ -459,6 +474,7 @@ Display_Line case $1 in start) + Cake_Stop Cake_Start ;; stop) @@ -508,12 +524,16 @@ case $1 in ;; esac ;; - extraoptions) - extraoptions="$3" + optionsdl) + optionsdl="$3" + ;; + optionsup) + optionsup="$3" ;; esac Write_Config if Cake_CheckStatus; then + Cake_Stop Cake_Start fi ;; @@ -528,10 +548,11 @@ case $1 in if [ "$VERSION_LOCAL_SCRIPT" != "$VERSION_REMOTE_SCRIPT" ]; then Print_Output "true" "New CakeQOS-Merlin detected ($VERSION_REMOTE_SCRIPT, currently running $VERSION_LOCAL_SCRIPT), updating..." "$WARN" else - Print_Output "true" "Local and server md5 don't match, updating..." "$WARN" + Print_Output "true" "Local and remote md5 don't match, updating..." "$WARN" fi + Cake_Stop >/dev/null 2>&1 Download_File "${SCRIPT_NAME}.sh" "$0" - echo + Cake_Start >/dev/null 2>&1 else Print_Output "false" "${SCRIPT_NAME}.sh is up-to-date." "$PASS" fi @@ -562,7 +583,7 @@ case $1 in fi Cake_Bin_Download Display_Line - if [ -z "$dlspeed" ] || [ -z "$upspeed" ] || [ -z "$queueprio" ] || [ -z "$extraoptions" ]; then + if [ -z "$dlspeed" ] || [ -z "$upspeed" ] || [ -z "$queueprio" ] || [ -z "$optionsdl" ] || [ -z "$optionsup" ]; then if [ -z "$dlspeed" ]; then while true; do echo @@ -626,16 +647,24 @@ case $1 in esac done fi - if [ -z "$extraoptions" ]; then + if [ -z "$optionsdl" ]; then echo - echo "Please enter your extra options:" + echo "Please enter your extra download options:" printf "[Options]: " - read -r "extraoptions" + read -r "optionsdl" + echo + fi + if [ -z "$optionsup" ]; then + echo + echo "Please enter your extra upload options:" + printf "[Options]: " + read -r "optionsup" echo fi Display_Line fi Write_Config + Cake_Stop Cake_Start ;; uninstall) @@ -650,6 +679,7 @@ case $1 in checkrun) if ! Cake_CheckStatus; then Print_Output "true" "Not running, forcing start..." "$CRIT" + Cake_Stop Cake_Start fi ;; From 649b32743082773a56dcb92c754098823aae13a7 Mon Sep 17 00:00:00 2001 From: Adamm <28355318+Adamm00@users.noreply.github.com> Date: Mon, 29 Jun 2020 23:14:57 +1000 Subject: [PATCH 2/9] $extraoptions doesn't need to be set twice | Don't show update check when backing out of settings --- cake-qos.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cake-qos.sh b/cake-qos.sh index ed45825..e033d35 100644 --- a/cake-qos.sh +++ b/cake-qos.sh @@ -178,8 +178,8 @@ Cake_Start(){ # Migrate universal options to individual if [ -n "${extraoptions:=}" ] && [ -z "$optionsdl" ] && [ -z "$optionsup" ]; then - optionsdl="${extraoptions:=}" - optionsup="${extraoptions:=}" + optionsdl="${extraoptions}" + optionsup="${extraoptions}" Write_Config fi @@ -299,7 +299,7 @@ Cake_Menu(){ echo echo "[e] --> Exit" echo - if Cake_CheckUpdates; then + if [ "$1" = "check" ] && Cake_CheckUpdates; then Display_Line echo "[*] $SCRIPT_NAME_FANCY update available!" fi @@ -463,7 +463,7 @@ Cake_Menu(){ } if [ -z "$1" ]; then - Cake_Menu + Cake_Menu "check" fi if [ -n "$option1" ]; then From 31d91736a8941c6339ff6b2469d1ecb817121510 Mon Sep 17 00:00:00 2001 From: jackiechun Date: Tue, 30 Jun 2020 20:43:48 -0400 Subject: [PATCH 3/9] Accept decimals in bandwidth speed input https://www.snbforums.com/threads/release-cakeqos-merlin.64800/page-38#post-598661 --- cake-qos.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake-qos.sh b/cake-qos.sh index e033d35..ef97eee 100644 --- a/cake-qos.sh +++ b/cake-qos.sh @@ -56,7 +56,7 @@ Filter_Version(){ } Validate_Bandwidth(){ - grep -qE "^[0-9]{1,3}$" + grep -qE "^[0-9]{1,3}(\.[0-9]+)?$" } Write_Config(){ @@ -695,4 +695,4 @@ case $1 in ;; esac Display_Line -if [ -n "$reloadmenu" ]; then echo; printf "[*] Press Enter To Continue..."; read -r "reloadmenu"; exec "$0"; fi \ No newline at end of file +if [ -n "$reloadmenu" ]; then echo; printf "[*] Press Enter To Continue..."; read -r "reloadmenu"; exec "$0"; fi From d6eee17c07564d4ed1dbfca86ee6a6468d0884c6 Mon Sep 17 00:00:00 2001 From: Adamm <28355318+Adamm00@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:50:58 +1000 Subject: [PATCH 4/9] Additional status options --- cake-qos.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/cake-qos.sh b/cake-qos.sh index e033d35..f1edfb6 100644 --- a/cake-qos.sh +++ b/cake-qos.sh @@ -320,6 +320,36 @@ Cake_Menu(){ ;; 3) option1="status" + while true; do + echo "Select Status Option:" + echo "[1] --> Download Status" + echo "[2] --> Upload Status" + echo "[3] --> General Status" + echo + printf "[1-3]: " + read -r "menu2" + echo + case "$menu2" in + 1) + option2="download" + break + ;; + 2) + option2="upload" + break + ;; + 3) + option2="general" + break + ;; + e|exit|back|menu) + unset "option1" "option2" "option3" + clear + Cake_Menu + break + ;; + esac + done break ;; 4) @@ -486,10 +516,20 @@ case $1 in status) if Cake_CheckStatus; then Print_Output "false" "Running..." "$PASS" - Print_Output "false" "> Download Status:" "$PASS" - echo "$STATUS_DOWNLOAD" - Print_Output "false" "> Upload Status:" "$PASS" - echo "$STATUS_UPLOAD" + case "$2" in + download) + tc -s qdisc show dev ifb9eth0 + ;; + upload) + tc -s qdisc show dev eth0 + ;; + general) + Print_Output "false" "> Download Status:" "$PASS" + echo "$STATUS_DOWNLOAD" + Print_Output "false" "> Upload Status:" "$PASS" + echo "$STATUS_UPLOAD" + ;; + esac else Print_Output "false" "Not running..." "$WARN" fi From ea7d406a8e343352b30379750a39a97035908c35 Mon Sep 17 00:00:00 2001 From: Adamm <28355318+Adamm00@users.noreply.github.com> Date: Wed, 1 Jul 2020 12:56:41 +1000 Subject: [PATCH 5/9] Dont unset option3 --- cake-qos.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake-qos.sh b/cake-qos.sh index b84d397..376da21 100644 --- a/cake-qos.sh +++ b/cake-qos.sh @@ -343,7 +343,7 @@ Cake_Menu(){ break ;; e|exit|back|menu) - unset "option1" "option2" "option3" + unset "option1" "option2" clear Cake_Menu break @@ -735,4 +735,4 @@ case $1 in ;; esac Display_Line -if [ -n "$reloadmenu" ]; then echo; printf "[*] Press Enter To Continue..."; read -r "reloadmenu"; exec "$0"; fi +if [ -n "$reloadmenu" ]; then echo; printf "[*] Press Enter To Continue..."; read -r "reloadmenu"; exec "$0"; fi \ No newline at end of file From a848dd3c4a5e8abdbd62b06a716de2674ece5938 Mon Sep 17 00:00:00 2001 From: Adamm <28355318+Adamm00@users.noreply.github.com> Date: Wed, 1 Jul 2020 13:02:19 +1000 Subject: [PATCH 6/9] Don't allow malformed commands --- cake-qos.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cake-qos.sh b/cake-qos.sh index 376da21..76b2c04 100644 --- a/cake-qos.sh +++ b/cake-qos.sh @@ -515,7 +515,6 @@ case $1 in ;; status) if Cake_CheckStatus; then - Print_Output "false" "Running..." "$PASS" case "$2" in download) tc -s qdisc show dev ifb9eth0 @@ -526,9 +525,14 @@ case $1 in general) Print_Output "false" "> Download Status:" "$PASS" echo "$STATUS_DOWNLOAD" + echo Print_Output "false" "> Upload Status:" "$PASS" echo "$STATUS_UPLOAD" ;; + *) + echo "Command Not Recognized, Please Try Again" + echo; exit 2 + ;; esac else Print_Output "false" "Not running..." "$WARN" @@ -570,6 +574,10 @@ case $1 in optionsup) optionsup="$3" ;; + *) + echo "Command Not Recognized, Please Try Again" + echo; exit 2 + ;; esac Write_Config if Cake_CheckStatus; then From 6e7b76b30d4ce9c83429216cc464eb5e98987b75 Mon Sep 17 00:00:00 2001 From: Adamm <28355318+Adamm00@users.noreply.github.com> Date: Wed, 1 Jul 2020 13:18:27 +1000 Subject: [PATCH 7/9] Update malformed command output --- cake-qos.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cake-qos.sh b/cake-qos.sh index 76b2c04..4a2e47c 100644 --- a/cake-qos.sh +++ b/cake-qos.sh @@ -732,13 +732,14 @@ case $1 in fi ;; *) - Print_Output "false" "Usage: $SCRIPT_NAME {install|update|start|status|stop|uninstall} (start has required parameters)" "$WARN" + Print_Output "false" "Usage: $SCRIPT_NAME {start|stop|status|settings|update|install|uninstall}" "$WARN" echo - Print_Output "false" "install: only downloads and installs necessary $SCRIPT_NAME binaries" "$PASS" - Print_Output "false" "update: update $SCRIPT_NAME binaries (if any available)" "$PASS" Print_Output "false" "start: configure and start $SCRIPT_NAME" "$PASS" - Print_Output "false" "status: check the current status of $SCRIPT_NAME" "$PASS" Print_Output "false" "stop: stop $SCRIPT_NAME" "$PASS" + Print_Output "false" "status: check the current status of $SCRIPT_NAME" "$PASS" + Print_Output "false" "settings: configure settings for $SCRIPT_NAME" "$PASS" + Print_Output "false" "update: update $SCRIPT_NAME binaries (if any available)" "$PASS" + Print_Output "false" "install: only downloads and installs necessary $SCRIPT_NAME binaries" "$PASS" Print_Output "false" "uninstall: stop $SCRIPT_NAME, remove from startup, and remove cake binaries" "$PASS" ;; esac From 50e8bbd8d6199d05c0c2501a0f6e6004a9bb1ed9 Mon Sep 17 00:00:00 2001 From: Adamm <28355318+Adamm00@users.noreply.github.com> Date: Wed, 1 Jul 2020 13:20:25 +1000 Subject: [PATCH 8/9] Aesthetics --- cake-qos.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cake-qos.sh b/cake-qos.sh index 4a2e47c..cb14591 100644 --- a/cake-qos.sh +++ b/cake-qos.sh @@ -734,12 +734,12 @@ case $1 in *) Print_Output "false" "Usage: $SCRIPT_NAME {start|stop|status|settings|update|install|uninstall}" "$WARN" echo - Print_Output "false" "start: configure and start $SCRIPT_NAME" "$PASS" + Print_Output "false" "start: start $SCRIPT_NAME" "$PASS" Print_Output "false" "stop: stop $SCRIPT_NAME" "$PASS" Print_Output "false" "status: check the current status of $SCRIPT_NAME" "$PASS" Print_Output "false" "settings: configure settings for $SCRIPT_NAME" "$PASS" - Print_Output "false" "update: update $SCRIPT_NAME binaries (if any available)" "$PASS" - Print_Output "false" "install: only downloads and installs necessary $SCRIPT_NAME binaries" "$PASS" + Print_Output "false" "update: update $SCRIPT_NAME & binaries (if available)" "$PASS" + Print_Output "false" "install: install and configure $SCRIPT_NAME" "$PASS" Print_Output "false" "uninstall: stop $SCRIPT_NAME, remove from startup, and remove cake binaries" "$PASS" ;; esac From 8927ce3f6f837fe26073b3abe172c3ca6d27a26d Mon Sep 17 00:00:00 2001 From: Adamm <28355318+Adamm00@users.noreply.github.com> Date: Wed, 1 Jul 2020 21:49:15 +1000 Subject: [PATCH 9/9] v1.0.2 Display CLI version of commands when using menu options --- cake-qos.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/cake-qos.sh b/cake-qos.sh index cb14591..9ac2b8c 100644 --- a/cake-qos.sh +++ b/cake-qos.sh @@ -498,6 +498,7 @@ fi if [ -n "$option1" ]; then set "$option1" "$option2" "$option3" + echo "[$] $0 $*" | tr -s " " fi Display_Line