~mythbuntu-dev/lirc/ubuntu

1 by Mario Limonciello
add hardy's debian/ directory
1
#! /bin/sh
2
### BEGIN INIT INFO
3
# Provides:          lirc
65 by Mario Limonciello
merge lirc.init.d from debian (yeah not a lot of changes. their's begs for improvement
4
# Required-Start:    $remote_fs $syslog
5
# Required-Stop:     $remote_fs $syslog
1 by Mario Limonciello
add hardy's debian/ directory
6
# Default-Start:     2 3 4 5
7
# Default-Stop:      0 1 6
8
# Short-Description: Starts LIRC daemon.
9
# Description:       LIRC is used to control different
10
#                    infrared receivers and transceivers.
11
### END INIT INFO
12
13
load_modules ()
14
{
115 by Mario Limonciello
* lirc.init.d:
15
	MODULES_MISSING=false
16
17
	log_daemon_msg "Loading LIRC modules"
18
	for mod in $*; do
19
		if [ $mod = "udev" ]; then
20
			log_end_msg 0
21
			log_success_msg "Restarted via udev, don't reload modules"
22
			break
23
		else
24
			modprobe $mod 2> /dev/null || MODULES_MISSING=true
25
		fi
26
	done
27
	log_end_msg $?
28
29
	if $MODULES_MISSING; then
30
		log_failure_msg "Unable to load LIRC kernel modules. Verify your"
31
		log_failure_msg "selected kernel modules in /etc/lirc/hardware.conf"
32
		START_LIRCMD=false
33
		START_LIRCD=false
34
	fi
1 by Mario Limonciello
add hardy's debian/ directory
35
}
36
37
build_remote_args ()
38
{
115 by Mario Limonciello
* lirc.init.d:
39
	REMOTE_ARGS="$*"
40
41
	#For remote only detection support, we need
42
	#both REMOTE_DEVICE and TRANSMITTER_DEVICE undefined
43
	if [ -z "$REMOTE_DEVICE" ] && [ -z "$TRANSMITTER_DEVICE" ] && [ -c $dev ]; then
44
		REMOTE_DEVICE="$dev"
45
	fi
46
47
	#If we have a REMOTE_DEVICE or REMOTE_DRIVER defined (either because no devices
48
	#were defined, OR if we explicitly did), then populate REMOTE_ARGS
49
	if [ ! -z "$REMOTE_DEVICE" ] || [ ! -z "$REMOTE_DRIVER" ]; then
50
		if [ -n "$REMOTE_DEVICE" ] && [ "$REMOTE_DEVICE" != "none" ]; then
51
			REMOTE_ARGS="--device=$REMOTE_DEVICE $REMOTE_ARGS"
52
		fi
53
		if [ -n "$REMOTE_DRIVER" ] && [ "$REMOTE_DRIVER" != "none" ]; then
54
			REMOTE_ARGS="--driver=$REMOTE_DRIVER $REMOTE_ARGS"
55
		fi
56
57
		#Now, if we ALSO have a transmitter defined, add some args
58
		#To make the first lircd listen up
59
		if [ ! -z "$TRANSMITTER_DEVICE" ] || [ ! -z "$TRANSMITTER_DRIVER" ]; then
118 by Mario Limonciello
Merge with Jeremy Yoder's tree to bump to 0.8.6 CVS
60
			REMOTE_ARGS="$REMOTE_ARGS --listen"
115 by Mario Limonciello
* lirc.init.d:
61
		fi
118 by Mario Limonciello
Merge with Jeremy Yoder's tree to bump to 0.8.6 CVS
62
		REMOTE_ARGS="--output=$REMOTE_SOCKET $REMOTE_ARGS"
115 by Mario Limonciello
* lirc.init.d:
63
	fi
64
	echo $REMOTE_ARGS
1 by Mario Limonciello
add hardy's debian/ directory
65
}
66
67
build_transmitter_args ()
68
{
115 by Mario Limonciello
* lirc.init.d:
69
	TRANSMITTER_ARGS="$*"
70
71
	#Transmitters must be explicitly be defined
72
	if [ ! -z "$TRANSMITTER_DEVICE" ] || [ ! -z "$TRANSMITTER_DRIVER" ]; then
73
		if [ -n "$TRANSMITTER_DEVICE" ] && [ "$TRANSMITTER_DEVICE" != "none" ]; then
74
			TRANSMITTER_ARGS="--device=$TRANSMITTER_DEVICE $TRANSMITTER_ARGS"
75
		fi
76
		if [ -n "$TRANSMITTER_DRIVER" ] && [ "$TRANSMITTER_DRIVER" != "none" ]; then
77
			TRANSMITTER_ARGS="--driver=$TRANSMITTER_DRIVER $TRANSMITTER_ARGS"
78
		fi
79
80
		#Now, if we ALSO have a remote defined, add some args
81
		#To make the second lircd connect
82
		if [ ! -z "$REMOTE_DEVICE" ] || [ ! -z "$REMOTE_DRIVER" ]; then
118 by Mario Limonciello
Merge with Jeremy Yoder's tree to bump to 0.8.6 CVS
83
			TRANSMITTER_ARGS="$TRANSMITTER_ARGS --connect=localhost:8765 --pidfile=/var/run/lirc/lircd1.pid"
115 by Mario Limonciello
* lirc.init.d:
84
		fi
118 by Mario Limonciello
Merge with Jeremy Yoder's tree to bump to 0.8.6 CVS
85
		TRANSMITTER_ARGS="--output=$TRANSMITTER_SOCKET $TRANSMITTER_ARGS"
115 by Mario Limonciello
* lirc.init.d:
86
	fi
87
	echo $TRANSMITTER_ARGS
1 by Mario Limonciello
add hardy's debian/ directory
88
}
89
143 by Mario Limonciello
Disable in-kernel-support when starting lircd, and re-enable when
90
in_kernel_support() {
151 by Mario Limonciello
For disabling other protocols, adjust to the new location in 2.6.37.
91
	if [ -d /sys/class/rc ]; then
92
		for file in `find /sys/class/rc/*/ -name protocols`; do
93
			if [ "$1" = "disable" ]; then
94
				echo "lirc" > $file
95
			else
96
				echo "none" > $file
97
				for protocol in `cat $file`; do
98
					echo "+${protocol}" > $file
99
				done
100
			fi
143 by Mario Limonciello
Disable in-kernel-support when starting lircd, and re-enable when
101
		done
147 by Mario Limonciello
Don't show init script errors if no remote is plugged in.
102
	fi
143 by Mario Limonciello
Disable in-kernel-support when starting lircd, and re-enable when
103
}
1 by Mario Limonciello
add hardy's debian/ directory
104
. /lib/lsb/init-functions
105
106
test -f /usr/sbin/lircd || exit 0
107
test -f /usr/sbin/lircmd || exit 0
108
109
START_LIRCMD=true
110
START_LIRCD=true
102 by Mario Limonciello
add system-wide irexec support from debian
111
START_IREXEC=true
112
1 by Mario Limonciello
add hardy's debian/ directory
113
114
if [ -f /etc/lirc/hardware.conf ];then
115 by Mario Limonciello
* lirc.init.d:
115
	. /etc/lirc/hardware.conf
116
fi
117
118
if [ ! -f /etc/lirc/lircd.conf ] || grep -q "^#UNCONFIGURED" /etc/lirc/lircd.conf; then
119
	if [ "$1" = "start" ]; then
120
		log_success_msg "No valid /etc/lirc/lircd.conf has been found."
121
		log_success_msg "Remote control support has been disabled."
122
		log_success_msg "Reconfigure LIRC or manually replace /etc/lirc/lircd.conf to enable."
123
	fi
124
125
	START_LIRCD=false
126
	START_LIRCMD=false
127
	START_IREXEC=false
128
fi
129
130
if [ ! -f /etc/lirc/lircmd.conf ] || grep -q "^#UNCONFIGURED" /etc/lirc/lircmd.conf; then
131
	START_LIRCMD=false
132
fi
133
134
if [ ! -f /etc/lirc/lircrc ] || grep -q "^#UNCONFIGURED" /etc/lirc/lircrc; then
135
	START_IREXEC=false
136
fi
137
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
138
#We need default socket locations
139
OLD_SOCKET="/dev/lircd"
140
if [ -z "$REMOTE_SOCKET" ]; then
141
	REMOTE_SOCKET="/var/run/lirc/lircd"
142
fi
143
if [ -z "$TRANSMITTER_SOCKET" ]; then
144
	TRANSMITTER_SOCKET="/var/run/lirc/lircd"
114.1.15 by Jeremy Yoder
* Fix /regression in /etc/init.d/lirc where if both REMOTE and TRANSMITTER
145
	#Now, if we ALSO have a remote defined,
146
	#change the default transmitter socket
147
	if [ ! -z "$REMOTE_DEVICE" ] || [ ! -z "$REMOTE_DRIVER" ]; then
148
		TRANSMITTER_SOCKET="${TRANSMITTER_SOCKET}1"
149
	fi
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
150
fi
102 by Mario Limonciello
add system-wide irexec support from debian
151
1 by Mario Limonciello
add hardy's debian/ directory
152
case "$1" in
115 by Mario Limonciello
* lirc.init.d:
153
	start)
154
		if [ "$LOAD_MODULES" = "true" ] && [ "$START_LIRCD" = "true" ]; then
155
			load_modules $2 $REMOTE_MODULES $TRANSMITTER_MODULES $MODULES
143 by Mario Limonciello
Disable in-kernel-support when starting lircd, and re-enable when
156
			in_kernel_support "disable"
115 by Mario Limonciello
* lirc.init.d:
157
		fi
158
159
		if [ "$START_LIRCD" = "true" ]; then
118 by Mario Limonciello
Merge with Jeremy Yoder's tree to bump to 0.8.6 CVS
160
			[ -d "/var/run/lirc" ] || mkdir -p "/var/run/lirc"
115 by Mario Limonciello
* lirc.init.d:
161
			log_daemon_msg "Starting remote control daemon(s) : LIRC "
162
			REMOTE_LIRCD_ARGS=`build_remote_args $REMOTE_LIRCD_ARGS`
163
			TRANSMITTER_LIRCD_ARGS=`build_transmitter_args $TRANSMITTER_LIRCD_ARGS`
164
165
			#if we have a remote defined, it is primary process
166
			if [ ! -z "$REMOTE_LIRCD_ARGS" ]; then
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
167
				start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/lircd -- $REMOTE_LIRCD_ARGS < /dev/null
115 by Mario Limonciello
* lirc.init.d:
168
				log_end_msg $?
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
169
				if [ -S "$REMOTE_SOCKET" -a "$OLD_SOCKET" != "$REMOTE_SOCKET" ]; then
170
					rm -f $OLD_SOCKET && ln -s $REMOTE_SOCKET $OLD_SOCKET
171
				fi 
115 by Mario Limonciello
* lirc.init.d:
172
173
				#now if we additionally have a transmitter defined, it is secondary process
174
				if [ ! -z "$TRANSMITTER_LIRCD_ARGS" ]; then
175
					/usr/sbin/lircd $TRANSMITTER_LIRCD_ARGS < /dev/null
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
176
					if [ -S "$TRANSMITTER_SOCKET" ]; then
177
						rm -f ${OLD_SOCKET}1 && ln -s $TRANSMITTER_SOCKET ${OLD_SOCKET}1
178
					fi 
115 by Mario Limonciello
* lirc.init.d:
179
				fi
180
			elif [ ! -z "$TRANSMITTER_LIRCD_ARGS" ]; then
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
181
				start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/lircd -- $TRANSMITTER_LIRCD_ARGS < /dev/null
182
				log_end_msg $?
183
				if [ -S "$TRANSMITTER_SOCKET" -a "$OLD_SOCKET" != "$TRANSMITTER_SOCKET" ]; then
184
					rm -f $OLD_SOCKET && ln -s $TRANSMITTER_SOCKET $OLD_SOCKET
185
				fi 
115 by Mario Limonciello
* lirc.init.d:
186
			else
187
				log_end_msg 1
188
			fi
189
		fi
190
191
		if [ "$START_LIRCMD" = "true" ]; then
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
192
			[ -d "/var/run/lirc" ] || mkdir -p "/var/run/lirc"
115 by Mario Limonciello
* lirc.init.d:
193
			log_daemon_msg "Starting remote control mouse daemon : LIRCMD "
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
194
			start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/lircmd < /dev/null
115 by Mario Limonciello
* lirc.init.d:
195
			log_end_msg $?
196
		fi
197
198
		if [ "$START_IREXEC" = "true" ]; then
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
199
			[ -d "/var/run/lirc" ] || mkdir -p "/var/run/lirc"
115 by Mario Limonciello
* lirc.init.d:
200
			log_daemon_msg "Starting execution daemon: irexec"
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
201
			start-stop-daemon --start --quiet --oknodo --exec /usr/bin/irexec -- -d /etc/lirc/lircrc < /dev/null
115 by Mario Limonciello
* lirc.init.d:
202
			log_end_msg $?
203
		fi
204
		;;
205
	stop)
143 by Mario Limonciello
Disable in-kernel-support when starting lircd, and re-enable when
206
		in_kernel_support "enable"
115 by Mario Limonciello
* lirc.init.d:
207
		if [ "$START_IREXEC" = "true" ]; then
208
			log_daemon_msg "Stopping execution daemon: irexec"
209
			start-stop-daemon --stop --quiet --exec /usr/bin/irexec
210
			log_end_msg $?
211
		fi
212
213
		if [ "$START_LIRCMD" = "true" ]; then
214
			log_daemon_msg "Stopping remote control mouse daemon: LIRCMD"
215
			start-stop-daemon --stop --quiet --exec /usr/sbin/lircmd
216
			log_end_msg $?
217
		fi
218
219
		if [ "$START_LIRCD" = "true" ]; then
220
			log_daemon_msg "Stopping remote control daemon(s): LIRC"
221
			start-stop-daemon --stop --quiet --exec /usr/sbin/lircd
222
			log_end_msg $?
114.1.12 by Jeremy Yoder
Changed lirc init script to create socket in /var/run/lirc/lircd
223
			[ -h "$OLD_SOCKET" ] && rm -f $OLD_SOCKET
224
			[ -h "${OLD_SOCKET}1" ] && rm -f ${OLD_SOCKET}1
115 by Mario Limonciello
* lirc.init.d:
225
		fi
226
		;;
227
	reload|force-reload)
228
		if [ "$START_IREXEC" = "true" ]; then
229
			start-stop-daemon --stop --quiet --signal 1 --exec /usr/bin/irexec
230
		fi
231
232
		if [ "$START_LIRCD" = "true" ]; then
233
			start-stop-daemon --stop --quiet --signal 1 --exec /usr/sbin/lircd
234
		fi
235
236
		if [ "$START_LIRCMD" = "true" ]; then
237
			start-stop-daemon --stop --quiet --signal 1 --exec /usr/sbin/lircmd
238
		fi
239
		;;
240
	restart)
241
		$0 stop
242
		#passes parameter $2 which is possibly our udev paramater
243
		$0 start $2
244
		;;
245
	*)
246
		echo "Usage: /etc/init.d/lircd {start|stop|reload|restart|force-reload}"
247
	exit 1
1 by Mario Limonciello
add hardy's debian/ directory
248
esac
249
250
exit 0