Skip to content

Commit d9e2d8b

Browse files
author
Holger Meyers
committed
Added install/uninstall options to Makefile to ease installation
1 parent 7fc276e commit d9e2d8b

File tree

5 files changed

+366
-1
lines changed

5 files changed

+366
-1
lines changed

Makefile

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
##########################################################################
22
# Configurable options #
33
##########################################################################
4+
# Install Base location
5+
PREFIX=/usr/local
6+
# Bin Dir
7+
BINDIR=$(PREFIX)/sbin
48
# Set the name of predictable tty
59
TTY_NAME := /dev/ttyMySensorsGateway
610
# Set the group name for the raw tty
7-
TTY_GROUPNAME := dialout
11+
TTY_GROUPNAME := tty
812
##########################################################################
913
# Please do not change anything below this line #
1014
##########################################################################
@@ -61,3 +65,42 @@ ${GATEWAY_SERIAL}: ${OBJS} ${GATEWAY_SERIAL_OBJS}
6165
clean:
6266
rm -rf $(PROGRAMS) $(GATEWAY) $(GATEWAY_SERIAL) ${OBJS} $(GATEWAY_OBJS) $(GATEWAY_SERIAL_OBJS)
6367

68+
install: all install-gatewayserial install-gateway install-initscripts
69+
70+
install-gatewayserial:
71+
@echo "Installing ${GATEWAY_SERIAL} to ${BINDIR}"
72+
@install -m 0755 ${GATEWAY_SERIAL} ${BINDIR}
73+
74+
install-gateway:
75+
@echo "Installing ${GATEWAY} to ${BINDIR}"
76+
@install -m 0755 ${GATEWAY} ${BINDIR}
77+
78+
install-initscripts:
79+
@echo "Installing initscripts to /etc/init.d"
80+
@install -m 0755 initscripts/PiGatewaySerial /etc/init.d
81+
@install -m 0755 initscripts/PiGateway /etc/init.d
82+
@echo "Installing syslog config to /etc/rsyslog.d"
83+
@install -m 0755 initscripts/30-PiGatewaySerial.conf /etc/rsyslog.d
84+
@install -m 0755 initscripts/30-PiGateway.conf /etc/rsyslog.d
85+
@service rsyslog restart
86+
87+
enable-gw: install
88+
@update-rc.d PiGateway defaults
89+
90+
enable-gwserial: install
91+
@update-rc.d PiGatewaySerial defaults
92+
93+
remove-gw:
94+
@update-rc.d -f PiGateway remove
95+
96+
remove-gwserial:
97+
@update-rc.d -f PiGatewaySerial remove
98+
99+
uninstall: remove-gw remove-gwserial
100+
@echo "Stopping daemon PiGatewaySerial (ignore errors)"
101+
-@service PiGatewaySerial stop
102+
@echo "Stopping daemon PiGateway (ignore errors)"
103+
-@service PiGateway stop
104+
@echo "removing files"
105+
rm ${BINDIR}/PiGatewaySerial ${BINDIR}/PiGateway /etc/init.d/PiGatewaySerial /etc/init.d/PiGateway /etc/rsyslog.d/30-PiGatewaySerial.conf /etc/rsyslog.d/30-PiGateway.conf
106+

initscripts/30-PiGateway.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if $programname == 'PiGateway' then /var/log/PiGateway.log
2+
& ~

initscripts/30-PiGatewaySerial.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if $programname == 'PiGatewaySerial' then /var/log/PiGatewaySerial.log
2+
& ~

initscripts/PiGateway

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#! /bin/sh
2+
### BEGIN INIT INFO
3+
# Provides: PiGateway
4+
# Required-Start: $remote_fs $syslog
5+
# Required-Stop: $remote_fs $syslog
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop: 0 1 6
8+
# Short-Description: MySensors Gateway
9+
# Description: This file should be used to construct scripts to be
10+
# placed in /etc/init.d.
11+
### END INIT INFO
12+
13+
# Author: Foo Bar <[email protected]>
14+
#
15+
# Please remove the "Author" lines above and replace them
16+
# with your own name if you copy and modify this script.
17+
18+
# Do NOT "set -e"
19+
20+
# PATH should only include /usr/* if it runs after the mountnfs.sh script
21+
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
22+
DESC="MySensors Gateway"
23+
NAME=PiGateway
24+
DAEMON=/usr/local/sbin/$NAME
25+
DAEMON_ARGS="-d"
26+
PIDFILE=/var/run/$NAME.pid
27+
SCRIPTNAME=/etc/init.d/$NAME
28+
29+
# Exit if the package is not installed
30+
[ -x "$DAEMON" ] || exit 0
31+
32+
# Read configuration variable file if it is present
33+
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
34+
35+
# Load the VERBOSE setting and other rcS variables
36+
. /lib/init/vars.sh
37+
38+
# Define LSB log_* functions.
39+
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
40+
# and status_of_proc is working.
41+
. /lib/lsb/init-functions
42+
43+
#
44+
# Function that starts the daemon/service
45+
#
46+
do_start()
47+
{
48+
# Return
49+
# 0 if daemon has been started
50+
# 1 if daemon was already running
51+
# 2 if daemon could not be started
52+
start-stop-daemon --start --quiet --exec $DAEMON --test > /dev/null \
53+
|| return 1
54+
start-stop-daemon --start --quiet --exec $DAEMON -- \
55+
$DAEMON_ARGS \
56+
|| return 2
57+
# Add code here, if necessary, that waits for the process to be ready
58+
# to handle requests from services started subsequently which depend
59+
# on this one. As a last resort, sleep for some time.
60+
}
61+
62+
#
63+
# Function that stops the daemon/service
64+
#
65+
do_stop()
66+
{
67+
# Return
68+
# 0 if daemon has been stopped
69+
# 1 if daemon was already stopped
70+
# 2 if daemon could not be stopped
71+
# other if a failure occurred
72+
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --name $NAME
73+
RETVAL="$?"
74+
[ "$RETVAL" = 2 ] && return 2
75+
# Wait for children to finish too if this is a daemon that forks
76+
# and if the daemon is only ever run from this initscript.
77+
# If the above conditions are not satisfied then add some other code
78+
# that waits for the process to drop all resources that could be
79+
# needed by services started subsequently. A last resort is to
80+
# sleep for some time.
81+
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
82+
[ "$?" = 2 ] && return 2
83+
# Many daemons don't delete their pidfiles when they exit.
84+
rm -f $PIDFILE
85+
return "$RETVAL"
86+
}
87+
88+
#
89+
# Function that sends a SIGHUP to the daemon/service
90+
#
91+
do_reload() {
92+
#
93+
# If the daemon can reload its configuration without
94+
# restarting (for example, when it is sent a SIGHUP),
95+
# then implement that here.
96+
#
97+
start-stop-daemon --stop --signal 1 --quiet --name $NAME
98+
return 0
99+
}
100+
101+
case "$1" in
102+
start)
103+
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
104+
do_start
105+
case "$?" in
106+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
107+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
108+
esac
109+
;;
110+
stop)
111+
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
112+
do_stop
113+
case "$?" in
114+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
115+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
116+
esac
117+
;;
118+
status)
119+
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
120+
;;
121+
#reload|force-reload)
122+
#
123+
# If do_reload() is not implemented then leave this commented out
124+
# and leave 'force-reload' as an alias for 'restart'.
125+
#
126+
#log_daemon_msg "Reloading $DESC" "$NAME"
127+
#do_reload
128+
#log_end_msg $?
129+
#;;
130+
restart|force-reload)
131+
#
132+
# If the "reload" option is implemented then remove the
133+
# 'force-reload' alias
134+
#
135+
log_daemon_msg "Restarting $DESC" "$NAME"
136+
do_stop
137+
case "$?" in
138+
0|1)
139+
do_start
140+
case "$?" in
141+
0) log_end_msg 0 ;;
142+
1) log_end_msg 1 ;; # Old process is still running
143+
*) log_end_msg 1 ;; # Failed to start
144+
esac
145+
;;
146+
*)
147+
# Failed to stop
148+
log_end_msg 1
149+
;;
150+
esac
151+
;;
152+
*)
153+
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
154+
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
155+
exit 3
156+
;;
157+
esac
158+
159+
:

initscripts/PiGatewaySerial

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#! /bin/sh
2+
### BEGIN INIT INFO
3+
# Provides: PiGatewaySerial
4+
# Required-Start: $remote_fs $syslog
5+
# Required-Stop: $remote_fs $syslog
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop: 0 1 6
8+
# Short-Description: MySensors Serial Gateway
9+
# Description: This file should be used to construct scripts to be
10+
# placed in /etc/init.d.
11+
### END INIT INFO
12+
13+
# Author: Foo Bar <[email protected]>
14+
#
15+
# Please remove the "Author" lines above and replace them
16+
# with your own name if you copy and modify this script.
17+
18+
# Do NOT "set -e"
19+
20+
# PATH should only include /usr/* if it runs after the mountnfs.sh script
21+
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
22+
DESC="MySensors Serial Gateway"
23+
NAME=PiGatewaySerial
24+
DAEMON=/usr/local/sbin/$NAME
25+
DAEMON_ARGS="-d"
26+
PIDFILE=/var/run/$NAME.pid
27+
SCRIPTNAME=/etc/init.d/$NAME
28+
29+
# Exit if the package is not installed
30+
[ -x "$DAEMON" ] || exit 0
31+
32+
# Read configuration variable file if it is present
33+
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
34+
35+
# Load the VERBOSE setting and other rcS variables
36+
. /lib/init/vars.sh
37+
38+
# Define LSB log_* functions.
39+
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
40+
# and status_of_proc is working.
41+
. /lib/lsb/init-functions
42+
43+
#
44+
# Function that starts the daemon/service
45+
#
46+
do_start()
47+
{
48+
# Return
49+
# 0 if daemon has been started
50+
# 1 if daemon was already running
51+
# 2 if daemon could not be started
52+
start-stop-daemon --start --quiet --exec $DAEMON --test > /dev/null \
53+
|| return 1
54+
start-stop-daemon --start --quiet --exec $DAEMON -- \
55+
$DAEMON_ARGS \
56+
|| return 2
57+
# Add code here, if necessary, that waits for the process to be ready
58+
# to handle requests from services started subsequently which depend
59+
# on this one. As a last resort, sleep for some time.
60+
}
61+
62+
#
63+
# Function that stops the daemon/service
64+
#
65+
do_stop()
66+
{
67+
# Return
68+
# 0 if daemon has been stopped
69+
# 1 if daemon was already stopped
70+
# 2 if daemon could not be stopped
71+
# other if a failure occurred
72+
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --name $NAME
73+
RETVAL="$?"
74+
[ "$RETVAL" = 2 ] && return 2
75+
# Wait for children to finish too if this is a daemon that forks
76+
# and if the daemon is only ever run from this initscript.
77+
# If the above conditions are not satisfied then add some other code
78+
# that waits for the process to drop all resources that could be
79+
# needed by services started subsequently. A last resort is to
80+
# sleep for some time.
81+
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
82+
[ "$?" = 2 ] && return 2
83+
# Many daemons don't delete their pidfiles when they exit.
84+
rm -f $PIDFILE
85+
return "$RETVAL"
86+
}
87+
88+
#
89+
# Function that sends a SIGHUP to the daemon/service
90+
#
91+
do_reload() {
92+
#
93+
# If the daemon can reload its configuration without
94+
# restarting (for example, when it is sent a SIGHUP),
95+
# then implement that here.
96+
#
97+
start-stop-daemon --stop --signal 1 --quiet --name $NAME
98+
return 0
99+
}
100+
101+
case "$1" in
102+
start)
103+
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
104+
do_start
105+
case "$?" in
106+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
107+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
108+
esac
109+
;;
110+
stop)
111+
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
112+
do_stop
113+
case "$?" in
114+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
115+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
116+
esac
117+
;;
118+
status)
119+
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
120+
;;
121+
#reload|force-reload)
122+
#
123+
# If do_reload() is not implemented then leave this commented out
124+
# and leave 'force-reload' as an alias for 'restart'.
125+
#
126+
#log_daemon_msg "Reloading $DESC" "$NAME"
127+
#do_reload
128+
#log_end_msg $?
129+
#;;
130+
restart|force-reload)
131+
#
132+
# If the "reload" option is implemented then remove the
133+
# 'force-reload' alias
134+
#
135+
log_daemon_msg "Restarting $DESC" "$NAME"
136+
do_stop
137+
case "$?" in
138+
0|1)
139+
do_start
140+
case "$?" in
141+
0) log_end_msg 0 ;;
142+
1) log_end_msg 1 ;; # Old process is still running
143+
*) log_end_msg 1 ;; # Failed to start
144+
esac
145+
;;
146+
*)
147+
# Failed to stop
148+
log_end_msg 1
149+
;;
150+
esac
151+
;;
152+
*)
153+
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
154+
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
155+
exit 3
156+
;;
157+
esac
158+
159+
:

0 commit comments

Comments
 (0)