From 37d7841f35913697aa39c00db9b08ce49e59d71b Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Sat, 4 Mar 2017 20:30:04 +0100 Subject: [PATCH] travelmate: update 0.4.1 * mute useless logging in "active mode" * optimize startup behaviour * cosmetics Signed-off-by: Dirk Brenken --- net/travelmate/Makefile | 2 +- net/travelmate/files/travelmate.init | 9 +++-- net/travelmate/files/travelmate.sh | 49 ++++++++++++++++------------ 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/net/travelmate/Makefile b/net/travelmate/Makefile index c16bfc8a9..2e952968b 100644 --- a/net/travelmate/Makefile +++ b/net/travelmate/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=travelmate -PKG_VERSION:=0.4.0 +PKG_VERSION:=0.4.1 PKG_RELEASE:=1 PKG_LICENSE:=GPL-3.0+ PKG_MAINTAINER:=Dirk Brenken diff --git a/net/travelmate/files/travelmate.init b/net/travelmate/files/travelmate.init index 71afc0dd1..ca318326c 100755 --- a/net/travelmate/files/travelmate.init +++ b/net/travelmate/files/travelmate.init @@ -1,15 +1,20 @@ #!/bin/sh /etc/rc.common -START=85 +START=90 USE_PROCD=1 trm_script="/usr/bin/travelmate.sh" +boot() +{ + ubus -t 30 wait_for network.interface + rc_procd start_service +} + start_service() { if [ $(/etc/init.d/travelmate enabled; printf ${?}) -eq 0 ] then - ubus -t 30 wait_for network.interface procd_open_instance "travelmate" procd_set_param command "${trm_script}" "${@}" procd_set_param stdout 1 diff --git a/net/travelmate/files/travelmate.sh b/net/travelmate/files/travelmate.sh index 1a9131de5..df4a970ce 100755 --- a/net/travelmate/files/travelmate.sh +++ b/net/travelmate/files/travelmate.sh @@ -6,11 +6,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# prepare environment +# set initial defaults # LC_ALL=C PATH="/usr/sbin:/usr/bin:/sbin:/bin" -trm_ver="0.4.0" +trm_ver="0.4.1" +trm_sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')" trm_enabled=1 trm_debug=0 trm_active=0 @@ -19,6 +20,8 @@ trm_maxretry=3 trm_timeout=60 trm_iw=1 +# f_envload: load travelmate environment +# f_envload() { # source required system libraries @@ -60,7 +63,7 @@ f_envload() fi } -# function to bring down all STA interfaces +# f_prepare: gather radio information & bring down all STA interfaces # f_prepare() { @@ -84,6 +87,8 @@ f_prepare() f_log "debug" "mode: ${mode}, radio: ${radio}, config: ${config}, disabled: ${disabled}" } +# f_check: check interface status +# f_check() { local ifname radio cnt=1 mode="${1}" @@ -123,7 +128,17 @@ f_check() f_log "debug" "mode: ${mode}, name: ${ifname}, status: ${trm_ifstatus}, count: ${cnt}, max-wait: ${trm_maxwait}" } -# function to write to syslog +# f_active: keep travelmate in an active state +# +f_active() +{ + if [ ${trm_active} -eq 1 ] + then + (sleep ${trm_timeout}; /etc/init.d/travelmate start >/dev/null 2>&1) & + fi +} + +# f_log: function to write to syslog # f_log() { @@ -135,21 +150,23 @@ f_log() logger -t "travelmate-[${trm_ver}] ${class}" "${log_msg}" if [ "${class}" = "error" ] then - logger -t "travelmate-[${trm_ver}] ${class}" "Please check the online documentation 'https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md'" + logger -t "travelmate-[${trm_ver}] ${class}" "Please check the readme 'https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md' (${trm_sysver})" + f_active exit 255 fi fi } +# f_main: main function for connection handling +# f_main() { local ssid_list config ap_radio sta_radio ssid cnt=1 - local sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')" - f_log "info " "start travelmate scanning ..." f_check "initial" if [ "${trm_ifstatus}" != "true" ] then + f_log "info " "start travelmate scanning ..." config_load wireless config_foreach f_prepare wifi-iface if [ -n "$(uci -q changes wireless)" ] @@ -198,37 +215,29 @@ f_main() f_check "sta" if [ "${trm_ifstatus}" = "true" ] then - f_log "info " "wwan interface connected to uplink ${ssid} (${cnt}/${trm_maxretry}, ${sysver})" + f_log "info " "wwan interface connected to uplink ${ssid} (${cnt}/${trm_maxretry}, ${trm_sysver})" sleep 5 return 0 else uci -q set wireless."${config}".disabled=1 uci -q commit wireless ubus call network reload - f_log "info " "wwan interface can't connect to uplink ${ssid} (${cnt}/${trm_maxretry}, ${sysver})" + f_log "info " "wwan interface can't connect to uplink ${ssid} (${cnt}/${trm_maxretry}, ${trm_sysver})" fi fi done else - f_log "info " "empty uplink list (${cnt}/${trm_maxretry}, ${sysver})" + f_log "info " "empty uplink list (${cnt}/${trm_maxretry}, ${trm_sysver})" fi cnt=$((cnt+1)) sleep 5 done done - f_log "info " "no wwan uplink found (${sysver})" - else - f_log "info " "wwan uplink still connected (${sysver})" + f_log "info " "no wwan uplink found (${trm_sysver})" fi } f_envload f_main - -# keep travelmate in an active state -# -if [ ${trm_active} -eq 1 ] -then - (sleep ${trm_timeout}; /etc/init.d/travelmate start >/dev/null 2>&1) & -fi +f_active exit 0