File: postinst

package info (click to toggle)
smstools 3.1.21-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,500 kB
  • sloc: ansic: 18,624; sh: 1,196; php: 115; makefile: 42; awk: 17
file content (175 lines) | stat: -rw-r--r-- 4,239 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
#!/bin/sh
set -e

oldversion="$2"

if [ -f /usr/share/debconf/confmodule ]; then
	. /usr/share/debconf/confmodule
fi


case "$1" in
	configure)
		adduser --system --quiet --no-create-home --home /nonexistent --group smsd
		adduser --quiet smsd dialout

		# Create configuration if it is wanted
		db_get smstools/configure || true
		if [ "$RET" = 'true' ]; then
			TEMPLATE_PATH="/usr/share/smstools/conf-templates"

			# Register configuration file with ucf
			ucfr smstools /etc/smsd.conf

			# Create temp files
			CONFIG_TEMP="/etc/smsd.conf.new"
			MODEM="`mktemp`"

			# Write out temporary global configuration into temp file
			cat ${TEMPLATE_PATH}/smsd.conf.template > $CONFIG_TEMP

			db_get smstools/eventhandler || true
			if [ ! -z "$RET" ]; then
				EVENTHANDLER="$RET"
				echo $EVENTHANDLER
				sed -i "s|@EVENTHANDLER@|$EVENTHANDLER|g" $CONFIG_TEMP
				sed -i 's|# eventhandler|eventhandler|g' $CONFIG_TEMP
			fi

			# Determine which devices we need to configure

			devices=""
			for i in $(seq 1 32); do
				if db_get smstools/modems/devicename$i; then
					if [ ! -z "$RET" ]; then
						devices="$devices $i"
						devicenames="$devicenames $RET"
					fi
				fi
			done

			# Normalize device lists
			devices="`echo $devices|sed 's|^ ||g;s| $||g'`"
			devicenames="`echo $devicenames|sed 's|^ ||g;s| $||g'`"

			# Update global smsd configuration to contain modems
			DEVICES="`echo $devicenames|sed 's| |, |g'`"
			sed -i "s|@DEVICES@|$DEVICES|g" $CONFIG_TEMP

			# Create configuration for devices
			for n in $devices
			do
				cat ${TEMPLATE_PATH}/smsd.modem.template > $MODEM

				db_get smstools/modems/devicename$n || true
				DEVICENAME="$RET"
				sed -i "s|@DEVICENAME@|$DEVICENAME|g" $MODEM

				db_get smstools/modems/devicenode$n || true
				if [ ! "$RET" = 'Other' ]
				then
					DEVICENODE="$RET"
				else
					db_get smstools/modems/devicenodeother$n || true
					DEVICENODE="$RET"
				fi

				sed -i "s|@DEVICE@|$DEVICENODE|g" $MODEM


				db_get smstools/modems/deviceinit$n || true
				if [ -z "$RET" ]
				then
					INIT=''
					sed -i 's|init = |#init = |g' $MODEM
				else
					INIT="$RET"
				fi
				sed -i "s|@INIT@|$INIT|g" $MODEM

				db_get smstools/modems/deviceincoming$n || true
				if [ -z "$RET" ]
				then
					INCOMING="yes"
				else
					if [ "$RET" = 'true' ]
					then
						INCOMING='yes'
					else
						INCOMING='no'
					fi
				fi
				sed -i "s|@INCOMING@|$INCOMING|g" $MODEM

				db_get smstools/modems/devicepin$n || true
				if [ -z "$RET" ]
				then
					PIN=''
					sed -i 's|pin = |#pin = |g' $MODEM
				else
					PIN="$RET"
				fi
				sed -i "s|@PIN@|$PIN|g" $MODEM

				db_get smstools/modems/devicebaudrate$n || true

				if [ "$RET" = 'Other' ]; then
					db_get smstools/modems/devicebaudrateother$n || true
				fi

				if [ -z "$RET" ]
				then
					BAUDRATE='19200'
				else
					BAUDRATE="$RET"
				fi
				sed -i "s|@BAUDRATE@|$BAUDRATE|g" $MODEM

				cat $MODEM >> $CONFIG_TEMP
				rm $MODEM
			done

			sed -i "s|Last changed: .*|Last changed: `date`|g" $CONFIG_TEMP

			if [ -f /etc/smsd.conf ]; then
				ucf --debconf-ok /etc/smsd.conf.new /etc/smsd.conf
				rm -f /etc/smsd.conf.new
			else
				mv /etc/smsd.conf.new /etc/smsd.conf
			fi

			rm -f $MODEM

		fi

        if [ -f /var/log/smsd.log ]; then
            ln -s /var/log/smstools/smsd.log /var/log/smsd.log 2> /dev/null || true
            mv /var/log/smsd.log /var/log/smstools/smsd.log 2>/dev/null || true
        fi

        if [ -d /var/log/smsd_stats ]; then
            ln -s /var/log/smstools/smsd_stats /var/log/smsd_stats 2> /dev/null || true
            mv /var/log/smsd_stats /var/log/smstools/smsd_stats 2>/dev/null || true
        fi

		# Fix permissions
		for i in /var/log/smstools; do
			if ! dpkg-statoverride --list $i >/dev/null 2>&1 ; then
				dpkg-statoverride --update --add smsd smsd 2755 $i
			fi
		done

		if ! dpkg-statoverride --list /var/log/smstools/smsd_stats >/dev/null 2>&1 ; then
		    dpkg-statoverride --update --add smsd smsd 0755 /var/log/smstools/smsd_stats
		fi

		for i in `find /var/spool/sms -type d`; do
			if ! dpkg-statoverride --list $i >/dev/null 2>&1 ; then
				dpkg-statoverride --update --add smsd smsd 3775 $i
			fi
		done
	;;
esac

#DEBHELPER#