File: lirc.postinst

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 (204 lines) | stat: -rw-r--r-- 4,846 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/sh 
set -e

make_devices ()
{
	if [ ! -e /dev/lirc ]; then
		mknod /dev/lirc c 61 0
		chown root.root /dev/lirc
		chmod 660 /dev/lirc
	fi
	if [ ! -e /dev/lircd ]; then
		mknod /dev/lircd p
		chown root.root /dev/lircd
		chmod 666 /dev/lircd
	fi
	if [ ! -e /dev/lircm ]; then
		mknod /dev/lircm p
		chown root.root /dev/lircm
		chmod 666 /dev/lircm
	fi
}
DebconfLoad ()
{
	db_get lirc/driver
	LIRCD_DRIVER="$RET"
	db_get lirc/modules
	MODULES="$RET"
	db_get lirc/device
	DEVICE="$RET"
	db_get lirc/lircd_conf
	LIRCD_CONF="$RET"
	db_get lirc/lircmd_conf
	LIRCMD_CONF="$RET"
	
	#Common kernel module configuration
	db_get lirc/port
	LIRC_PORT=$RET
	db_get lirc/irq
	LIRC_IRQ=$RET
	db_get lirc/cflags
	LIRC_CFLAGS=$RET

	#lirc_parallel
	db_get lirc/timer
	LIRC_PARALLEL_TIMER=$RET
}
check_hardware_conf ()
{
	#Make sure that all variables are there, and also create the file if
	#it is not there
	local VAR
	for VAR in DRIVER MODULES DEVICE LIRCD_CONF LIRCMD_CONF
	do
		if ! grep -q "^$VAR\>" /etc/lirc/hardware.conf; then
			echo "$VAR=\"UNCONFIGURED\"" >> /etc/lirc/hardware.conf
		fi
	done
}

setup_modutils_file ()
{
	MODUTILS="$1"
	if [ ! -f "$MODUTILS" ];then
		#The file was removed, and we should not replace a deleted
		#conffile
		return
	fi

	echo "Setting up modutils file"

	OLD_LINE=""
	NEW_LINE=""
	if expr "$MODULES" : '.*_serial\>' > /dev/null; then
		OLD_LINE="^ *options *lirc_serial"
		NEW_LINE="options lirc_serial io=$LIRC_PORT irq=$LIRC_IRQ"
	elif expr "$MODULES" : '.*_sir\>' > /dev/null; then
		OLD_LINE="^ *options *lirc_sir"
		NEW_LINE="options lirc_sir io=$LIRC_PORT irq=$LIRC_IRQ"
	elif expr "$MODULES" : '.*_parallel\>' > /dev/null; then
		OLD_LINE="^ *options *lirc_parallel"
		NEW_LINE="options lirc_parallel io=$LIRC_PORT irq=$LIRC_IRQ"
	elif expr "$MODULES" : '.*_gpio\>' > /dev/null; then
		:
	elif expr "$MODULES" : '.*_it87\>' > /dev/null; then
		:
	elif expr "$MODULES" : '.*_bt829\>' > /dev/null; then
		:
	elif expr "$MODULES" : '.*_i2c\>' > /dev/null; then
		:
	fi
	ADD_OPTIONS=$(grep "^ *add *options" "$MODUTILS" || true)
	if [ "$OLD_LINE" ]; then
		sed -e "/^ *add *options/D
			/$OLD_LINE/D
			" "$MODUTILS" > "$MODUTILS".tmp
		mv "$MODUTILS".tmp "$MODUTILS"
	fi
	if [ "$NEW_LINE" ]; then
		echo $NEW_LINE >> "$MODUTILS"
	fi
	echo "$ADD_OPTIONS" >> "$MODUTILS"
}

Save ()
{
	check_hardware_conf

	sed -e "
		s|^\(DRIVER\)=.*|\1=\"$LIRCD_DRIVER\"|;
		s|^\(MODULES\)=.*|\1=\"$MODULES\"|;
		s|^\(DEVICE\)=.*|\1=\"$DEVICE\"|;
		s|^\(LIRCD_CONF\)=.*|\1=\"$LIRCD_CONF\"|;
		s|^\(LIRCMD_CONF\)=.*|\1=\"$LIRCMD_CONF\"|;
		" $1 > $1.tmp
#		s|^\(PORT\)=.*|\1=\"$LIRC_PORT\"|;
#		s|^\(IRQ\)=.*|\1=\"$LIRC_IRQ\"|;
#		s|^\(TIMER\)=.*|\1=\"$TIMER\"|;
#		s|^\(CFLAGS\)=.*|\1=\"$CFLAGS\"|;
	mv $1.tmp $1

}

. /usr/share/debconf/confmodule

if [ "$1" = "configure" ]; then
	[ -x /usr/sbin/update-devfsd ] && /usr/sbin/update-devfsd >&2
	db_get lirc/install_devices
	if $RET; then
		make_devices
	fi

	db_fget lirc/reconfigure config_changed
	CONFIG_CHANGED=$RET
	db_fset lirc/reconfigure config_changed false

	if $CONFIG_CHANGED || [ -f /etc/lirc/hardware.conf ];then
		check_hardware_conf
		. /etc/lirc/hardware.conf
	fi

	if $CONFIG_CHANGED || [ "$DRIVER" = "UNCONFIGURED" ]; then
		DebconfLoad
		Save /etc/lirc/hardware.conf
	fi
	db_fget lirc/reconfigure modutils_gen_first_time
	if $CONFIG_CHANGED || ! $RET; then
		DebconfLoad
		setup_modutils_file /etc/modutils/lirc
		db_fset lirc/reconfigure modutils_gen_first_time true
	fi

	# If we don't have a valid lircd.conf try to get one
	if [ ! -f /etc/lirc/lircd.conf ] \
		|| grep -q "^#UNCONFIGURED" /etc/lirc/lircd.conf ;then
		db_get lirc/lircd_conf

		# if there is a misplaced config file it is ok to move it to
		# the right place
		if [ -f /etc/lircd.conf ];then 
			echo moving /etc/lircmd.conf to /etc/lirc/
			mv /etc/lircd.conf /etc/lirc/

		# we don't restore the file unless the user is (re)configuring
		elif $CONFIG_CHANGED \
			&& [ -f "/usr/share/lirc/remotes/$RET" ];then
			echo trying default lircd.conf
			cp /usr/share/lirc/remotes/$RET \
				/etc/lirc/lircd.conf
		fi
	fi
	# If we don't have a valid lircmd.conf try to get one
	if [ ! -f /etc/lirc/lircmd.conf ] \
		|| grep -q "^#UNCONFIGURED" /etc/lirc/lircmd.conf ;then
		db_get lirc/lircmd_conf

		# if there is a misplaced config file it is ok to move it to
		# the right place
		if [ -f /etc/lircmd.conf ];then 
			echo moving /etc/lircmd.conf to /etc/lirc/
			mv /etc/lircmd.conf /etc/lirc/

		# we don't restore the file unless the user is (re)configuring
		elif $CONFIG_CHANGED \
			&& [ -f "/usr/share/lirc/remotes/$RET" ];then
			echo trying default lircmd.conf
			cp /usr/share/lirc/remotes/$RET \
				/etc/lirc/lircmd.conf
		fi
	fi
	if [ -f /var/log/lircd ]
	then
		db_get lirc/remove_var-log-lircd
		if $RET 
		then 
			rm /var/log/lircd
		fi
	fi
fi


db_stop

#DEBHELPER#