-
Notifications
You must be signed in to change notification settings - Fork 6
/
S60i2c2oled
68 lines (63 loc) · 1.63 KB
/
S60i2c2oled
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
#!/bin/bash
#
# /media/fat/i2c2oled/S60i2c2oled
#
# 2021-04-19 by venice
# License GPL v3
# Release based on S60tty2oled
#
SCRIPT="i2c2oled.sh"
DAEMON="/media/fat/i2c2oled/${SCRIPT}"
INITSCRIPT="/media/fat/i2c2oled/S60i2c2oled"
USERSTARTUP="/media/fat/linux/user-startup.sh"
USERSTARTUPTPL="/media/fat/linux/_user-startup.sh"
# Start
start() {
if [[ -x ${DAEMON} ]]; then
echo "Starting i2c2oled..."
${DAEMON} &
else
echo "${DAEMON} not found!"
fi
}
# Stop
stop() {
echo "Stopping i2c2oled..."
I2CINWPID=$(ps -eo pid,ppid,args | grep $(ps | grep ${SCRIPT} | awk 'NR==1{print $1}') | tail -1 | awk '{print $1}')
#echo "PID inotifywait: ${I2CINWPID}"
killall ${SCRIPT}
kill ${I2CINWPID}
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
setup)
if [ ! -e ${USERSTARTUP} ] && [ -e /etc/init.d/S99user ]; then
if [ -e ${USERSTARTUPTPL} ]; then
echo "Copying ${USERSTARTUPTPL} to ${USERSTARTUP}"
cp ${USERSTARTUPTPL} ${USERSTARTUP}
else
echo "Creating ${USERSTARTUP}"
echo -e "#!/bin/sh\n" > ${USERSTARTUP}
echo -e 'echo "***" $1 "***"' >> ${USERSTARTUP}
fi
fi
if [ $(grep -c "i2c2oled" ${USERSTARTUP}) = "0" ]; then
echo "Adding i2c2oled init to user-startup"
echo -e "\n# Startup i2c2oled" >> ${USERSTARTUP}
echo -e "[[ -e ${INITSCRIPT} ]] && ${INITSCRIPT} \$1" >> ${USERSTARTUP}
fi
;;
*)
echo "Usage: $0 {start|stop|restart|setup}"
exit 1
;;
esac