File: init.d

package info (click to toggle)
lirc 0.7.1pre2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,852 kB
  • ctags: 2,924
  • sloc: ansic: 31,205; sh: 12,021; makefile: 631
file content (118 lines) | stat: -rw-r--r-- 3,014 bytes parent folder | download
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#! /bin/sh
#
#

load_modules ()
{
	local MODULES_MISSING=false

	for mod in $*
	do
		modprobe -k $mod 2> /dev/null || MODULES_MISSING=true
	done

	if $MODULES_MISSING; then
		echo "#####################################################"
		echo "## I couldn't load the required kernel modules     ##"
		echo "## You should install lirc-modules-source to build ##"
		echo "## kernel support for your hardware.               ##"
		echo "#####################################################"
		echo "## If this message is not appropriate you may set  ##"
		echo "## LOAD_MODULES=false in /etc/lirc/hardware.conf   ##"
		echo "#####################################################"
		START_LIRCMD=false
		START_LIRCD=false
	fi
}

build_args ()
{
	local ARGS="$*"
	if [ -n "$DEVICE" ] && [ "$DEVICE" != "none" ]; then
		if [ -d /dev/lirc ] && [ "$DEVICE" = "/dev/lirc" ];then
			#new device names
			DEVICE="/dev/lirc/0"
		fi
		ARGS="--device=$DEVICE $ARGS"
	fi
	if [ -n "$DRIVER" ] && [ "$DRIVER" != "none" ]; then
		ARGS="--driver=$DRIVER $ARGS"
	fi
	echo $ARGS
}

test -f /usr/sbin/lircd || exit 0
test -f /usr/sbin/lircmd || exit 0
#test -f /etc/lirc/lircd.conf || exit 0
#test -f /etc/lirc/lircmd.conf || exit 0

START_LIRCMD=true
START_LIRCD=true

if [ ! -f /etc/lirc/lircd.conf ] \
	|| grep -q "^#UNCONFIGURED"  /etc/lirc/lircd.conf;then
	if [ "$1" = "start" ]; then
	  echo "############################################"
	  echo "## LIRC IS NOT CONFIGURED                 ##"
	  echo "##                                        ##"
	  echo "## read /usr/share/doc/lirc/README.Debian ##"
	  echo "############################################"
	fi
	START_LIRCD=false
	START_LIRCMD=false
fi
if [ ! -f /etc/lirc/lircmd.conf ] \
	|| grep -q "^#UNCONFIGURED" /etc/lirc/lircmd.conf;then
	START_LIRCMD=false
fi

if [ -f /etc/lirc/hardware.conf ];then
	. /etc/lirc/hardware.conf
fi


case "$1" in
  start)
    if [ "$LOAD_MODULES" = "true" ] && [ "$START_LIRCD" = "true" ]; then
	load_modules $MODULES
    fi
    echo -n "Starting lirc daemon:"
    if $START_LIRCD; then
      echo -n " lircd"
      LIRCD_ARGS=`build_args $LIRCD_ARGS`
      start-stop-daemon --start --quiet --exec /usr/sbin/lircd -- $LIRCD_ARGS \
		< /dev/null
    fi
    if $START_LIRCMD; then
      echo -n " lircmd"
      start-stop-daemon --start --quiet --exec /usr/sbin/lircmd \
      		< /dev/null
    fi
    echo "."
    ;;
  stop)
    echo -n "Stopping lirc daemon:"
    echo -n " lircmd"
    start-stop-daemon --stop --quiet --exec /usr/sbin/lircmd
    echo -n " lircd"
    start-stop-daemon --stop --quiet --exec /usr/sbin/lircd
    echo "."
    ;;
  reload|force-reload)
    if $START_LIRCD; then
      start-stop-daemon --stop --quiet --signal 1 --exec /usr/sbin/lircd
    fi
    if $START_LIRCMD; then
      start-stop-daemon --stop --quiet --signal 1 --exec /usr/sbin/lircmd
    fi
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: /etc/init.d/lircd {start|stop|reload|restart|force-reload}"
    exit 1
esac

exit 0