travelmate: update 0.4.1 4105/head
authorDirk Brenken <dev@brenken.org>
Sat, 4 Mar 2017 19:30:04 +0000 (20:30 +0100)
committerDirk Brenken <dev@brenken.org>
Sat, 4 Mar 2017 19:30:04 +0000 (20:30 +0100)
* mute useless logging in "active mode"
* optimize startup behaviour
* cosmetics

Signed-off-by: Dirk Brenken <dev@brenken.org>
net/travelmate/Makefile
net/travelmate/files/travelmate.init
net/travelmate/files/travelmate.sh

index c16bfc8a90d797d6bd961fb3e46bb5d84940d46e..2e952968b966864319781d3a096d4ef2f5b4a78b 100644 (file)
@@ -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 <dev@brenken.org>
index 71afc0dd11568bf07a2f097b93fc56fd09aec6a7..ca318326c62d252997ac36199faf967e9a922b76 100755 (executable)
@@ -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
index 1a9131de5a26d24e2451deb5a8406b9c3857bae1..df4a970ce75c81be56ac3ba2063f0eccff4789d1 100755 (executable)
@@ -6,11 +6,12 @@
 # You should have received a copy of the GNU General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
-# 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