-
Notifications
You must be signed in to change notification settings - Fork 12
/
S60tty2oled
74 lines (68 loc) · 1.81 KB
/
S60tty2oled
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
# 2022-03-12 Ensure Unix-Encoding of INI files
# 2021-11-24 Working in /tmp
# 2021-09-09 Moved from /etc/init.d to /media/fat/tty2oled
# 2021-01-22 Added -x /usr/bin/tty2oled check to start()
# 2021-04-12 Added an INI file
# 2022-06-17 Redo/Rework of PID and inotify
#
! [ "$(dos2unix -ic /media/fat/tty2oled/*.ini)" = "" ] && dos2unix -k -q /media/fat/tty2oled/*.ini
. /media/fat/tty2oled/tty2oled-system.ini
. /media/fat/tty2oled/tty2oled-user.ini
cd /tmp
# Start
start() {
### Wait for USB module and start tty2oled daemon
WAITEND=$((SECONDS+10))
while ! [ -c ${TTYDEV} ] && [ ${SECONDS} -lt ${WAITEND} ]; do
sleep 0.1
done
if ! [ -c ${TTYDEV} ]; then
echo "Could not find the needed USB module ${TTYDEV}. Exiting."
exit 1
fi
if [[ -x ${DAEMONSCRIPT} ]]; then
if [ -e /run/tty2oled-daemon.pid ] && [ -d /proc/$(</run/tty2oled-daemon.pid) ]; then
echo "${DAEMONNAME} already running"
exit 1
else
echo "Starting ${DAEMONNAME}..."
${DAEMONSCRIPT} & echo $! > /run/tty2oled-daemon.pid
fi
else
echo "${DAEMONSCRIPT} not found!"
fi
}
# Stop
stop() {
echo "Stopping ${DAEMONNAME}..."
if [ -e /run/tty2oled-daemon.pid ]; then
PIDDAEMON=$(</run/tty2oled-daemon.pid)
PIDINOTIFY=$(ps -eo pid,ppid,args | grep $(ps | grep tty2oled | awk 'NR==1{print $1}') | tail -1 | awk '{print $1}')
#echo "PIDDAEMON = $PIDDAEMON"
#echo "PIDINOTIFY = $PIDINOTIFY"
fi
[ ${PIDDAEMON} ] && kill ${PIDDAEMON} &> /dev/null
[ ${PIDINOTIFY} ] && kill ${PIDINOTIFY} &> /dev/null
rm -f /run/tty2oled-daemon.pid
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
# reload)
# reload
# ;;
*)
# echo "Usage: $0 {start|stop|restart|reload}"
echo "Usage: $0 {start|stop|restart}"
exit 1
esac