summaryrefslogtreecommitdiffstats
path: root/net/travelmate/files/travelmate-service.sh
blob: 441bcd178d9b21d61211892b427d36c78946799d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
# travelmate service script, a wlan connection manager for travel router
# Copyright (c) 2016-2026 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.

# set (s)hellcheck exceptions
# shellcheck disable=all

# initial defaults
#
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
trm_funlib="/usr/lib/travelmate-functions.sh"
trm_action="${1}"

# 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}")"
			: >"${trm_rtfile}"
			: >"${trm_pidfile}"
		fi
		break
	elif [ -n "${trm_action}" ]; then
		f_log "info" "travelmate instance started ::: action: ${trm_action}, pid: ${$}"
		f_main
		trm_action=""
	fi

	# wait for next action
	#
	while :; do
		sleep "${trm_timeout}" 0 >/dev/null 2>&1
		rc="${?}"
		if [ "${rc}" != "0" ]; then
			[ "$(f_getgw)" = "false" ] && rc="0"
		fi
		[ "${rc}" = "0" ] && break
	done
	json_cleanup
	f_conf
	f_main
done