- prikazi stateove tijekom grub migracije
[kernel-cn.git] / debian / postinst
1 #!/bin/sh
2 # postinst script for spamassassin-cn
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
8 # summary of how this script can be called:
9 #        * <postinst> `configure' <most-recently-configured-version>
10 #        * <old-postinst> `abort-upgrade' <new version>
11 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12 #          <new-version>
13 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14 #          <failed-install-package> <version> `removing'
15 #          <conflicting-package> <version>
16 # for details, see http://www.debian.org/doc/debian-policy/ or
17 # the debian-policy package
18 #
19
20 case "$1" in
21     configure|reconfigure)
22       # continue below
23     ;;
24
25     *)
26         exit 0
27     ;;
28 esac
29
30 # import CN-functions
31 . /usr/share/carnet-tools/functions.sh
32
33 ################################################################################
34
35 # starting up backup
36 echo -n "CN: Backed up to /var/backups:"
37
38 # backup lilo.conf
39 if [ -e /etc/lilo.conf ]; then
40   cp_backup_conffile /etc/lilo.conf
41   echo -n " lilo.conf"
42 fi
43
44 # backup old kernel params
45 if [ -e /etc/sysctl.conf ]; then
46   cp_backup_conffile /etc/sysctl.conf
47   echo -n " sysctl.conf"
48 fi
49
50 # backup old kernel params
51 if [ -e /etc/kernel-img.conf ]; then
52   cp_backup_conffile /etc/kernel-img.conf
53   echo -n " kernel-img.conf"
54 fi
55
56 # finished
57 echo "."
58
59 ################################################################################
60
61 # intro msg
62 echo -n "CN: Configuring system (this will take a while):"
63
64 # generate kernel-img.conf
65 if [ ! -e /etc/kernel-img.conf ]; then
66     touch /etc/kernel-img.conf
67 fi
68
69 # update postinst_hook for grub
70 if grep -q postinst_hook /etc/kernel-img.conf; then
71     cp_check_and_sed '^postinst_hook' \
72       's;^postinst_hook[[:blank:]]*=.*;postinst_hook = /usr/sbin/update-grub;g' \
73           /etc/kernel-img.conf || true
74 else
75     echo "postinst_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
76 fi
77
78 # update postrm_hook for grub
79 if grep -q postrm_hook /etc/kernel-img.conf; then
80     cp_check_and_sed '^postrm_hook' \
81       's;^postrm_hook[[:blank:]]*=.*;postrm_hook = /usr/sbin/update-grub;g' \
82           /etc/kernel-img.conf || true
83 else
84     echo "postrm_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
85 fi
86
87 # enable initrd
88 if grep -q do_initrd /etc/kernel-img.conf; then
89     cp_check_and_sed '^do_initrd' \
90       's/^do_initrd[[:blank:]]*=.*/do_initrd = yes/g' \
91           /etc/kernel-img.conf || true
92 else
93     echo "do_initrd = yes" >> /etc/kernel-img.conf
94 fi
95
96 echo -n " kernel-img.conf"
97
98 # generate initial grub loaders
99 if [ ! -d /boot/grub ]; then
100     mkdir -p /boot/grub
101     if [ -d /usr/lib/grub/i386-pc ]; then
102         cp -a /usr/lib/grub/i386-pc/* /boot/grub
103     fi
104 fi
105 echo -n " grub1"
106
107 # create/update grub configuration
108 if [ -e /boot/grub/menu.lst ]; then
109     # is there uncompatibile grub conf present?
110     if ! grep -q 'AUTOMAGIC KERNELS LIST' /boot/grub/menu.lst; then
111         mv -f /boot/grub/menu.lst /boot/grub/menu.lst.old
112     fi
113 fi
114 if [ ! -e /boot/grub/menu.lst ]; then
115     yes | /usr/sbin/update-grub >/dev/null 2>&1 || true
116 else
117     /usr/sbin/update-grub >/dev/null 2>&1 || true
118 fi
119 echo -n " grub2"
120
121 # workaround grsec
122 if [ -x /sbin/chpax ]; then
123     if [ -x /usr/sbin/grub ]; then
124         chpax -spmrx /usr/sbin/grub || true
125     fi
126     if [ -x /usr/sbin/grub-probe ]; then
127         chpax -spmrx /usr/sbin/grub-probe || true
128     fi
129 fi
130 echo -n " grub3"
131
132 # workaround execshield
133 SHIELD=$(sysctl -e -n kernel.exec-shield)
134 if [ ! -z "$SHIELD" ]; then
135     sysctl -w -e kernel.exec-shield=0 >/dev/null 2>&1
136 fi
137
138 # install grub loader
139 if ! grub-install --no-floppy '(hd0)' >/dev/null 2>&1; then
140     echo "."
141     echo "CN: FATAL ERROR running grub-install!"
142     echo "CN: Do not reboot your server and report this to OTRS immediately!"
143     exit 1
144 fi
145 echo -n " grub4"
146
147 # restore execshield state
148 if [ ! -z "$SHIELD" ]; then
149     sysctl -w -e "kernel.exec-shield=$SHIELD" >/dev/null 2>&1
150 fi
151
152 # disable lilo
153 if [ -e /etc/lilo.conf ]; then
154     mv -f /etc/lilo.conf /etc/lilo.conf.old
155 fi
156 echo -n " lilo"
157
158 # mdadm
159 if [ -x /usr/share/mdadm/mkconf ]; then
160     if [ ! -e /etc/mdadm/mdadm.conf ]; then
161         touch /etc/mdadm/mdadm.conf
162     fi
163
164     /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.$$
165     if ! cmp -s /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf; then
166         mv /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf
167     fi
168     rm -f /etc/mdadm/mdadm.conf.$$ /etc/initramfs-tools/hooks/md \
169         /var/lib/mdadm/CONF-UNCHECKED
170     echo -n " mdadm"
171 fi
172
173 # update initramfs accordingly
174 update-initramfs -u -k all >/dev/null 2>&1 || true
175 echo -n " initramfs"
176
177 # finished
178 echo "."
179
180 ################################################################################
181
182 # rest of configuration...
183 echo -n "CN: Modifying the neccessary system files:"
184
185 # remove group 99
186 if getent group proc >/dev/null 2>&1; then
187     groupdel proc >/dev/null 2>&1
188 fi
189 echo -n " proc"
190
191 # remove oidentd from oident group
192 if getent group oident >/dev/null 2>&1; then
193     # sarge default
194     cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup' \
195       's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup/OIDENT_GROUP=oident/g' \
196           /etc/default/oidentd || true
197
198     # old kernel-2.6-cn default
199     cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc' \
200       's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc/OIDENT_GROUP=oident/g' \
201           /etc/default/oidentd || true
202
203     echo -n " oidentd"
204 fi
205
206 # default kernel parameters
207 rm -f /etc/sysctl.conf.$$
208 cat > /etc/sysctl.conf.$$ <<EOF
209 kernel.exec-shield=3
210 kernel.maps_protect=1
211 net.core.rmem_default=1048576
212 net.core.wmem_default=1048576
213 net.ipv4.conf.all.accept_redirects=0
214 net.ipv4.conf.all.accept_source_route=0
215 net.ipv4.conf.all.log_martians=1
216 net.ipv4.conf.all.rp_filter=1
217 net.ipv4.conf.all.secure_redirects=1
218 net.ipv4.conf.all.send_redirects=0
219 net.ipv4.icmp_echo_ignore_broadcasts=1
220 net.ipv4.icmp_ignore_bogus_error_responses=1
221 net.ipv4.ip_forward=0
222 net.ipv4.ip_local_port_range=10000 65000
223 net.ipv4.tcp_congestion_control=cubic
224 net.ipv4.tcp_ecn=0
225 net.ipv4.tcp_max_syn_backlog=8192
226 net.ipv4.tcp_retries1=2
227 net.ipv4.tcp_rfc1337=1
228 net.ipv4.tcp_syncookies=1
229 vm.mmap_min_addr=65536
230 EOF
231
232 # old kernel params
233 if [ -e /etc/sysctl.conf ]; then
234   #cat /etc/sysctl.conf >> /etc/sysctl.conf.$$
235   #ignore some of 2.4 stuff
236   egrep -v 'net\.core\.(r|w)mem_max|net\.ipv4\.tcp_(r|w)mem|vm\.bdflush|net\.ipv4\.ip_local_port_range|kernel\.rtsig-max|net\.ipv4\.tcp_syncookies' \
237     /etc/sysctl.conf >> /etc/sysctl.conf.$$
238 fi
239
240 # add sysctl.conf Debian headers
241 rm -f /etc/sysctl.conf-head
242 cat > /etc/sysctl.conf-head <<EOF
243 #
244 # /etc/sysctl.conf - Configuration file for setting system variables
245 # See sysctl.conf (5) for information.
246 #
247 EOF
248
249 # merge old and new in one conf, primarily respecting old
250 script='
251 my %confhash = ();
252 my ($key, $value);
253 while (<>)
254 {
255   chomp();
256   if (/^\s*(\S+)\s*=\s*(.+)\s*$/o)
257   {
258     my ($key, $value) = ($1, $2);
259     $key =~ s/\//./go;
260     $confhash{$key} = $value;
261   }
262 }
263 for (sort { $a cmp $b } keys %confhash)
264 {
265   print $_, "=", $confhash{$_}, "\n";
266 }
267 '
268 rm -f /etc/sysctl.conf-new
269 perl -e "$script" < /etc/sysctl.conf.$$ > /etc/sysctl.conf-new
270 cat /etc/sysctl.conf-head /etc/sysctl.conf-new > /etc/sysctl.conf.$$
271 rm -f /etc/sysctl.conf-head /etc/sysctl.conf-new
272
273 # finished with merging, move into sysctl.conf
274 cp_mv /etc/sysctl.conf.$$ /etc/sysctl.conf
275 echo -n " sysctl.conf"
276
277 # finished with basic kernel-2.6-cn stuff
278 echo "."
279
280 ################################################################################
281
282 # intro
283 echo -n "CN: Setting up PAM configurations:"
284
285 # update pam_limits accordingly
286 if [ -e /etc/security/limits.conf ]; then
287   rm -f /etc/security/limits.conf.$$
288   cp /etc/security/limits.conf /etc/security/limits.conf.$$
289   cp-update kernel-2.6-cn /etc/security/limits.conf.$$ <<EOF
290 *               soft    core            0
291 *               hard    nofile          4096
292 *               soft    nofile          4096
293 EOF
294   cp_mv /etc/security/limits.conf.$$ /etc/security/limits.conf
295   echo -n " limits"
296 fi
297
298 # check pam.d/login
299 if [ -e /etc/pam.d/login ]; then
300   cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
301     's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
302     /etc/pam.d/login || true
303   echo -n " login"
304 fi
305
306 # check pam.d/ssh
307 if [ -e /etc/pam.d/ssh ]; then
308   cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
309     's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
310     /etc/pam.d/ssh || true
311   echo -n " ssh"
312 fi
313
314 # finished with PAM
315 echo "."
316
317 ################################################################################
318
319 # remove obsolete links
320 rm -f /boot/vmlinuz /boot/vmlinuz.old /boot/vmlinuz.old2 \
321   /boot/vmlinuz.plain /vmlinuz /vmlinuz.old /boot/vmlinuz.plain
322 echo "CN: Removed old symlinks in / and /boot."
323
324 ################################################################################
325
326 # fix old kernel-2.4-cn postrm
327 if [ -e /var/lib/dpkg/info/kernel-2.4-cn.postrm ]; then
328     echo "CN: Fixed old kernel-2.4-cn postrm."
329     cat > /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ <<EOF
330 #!/bin/sh
331
332 set -e
333
334 # be sure, be safe
335 if [ "$1" != "remove" ]; then
336   exit 0
337 fi
338
339 # import CN-functions
340 . /usr/share/carnet-tools/functions.sh
341
342 # remove us from limits.conf
343 cp-update -r kernel-2.4-cn /etc/security/limits.conf
344
345 # remove us from modules
346 cp-update -r kernel-2.4-cn /etc/modules
347 EOF
348     if ! cmp -s /var/lib/dpkg/info/kernel-2.4-cn.postrm \
349         /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$; then
350         mv /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ \
351             /var/lib/dpkg/info/kernel-2.4-cn.postrm
352         chmod +x /var/lib/dpkg/info/kernel-2.4-cn.postrm
353     fi
354     rm -f /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$
355 fi
356
357 ################################################################################
358
359 # fix old kernel-cn postrm
360 if [ -e /var/lib/dpkg/info/kernel-cn.postrm ]; then
361     echo "CN: Fixed old kernel-cn postrm."
362     cat > /var/lib/dpkg/info/kernel-cn.postrm.$$ <<EOF
363 #!/bin/sh
364
365 set -e
366
367 # be sure, be safe
368 if [ "$1" != "remove" ]; then
369   exit 0
370 fi
371
372 # import CN-functions
373 . /usr/share/carnet-tools/functions.sh
374
375 # remove us from limits.conf
376 cp-update -r kernel-cn /etc/security/limits.conf
377
378 # remove us from modules
379 cp-update -r kernel-cn /etc/modules
380 EOF
381     if ! cmp -s /var/lib/dpkg/info/kernel-cn.postrm \
382         /var/lib/dpkg/info/kernel-cn.postrm.$$; then
383         mv /var/lib/dpkg/info/kernel-cn.postrm.$$ \
384             /var/lib/dpkg/info/kernel-cn.postrm
385         chmod +x /var/lib/dpkg/info/kernel-cn.postrm
386     fi
387     rm -f /var/lib/dpkg/info/kernel-cn.postrm.$$
388 fi
389
390 ################################################################################
391
392 # dh_installdeb will replace this with shell code automatically
393 # generated by other debhelper scripts.
394
395 #DEBHELPER#
396
397 exit 0