diff options
Diffstat (limited to 'net/travelmate/files/travelmate.init')
-rwxr-xr-x | net/travelmate/files/travelmate.init | 86 |
1 files changed, 33 insertions, 53 deletions
diff --git a/net/travelmate/files/travelmate.init b/net/travelmate/files/travelmate.init index 1346bc6dc..2017ba933 100755 --- a/net/travelmate/files/travelmate.init +++ b/net/travelmate/files/travelmate.init @@ -3,7 +3,7 @@ # This is free software, licensed under the GNU General Public License v3. # set (s)hellcheck exceptions -# shellcheck disable=1091,2016,2034,2039,2059,2086,2143,2154,2181,2188 +# shellcheck disable=2034,2086,2154,3043,3060 START=25 USE_PROCD=1 @@ -17,19 +17,16 @@ trm_pidfile="/var/run/travelmate.pid" boot() { - if [ -s "${trm_pidfile}" ] - then - > "${trm_pidfile}" + if [ -s "${trm_pidfile}" ]; then + : >"${trm_pidfile}" fi rc_procd start_service } start_service() { - if [ "$("${trm_init}" enabled; printf "%u" ${?})" = "0" ] - then - if [ "${action}" = "boot" ] - then + if "${trm_init}" enabled; then + if [ "${action}" = "boot" ]; then return 0 fi procd_open_instance "travelmate" @@ -45,17 +42,14 @@ start_service() reload_service() { local ppid pid timeout - + timeout="$(uci_get travelmate global trm_timeout)" - if [ -s "${trm_pidfile}" ] - then + if [ -s "${trm_pidfile}" ]; then ppid="$(cat "${trm_pidfile}" 2>/dev/null)" - if [ -n "${ppid}" ] - then + if [ -n "${ppid}" ]; then pid="$(pgrep -xnf "sleep ${timeout:-60} 0" -P ${ppid} 2>/dev/null)" - if [ -n "${pid}" ] - then + if [ -n "${pid}" ]; then kill -INT ${pid} 2>/dev/null fi fi @@ -73,13 +67,10 @@ status_service() rtfile="$(uci_get travelmate global trm_rtfile "/tmp/trm_runtime.json")" json_load_file "${rtfile}" >/dev/null 2>&1 - json_select data >/dev/null 2>&1 - if [ "${?}" = "0" ] - then + if json_select data >/dev/null 2>&1; then printf "%s\n" "::: travelmate runtime information" json_get_keys keylist - for key in ${keylist} - do + for key in ${keylist}; do json_get_var value "${key}" printf " + %-18s : %s\n" "${key}" "${value}" done @@ -92,21 +83,20 @@ scan() { local result scan_dev radio="${1:-"radio0"}" - scan_dev="$(ubus -S call network.wireless status 2>/dev/null | jsonfilter -l1 -e "@.${radio}.interfaces[0].ifname")" - result="$(iwinfo "${scan_dev:-${radio}}" scan 2>/dev/null | \ + scan_dev="$(ubus -S call network.wireless status 2>/dev/null | jsonfilter -q -l1 -e "@.${radio}.interfaces[0].ifname")" + result="$(iwinfo "${scan_dev:-${radio}}" scan 2>/dev/null | awk 'BEGIN{FS="[[:space:]]"}/Address:/{var1=$NF}/ESSID:/{var2=""; for(i=12;i<=NF;i++)if(var2==""){var2=$i}else{var2=var2" "$i}}/Channel:/{var3=$NF}/Quality:/{split($NF,var0,"/")}/Encryption:/{var4=""; - for(j=12;j<=NF;j++)if(var4==""){var4=$j}else{var4=var4" "$j};printf " %-11i%-10s%-35s%-20s%s\n",(var0[1]*100/var0[2]),var3,var2,var1,var4}' | \ + for(j=12;j<=NF;j++)if(var4==""){var4=$j}else{var4=var4" "$j};printf " %-11i%-10s%-35s%-20s%s\n",(var0[1]*100/var0[2]),var3,var2,var1,var4}' | sort -rn)" - printf "%s\\n" "::: Available nearby uplinks on '${scan_dev:-${radio}}'" - printf "%s\\n" ":::" - if [ -n "${result}" ] - then - printf "%-15s%-10s%-35s%-20s%s\\n" " Strength" "Channel" "ESSID" "BSSID" "Encryption" - printf "%s\\n" " --------------------------------------------------------------------------------------" - printf "%s\\n" "${result}" + printf '%s\n' "::: Available nearby uplinks on '${scan_dev:-${radio}}'" + printf '%s\n' ":::" + if [ -n "${result}" ]; then + printf '%-15s%-10s%-35s%-20s%s\n' " Strength" "Channel" "ESSID" "BSSID" "Encryption" + printf '%s\n' " --------------------------------------------------------------------------------------" + printf '%s\n' "${result}" else - printf "%s\\n" "::: No scan results" + printf '%s\n' "::: No scan results" fi } @@ -119,13 +109,10 @@ setup() zone="${zone//[+*~%&\$@\"\' ]/}" metric="${metric//[^0-9]/}" - if [ -n "${iface}" ] && [ "${iface}" = "${input}" ] - then + if [ -n "${iface}" ] && [ "${iface}" = "${input}" ]; then printf "%s\n" "The uplink interface '${input}' has been already configured" - elif [ -n "${input}" ] - then - if [ -n "${iface}" ] - then + elif [ -n "${input}" ]; then + if [ -n "${iface}" ]; then uci -q batch <<-EOC del network."${iface}" del network."${iface}6" @@ -144,12 +131,9 @@ setup() commit network EOC - while [ -n "$(uci -q get firewall.@zone["${cnt}"].name)" ] - do - if [ "$(uci -q get firewall.@zone["${cnt}"].name)" = "${zone}" ] - then - if [ -n "${iface}" ] - then + while [ -n "$(uci -q get firewall.@zone["${cnt}"].name)" ]; do + if [ "$(uci -q get firewall.@zone["${cnt}"].name)" = "${zone}" ]; then + if [ -n "${iface}" ]; then uci -q batch <<-EOC del_list firewall.@zone["${cnt}"].network="${iface}" del_list firewall.@zone["${cnt}"].network="${iface}6" @@ -162,19 +146,16 @@ setup() EOC break fi - cnt=$((cnt+1)) + cnt=$((cnt + 1)) done - if [ -n "${iface}" ] - then + if [ -n "${iface}" ]; then cnt=0 - while [ -n "$(uci -q get wireless.@wifi-iface["${cnt}"].network)" ] - do - if [ "$(uci -q get wireless.@wifi-iface["${cnt}"].network)" = "${iface}" ] - then + while [ -n "$(uci -q get wireless.@wifi-iface["${cnt}"].network)" ]; do + if [ "$(uci -q get wireless.@wifi-iface["${cnt}"].network)" = "${iface}" ]; then uci -q set wireless.@wifi-iface["${cnt}"].network="${input}" fi - cnt=$((cnt+1)) + cnt=$((cnt + 1)) done uci -q commit wireless fi @@ -192,8 +173,7 @@ service_triggers() delay="$(uci_get travelmate global trm_triggerdelay "2")" PROCD_RELOAD_DELAY=$((delay * 1000)) - if [ -n "${iface}" ] - then + if [ -n "${iface}" ]; then procd_add_interface_trigger "interface.*.down" "${iface}" "${trm_init}" reload fi procd_add_raw_trigger "interface.*.up" "${PROCD_RELOAD_DELAY}" "${trm_init}" start |