#
if [ "${trm_action}" = "stop" ]; then
return 0
- elif [ "${trm_enabled}" != "1" ]; then
- f_log "info" "travelmate is currently disabled, please set 'trm_enabled' to '1' to use this service"
- /etc/init.d/travelmate stop
elif [ -z "${trm_iface}" ]; then
f_log "info" "travelmate is currently not configured, please use the 'Interface Wizard' in LuCI"
/etc/init.d/travelmate stop
+ return 0
elif ! "${trm_ubuscmd}" -t "${trm_maxwait}" wait_for network.wireless network.interface."${trm_iface}" >/dev/null 2>&1; then
f_log "info" "travelmate interface '${trm_iface}' does not appear on ubus, please check your network setup"
/etc/init.d/travelmate stop
+ return 0
fi
# apply wifi-device config, commit and reload on changes
if [ -n "${log_msg}" ] && { [ "${class}" != "debug" ] || [ "${trm_debug}" = "1" ]; }; then
if [ -x "${trm_logcmd}" ]; then
- "${trm_logcmd}" -p "${class}" -t "trm-${trm_bver}[${$}]" "${log_msg::512}"
+ "${trm_logcmd}" -p "${class}" -t "trm-${trm_bver:-"-"}[${$}]" "${log_msg::512}"
else
- printf "%s %s %s\n" "${class}" "trm-${trm_bver}[${$}]" "${log_msg::512}" >&2
+ printf "%s %s %s\n" "${class}" "trm-${trm_bver:-"-"}[${$}]" "${log_msg::512}" >&2
fi
if [ "${class}" = "err" ] || [ "${class}" = "emerg" ]; then
trm_ifstatus="error"
- f_genstatus
+ [ -s "${trm_rtfile}" ] && f_genstatus
: >"${trm_pidfile}"
exit 1
fi
fi
}
-# source required system libraries
-#
-if [ -r "/lib/functions.sh" ] && [ -r "/lib/functions/network.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]; then
- . "/lib/functions.sh"
- . "/lib/functions/network.sh"
- . "/usr/share/libubox/jshn.sh"
-else
- f_log "err" "system libraries not found"
-fi
-
# reference required system utilities
#
trm_catcmd="$(f_cmd cat)"
trm_ipcalccmd="$(f_cmd ipcalc.sh)"
trm_mailcmd="$(f_cmd msmtp optional)"
-f_system
-if [ "${trm_action}" != "stop" ]; then
+# source required system libraries
+#
+if [ -r "/lib/functions.sh" ] && [ -r "/lib/functions/network.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]; then
+ . "/lib/functions.sh"
+ . "/lib/functions/network.sh"
+ . "/usr/share/libubox/jshn.sh"
+else
+ f_log "err" "system libraries not found"
+fi
+
+# initial system check
+#
+[ -S "/var/run/ubus/ubus.sock" ] && f_system
+
+# entry point
+#
+if [ -n "${trm_action}" ] && [ "${trm_action}" != "stop" ]; then
[ ! -d "/etc/travelmate" ] && f_log "err" "no travelmate config directory"
[ ! -r "/etc/config/travelmate" ] && f_log "err" "no travelmate config"
[ "$(uci_get travelmate global trm_enabled)" = "0" ] && f_log "err" "travelmate is disabled"
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
trm_funlib="/usr/lib/travelmate-functions.sh"
trm_action="${1}"
-[ -z "${trm_bver}" ] && . "${trm_funlib}"
-f_conf
+
+# source required system libraries and perform initial checks
+#
+if [ -z "${trm_bver}" ]; then
+ . "${trm_funlib}"
+ f_conf
+fi
# control travelmate actions
#
while :; do
+
+ # handle service stop and start actions, then execute main loop
+ #
if [ "${trm_action}" = "stop" ]; then
if [ -s "${trm_pidfile}" ]; then
f_log "info" "travelmate instance stopped ::: action: ${trm_action}, pid: $("${trm_catcmd}" "${trm_pidfile}")"
f_main
trm_action=""
fi
+
+ # wait for next action
+ #
while :; do
sleep "${trm_timeout}" 0 >/dev/null 2>&1
rc="${?}"