Debian Codegraph @

debian/postinst

raw
1 #!/bin/sh
2
3 set -e
4
5 # source debconf library.
6 . /usr/share/debconf/confmodule
7
8 # location of the configfile
9 configfile="/etc/cvsd/cvsd.conf"
10
11 # location of the file that will be edited
12 # only when editing is complete will $configfile be overwritten
13 tmpconfigfile=`mktemp`
14
15 # location of the file that will be used temporarily
16 tmpfile=`mktemp`
17
18 # create cvsd group if it's not there yet
19 getent group cvsd >/dev/null || \
20 addgroup --system cvsd
21
22 # create cvsd user if it's not there yet
23 getent passwd cvsd >/dev/null || \
24 adduser --system --ingroup cvsd --home /var/lib/cvsd cvsd
25
26 # correct settings for cvsd user
27 (getent passwd cvsd | grep -q "^cvsd:.*:cvs pserver daemon:") || usermod -c "cvs pserver daemon" cvsd
28 gid=`getent group cvsd | sed 's/^cvsd:[^:]*:\([0-9]*\):.*$/\1/'`
29 (getent passwd cvsd | grep -q "^cvsd:.*:$gid:") || usermod -g "cvsd" cvsd
30 (getent passwd cvsd | grep -q ":/bin/false$") || usermod -s "/bin/false" cvsd
31
32 # sed expressions to escape character so vars may be used in regexps
33 RE_ESCAPE="s/[\\\\\/.+*()\[^$]/\\\\&/g"
34 RP_ESCAPE="s/[\\\\\/&]/\\\\&/g"
35
36 # function to do modification of an option
37 # modifications are to $tmpconfigfile
38 thingamagiggy () {
39 setting="$1"
40 value="$2"
41 value_re=`echo "$value" | sed "$RE_ESCAPE"`
42 value_rp=`echo "$value" | sed "$RP_ESCAPE"`
43 # if config already contains this setting we're done
44 grep \
45 '^[[:space:]]*'"$setting"'[[:space:]][[:space:]]*'"$value_re"'[[:space:]]*$' \
46 < "$tmpconfigfile" > /dev/null 2>&1 \
47 && return 0
48 # check if a setting should be modified or added
49 if grep \
50 '^[[:space:]]*'"$setting"'[[:space:]][[:space:]]*[^[:space:]]*[[:space:]]*$' \
51 < "$tmpconfigfile" > /dev/null 2>&1
52 then
53 # setting is present with another value, modify
54 sed \
55 's/^\([[:space:]]*'"$setting"'[[:space:]][[:space:]]*\)[^[:space:]]*\([[:space:]]*\)$/\1'"$value_rp"'\2/' \
56 < "$tmpconfigfile" > "$tmpfile"
57 cat "$tmpfile" > "$tmpconfigfile"
58 else
59 # setting is not yet present, add
60 echo "$setting $value" >> "$tmpconfigfile"
61 fi
62 }
63
64 # install a new configfile if there is no existing one or if it
65 # is an old generated one, otherwise modify current configfile
66 if ! [ -e "$configfile" ]
67 then
68 # create a new configuration file
69 cat > "$tmpconfigfile" << EOM
70 # This is the configuration file for cvsd.
71 # See the manual page cvsd.conf(5) for more information.
72 #
73 # You can also use 'dpkg-reconfigure cvsd' to modify these
74 # settings.
75 #
76 # See the "Password authentication server"
77 # section in the cvs texinfo for more information
78 # about running a pserver.
79
80 # RootJail <path>
81 # This is the location of the chroot jail
82 # cvs should be run in.
83 # Specify 'none' (without quotes) to not use
84 # a chroot jail.
85 # This directory should be initialized with
86 # the cvsd-buildroot script.
87 RootJail /var/lib/cvsd
88
89 # Uid <uid>
90 # This specifies which user id cvs should be
91 # run as. This can be a numerical id or
92 # a symbolic value.
93 Uid cvsd
94
95 # Gid <gid>
96 # This specifies which group id cvs should be
97 # run as. This can be a numerical id or
98 # a symbolic value.
99 Gid cvsd
100
101 # CvsCommand <path>
102 # If you define this it should point to the cvs
103 # command to execute. Otherwise "/bin/cvs" will
104 # be used if a RootJail is configured and the
105 # cvs command found at compiletime otherwise.
106 # The path should be relative to the specified
107 # RootJail and should start with a '/'.
108
109 # CvsArgs <arg>...
110 # Additional arguments to pass to the cvs command.
111 # For example, to enable read-only access to the
112 # repository, pass the -R option.
113
114 # Nice <num>
115 # This specifies the nice value (on most systems
116 # ranging from -20 to 20) where the smaller the number
117 # (more negative) the higher the priority.
118 Nice 1
119
120 # Umask <mask>
121 # This specifies a umask used by the cvs pserver when
122 # creating files. Specify as an octal value.
123 Umask 027
124
125 # Limit <resource> <value>
126 # <resource> can be one of: coredumpsize, cputime, datasize, filesize,
127 # memorylocked, openfiles, maxproc, memoryuse, stacksize or virtmem.
128 # <value> is the maximum value for the given resource. For size values
129 # a suffix of 'b', 'k' or 'm' can be specified ('k' is default). Time
130 # values can be formatted as 'mm:ss' or have 'm' or 's' suffixes
131 # ('s' is default).
132 Limit coredumpsize 0
133
134 # PidFile <file>
135 # This specifies the location the process id of the
136 # daemon is written.
137 PidFile /var/run/cvsd.pid
138
139 # Listen <address> <port>
140 # The addresses and ports to listen on for connections.
141 #Listen * 2401
142
143 # MaxConnections <num>
144 # The maximum number of connections that will
145 # be handled simultaneously. 0 is unlimited.
146 MaxConnections 10
147
148 # Log <scheme/file> [<loglevel>]
149 # The way logging is done. Either none, syslog or a
150 # filename may be specified, followed by an optional
151 # loglevel. Loglevel may be one of:
152 # crit, error, warning, notice, info (default) or debug.
153 # This option can be supplied multiple times.
154 # If this option is not specified syslog info is assumed.
155 Log syslog info
156 #Log /var/log/cvsd.log debug
157
158 # Repos <path>
159 # This option specifies which repositories
160 # can be used. The value is passed as a
161 # --allow-root=<path> parameter to cvs.
162 # The path should be relative to the specified
163 # RootJail and should start with a '/'.
164 # This option can be supplied multiple times.
165 Repos /test
166 Repos /coolsoftware
167
168 EOM
169 else
170 # use the existing configfile
171 cat "$configfile" > "$tmpconfigfile"
172 fi
173
174 # Location of Chroot jail
175 db_get cvsd/rootjail
176 [ "$RET" = "" ] || [ "$RET" = "/" ] && RET="none"
177 thingamagiggy "RootJail" "$RET"
178 if [ "$RET" = "none" ]; then
179 (getent passwd cvsd | grep -q "^cvsd:.*:/:") || usermod -d "/" cvsd
180 else
181 (getent passwd cvsd | grep -q "^cvsd:.*:$RET:") || usermod -d "$RET" cvsd
182 fi
183 rootjail="$RET"
184
185 # Maximum number of connections
186 db_get cvsd/maxconnections
187 [ -n "$RET" ] || RET=0
188 thingamagiggy "MaxConnections" "$RET"
189
190 # Nice value to run at
191 db_get cvsd/nice
192 [ -n "$RET" ] || RET=1
193 thingamagiggy "Nice" "$RET"
194
195 # Umask to use
196 db_get cvsd/umask
197 [ -n "$RET" ] || RET="027"
198 thingamagiggy "Umask" "$RET"
199
200 # Address-Port combinations to listen on
201 sed 's/^\([[:space:]]*\)Listen/\1x-Listen/' < "$tmpconfigfile" > "$tmpfile"
202 cat "$tmpfile" > "$tmpconfigfile"
203 # check current listen settings
204 db_get cvsd/listen
205 if [ -n "$RET" ]
206 then
207 echo "$RET" | tr ' ' '\n' | while read addr
208 do
209 read port
210 # if current config already contains this addr/port combination
211 # remove the x-, otherwise add a new option
212 addr_re=`echo "$addr" | sed "$RE_ESCAPE"`
213 port_re=`echo "$port" | sed "$RE_ESCAPE"`
214 if grep \
215 '^[[:space:]]*x-Listen[[:space:]][[:space:]]*'"$addr_re"'[[:space:]][[:space:]]*'"$port_re"'[[:space:]]*$' \
216 < "$tmpconfigfile" > /dev/null 2>&1
217 then
218 sed \
219 's/^\([[:space:]]*\)x-\(Listen[[:space:]][[:space:]]*'"$addr_re"'[[:space:]][[:space:]]*'"$port_re"'[[:space:]]*\)$/\1\2/' \
220 "$tmpconfigfile" > "$tmpfile"
221 cat "$tmpfile" > "$tmpconfigfile"
222 else
223 echo "Listen $addr $port" >> "$tmpconfigfile"
224 fi
225 done
226 fi
227 # remove remaining x-Listen options
228 grep -v '^[[:space:]]*x-Listen' < "$tmpconfigfile" > "$tmpfile" || true
229 cat "$tmpfile" > "$tmpconfigfile"
230
231 # Repositories to have
232 sed 's/^\([[:space:]]*\)Repos/\1x-Repos/' < "$tmpconfigfile" > "$tmpfile"
233 cat "$tmpfile" > "$tmpconfigfile"
234 # check current repository settings
235 db_get cvsd/repositories
236 # remove extra repositories
237 OLDIFS="$IFS"
238 IFS=':'
239 for repos in $RET
240 do
241 IFS="$OLDIFS"
242 repos_re=`echo "$repos" | sed "$RE_ESCAPE"`
243 if grep \
244 '^[[:space:]]*x-Repos[[:space:]][[:space:]]*'"$repos_re"'[[:space:]]*$' \
245 < "$tmpconfigfile" > /dev/null 2>&1
246 then
247 sed \
248 's/^\([[:space:]]*\)x-\(Repos[[:space:]][[:space:]]*'"$repos_re"'[[:space:]]*\)$/\1\2/' \
249 "$tmpconfigfile" > "$tmpfile"
250 cat "$tmpfile" > "$tmpconfigfile"
251 else
252 echo "Repos $repos" >> "$tmpconfigfile"
253 fi
254 done
255 # remove remaining x-Repos options
256 grep -v '^[[:space:]]*x-Repos' < "$tmpconfigfile" > "$tmpfile" || true
257 cat "$tmpfile" > "$tmpconfigfile"
258
259 # Limits
260 sed 's/^\([[:space:]]*\)Limit/\1x-Limit/' < "$tmpconfigfile" > "$tmpfile"
261 cat "$tmpfile" > "$tmpconfigfile"
262 # check current limits
263 db_get cvsd/limits
264 for limit in `echo "$RET" | sed 's/,//g'`
265 do
266 db_get "cvsd/limit_$limit"
267 if [ "x$RET" != "x" ]
268 then
269 value="$RET"
270 value_rp=`echo "$value" | sed "$RP_ESCAPE"`
271 if grep \
272 '^[[:space:]]*x-Limit[[:space:]][[:space:]]*'"$limit"'[[:space:]]' \
273 < "$tmpconfigfile" > /dev/null 2>&1
274 then
275 sed \
276 's/^\([[:space:]]*\)x-\(Limit[[:space:]][[:space:]]*'"$limit"'[[:space:]]*\)[^[:space:]]*\([[:space:]]*\)$/\1\2'"$value_rp"'\3/' \
277 "$tmpconfigfile" > "$tmpfile"
278 cat "$tmpfile" > "$tmpconfigfile"
279 else
280 echo "Limit $limit $value" >> "$tmpconfigfile"
281 fi
282 fi
283 done
284 # remove remaining x-Limit options
285 grep -v '^[[:space:]]*x-Limit' < "$tmpconfigfile" > "$tmpfile" || true
286 cat "$tmpfile" > "$tmpconfigfile"
287
288 # acutually save (and make a backup) of the configfile
289 # only save if there are any differences
290 if ! diff "$tmpconfigfile" "$configfile" > /dev/null 2>&1
291 then
292 if [ -e "$configfile" ]
293 then
294 # make backup
295 [ -e "$configfile.old" ] || ( touch "$configfile.old"; chmod 644 "$configfile.old")
296 cat "$configfile" > "$configfile.old"
297 else
298 # create configfile
299 touch "$configfile"
300 chmod 644 "$configfile"
301 fi
302 cat "$tmpconfigfile" > "$configfile"
303 fi
304 rm "$tmpconfigfile"
305 rm "$tmpfile"
306
307 # rebuild the rootjail
308 if [ "$rootjail" != "none" ]
309 then
310 cvsd-buildroot "$rootjail"
311 fi
312
313 #DEBHELPER#
314
315 db_stop
316 exit 0