-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathflashair-network
executable file
·53 lines (41 loc) · 1.66 KB
/
flashair-network
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
#!/usr/bin/env bash
# ---------------------------------------------------
# Flashair SD Card wifi network detection
#
# Revision history :
# 30/03/2017, V1.0 - Creation by N. Bernaerts
# 12/08/2017, V1.1 - Restrict disconnect condition
# ---------------------------------------------------
# load flashair environment variables
. /usr/local/sbin/flashair-common
# check if connected to flashair wifi network
FLASHAIR_INTERFACE=$(iwconfig | grep "ESSID" | grep "${FLASHAIR_NAME}_" | cut -d' ' -f1)
# check if flashair daemon is running
start-stop-daemon --status --name "${FLASHAIR_DAEMON_NAME}"
FLASHAIR_DAEMON_STATUS=$?
echo "flashair network - ${FLASHAIR_DAEMON_NAME} status ${FLASHAIR_DAEMON_STATUS}" >> /tmp/flash.log
# if connected to flashair wifi network and daemon not running
if [ "${FLASHAIR_INTERFACE}" != "" -a "${FLASHAIR_DAEMON_STATUS}" != "0" ]
then
# create fifo
rm -f "${FLASHAIR_FIFO}"
mkfifo "${FLASHAIR_FIFO}"
# call flashair connect command
flashair-command --connect "${FLASHAIR_INTERFACE}"
# start flashair daemon
start-stop-daemon --start --background --exec "${FLASHAIR_DAEMON_PATH}"
# else, if not connected to flashair wifi network and daemon is running
elif [ "${FLASHAIR_INTERFACE}" = "" -a "${FLASHAIR_DAEMON_STATUS}" = "0" ]
then
# get processes ID
PID_DAEMON=$(pgrep "${FLASHAIR_DAEMON_NAME}")
PID_INOTIFY=$(pgrep --parent ${PID_DAEMON} "inotifywait")
# stop inotifywait child process
[ "${PID_INOTIFY}" != "" ] && kill -9 ${PID_INOTIFY}
# stop flashair daemon
start-stop-daemon --stop --name "${FLASHAIR_DAEMON_NAME}"
# call flashair disconnect command
flashair-command --disconnect
# delete fifo
rm -f "${FLASHAIR_FIFO}"
fi