From 17f3ad2b86d0a56902314e317149ec6147062103 Mon Sep 17 00:00:00 2001 From: Johannes Truschnigg Date: Fri, 2 Sep 2022 20:33:57 +0200 Subject: [PATCH] Extend configuration wizard, round 1 --- sqm_lagthrottle_suggest_config.sh | 82 +++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/sqm_lagthrottle_suggest_config.sh b/sqm_lagthrottle_suggest_config.sh index ef2cde7..d945088 100755 --- a/sqm_lagthrottle_suggest_config.sh +++ b/sqm_lagthrottle_suggest_config.sh @@ -19,11 +19,18 @@ TZ=UTC LC_ALL=C export TZ LC_ALL -for p in sort sleep cat awk tee date fping +for p in sort sleep cat awk tee date fping find head do type "${p}" >/dev/null || { printf 'FATAL: Required program "%s" not installed.\n' "${p}" >&2; exit 1; } done +_goon() { +echo "" >&2 +echo "${1:-Hit the [ENTER] key when ready, or [CTRL]+[C] to abort...}" >&2 +read -s _ >/dev/null +echo "" >&2 +} + fpo="/tmp/fping_${$}.out" sto="${fpo}.stats" cfgo="./sqm_lagthrottle.conf.$(date +%s)" @@ -31,15 +38,54 @@ POTENTIAL_PING_PEERS='1.1.1.1 8.8.8.8 a.root-servers.net b.root-servers.net c.ro set -u -echo "This script will ping potential peers for two minutes," >&2 -echo "record stats, and recommend configuration values for sqm_lagthrottle.sh" >&2 +echo "Welcome to the interactive sqm_lagthrottle configuration wizard." >&2 +echo "" >&2 +printf 'This script will prompt you for a number of settings\n(recommending sensible defaults where thought possible)\nrequired for proper operation of sqm_lagthrottle.\n\nPlease take a few minutes to follow its instructions\nto make the most out of dynamically adjusting your bandwidth shaper.\n' +_goon +echo "" >&2 +printf 'After this process, a configuration file drop-in will be created at\n\t%s\n\nYou can rename and use that file as your sqm_lagthrottle configuration\nfile as per its instructions.\n' "${cfgo}" >&2 +echo "" >&2 +_goon + + +ifb_dev=$(find /sys/devices/virtual/net/ -name ifb\* -print | head -n 1) +if [ -e /sys/devices/virtual/net/ifb* ] +then + printf 'Likely network device auto-detected to apply traffic shaping to:\n\t%s\n\n' "${ifb_dev}" >&2 + printf 'Please confirm this by supplying either this device path,\nor a custom value to replace it:\n\t' >&2 + read ifb_dev +else + printf 'FATAL: No SQM shaping network device could be determined.\nAre you sure SQM has been set up via luci-app-sqm?\n' >&2 + exit 1 +fi +echo "" >&2 + +if ! [ -f "${ifb_dev}"///statistics/tx_bytes ] +then + printf 'FATAL: No SQM shaping network device could be identified at\n\t%s\n' "${ifb_dev}" >&2 + exit 1 +fi + +stats_rx="${ifb_dev}"/statistics/tx_bytes +iface_rx="${ifb_dev%%*/}" + +printf 'Please key in the positive integer LOWER bound (=minimum) bandwidth in Kbps\nfor your downstream Internet connection that you want to shape to: ' >&2 +read bw_down_min echo "" >&2 -printf 'Suggested values will also be written to "%s"\n' "${cfgo}" >&2 + +printf 'Please key in the positive integer UPPER bound (=maximum) bandwidth in Kbps\nfor your downstream Internet connection that you want to shape to: ' >&2 +read bw_down_max echo "" >&2 -echo "Please keep your Internet-directed traffic at a minimum while pinging." >&2 + +if ! [ ${bw_down_min} -lt ${bw_down_max} ] +then + printf 'FATAL: Maximum shaping bandwith must be greater than minimum.\n' + exit 1 +fi + +printf 'Now, we will ping potential ICMP ECHO peers for two minutes,\nrecord stats, and determine the top four choices.\n\nPlease keep your Internet-directed traffic at a minimum while this happens!\n' >&2 +_goon echo "" >&2 -echo "Hit the [ENTER] key when ready, or [CTRL]+[C] to abort..." >&2 -read _ >/dev/null printf 'Performing pings, please be patient...' >&2 #set -x @@ -59,11 +105,6 @@ fping --all --addr --count="${P_COUNT}" --period=250 --retry=0 --size=1280 ${POT wait -echo "" >&2 -echo "Pings done. Computed settings follow:" >&2 -echo "" >&2 -echo "" >&2 - set -e awk -v "outfile=${sto}" -v "P_COUNT=${P_COUNT}" ' @@ -100,7 +141,7 @@ END { { #print p " " peers_pinglist[p] } -}' "${fpo}" | tee -a "${cfgo}" +}' "${fpo}" > "${cfgo}" awk ' { @@ -119,17 +160,16 @@ END { } } printf "\"\n" -}' "${sto}" | tee -a "${cfgo}" +}' "${sto}" >> "${cfgo}" -echo "" >&2 -echo "" >&2 +printf 'BW_MIN_RX="%d"\n' "${bw_down_min}" >> "${cfgo}" +printf 'BW_MAX_RX="%d"\n' "${bw_down_max}" >> "${cfgo}" +printf 'STATS_RX="%s"\n' "${stats_rx}" >> "${cfgo}" +printf 'IFACE_RX="%s"\n' "${iface_rx}" >> "${cfgo}" +printf 'Determined suggested values saved in "%s"\n\n' "${cfgo}" >&2 -echo "Hit the [ENTER] to display full stats, or [CTRL]+[C] to exit." >&2 -read _ >/dev/null +_goon "Hit the [ENTER] to display full stats, or [CTRL]+[C] to exit." >&2 cat "${sto}" >&2 echo "" >&2 rm -f "${fpo}" "${sto}" - -printf 'Determined suggested values saved in "%s"\n\n' "${cfgo}" >&2 -echo "" >&2 -- 2.39.5