- ugasi execshield prije izvrsavanja gruba
[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
106 # create/update grub configuration
107 if [ -e /boot/grub/menu.lst ]; then
108     # is there uncompatibile grub conf present?
109     if ! grep -q 'AUTOMAGIC KERNELS LIST' /boot/grub/menu.lst; then
110         mv -f /boot/grub/menu.lst /boot/grub/menu.lst.old
111     fi
112 fi
113 if [ ! -e /boot/grub/menu.lst ]; then
114     yes | /usr/sbin/update-grub >/dev/null 2>&1 || true
115 else
116     /usr/sbin/update-grub >/dev/null 2>&1 || true
117 fi
118
119 # install grub loader
120 SHIELD=$(sysctl -e -n kernel.exec-shield)
121 if [ ! -z "$SHIELD" ]; then
122     sysctl -w -e kernel.exec-shield=0 >/dev/null 2>&1
123 fi
124 if ! grub-install --no-floppy '(hd0)' >/dev/null 2>&1; then
125     echo "."
126     echo "CN: FATAL ERROR running grub-install!"
127     echo "CN: Do not reboot your server and report this to OTRS immediately!"
128     exit 1
129 fi
130 if [ ! -z "$SHIELD" ]; then
131     sysctl -w -e "kernel.exec-shield=$SHIELD" >/dev/null 2>&1
132 fi
133
134 # disable lilo
135 if [ -e /etc/lilo.conf ]; then
136     mv -f /etc/lilo.conf /etc/lilo.conf.old
137 fi
138 echo -n " lilo"
139
140 # mdadm
141 if [ -x /usr/share/mdadm/mkconf ]; then
142     if [ ! -e /etc/mdadm/mdadm.conf ]; then
143         touch /etc/mdadm/mdadm.conf
144     fi
145
146     /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.$$
147     if ! cmp -s /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf; then
148         mv /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf
149     fi
150     rm -f /etc/mdadm/mdadm.conf.$$ /etc/initramfs-tools/hooks/md \
151         /var/lib/mdadm/CONF-UNCHECKED
152     echo -n " mdadm"
153 fi
154
155 # update initramfs accordingly
156 update-initramfs -u -k all >/dev/null 2>&1 || true
157 echo -n " initramfs"
158
159 # finished
160 echo "."
161
162 ################################################################################
163
164 # rest of configuration...
165 echo -n "CN: Modifying the neccessary system files:"
166
167 # remove group 99
168 if getent group proc >/dev/null 2>&1; then
169     groupdel proc >/dev/null 2>&1
170 fi
171 echo -n " proc"
172
173 # remove oidentd from oident group
174 if getent group oident >/dev/null 2>&1; then
175     # sarge default
176     cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup' \
177       's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup/OIDENT_GROUP=oident/g' \
178           /etc/default/oidentd || true
179
180     # old kernel-2.6-cn default
181     cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc' \
182       's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc/OIDENT_GROUP=oident/g' \
183           /etc/default/oidentd || true
184
185     echo -n " oidentd"
186 fi
187
188 # default kernel parameters
189 rm -f /etc/sysctl.conf.$$
190 cat > /etc/sysctl.conf.$$ <<EOF
191 kernel.exec-shield=3
192 kernel.maps_protect=1
193 net.core.rmem_default=1048576
194 net.core.wmem_default=1048576
195 net.ipv4.conf.all.accept_redirects=0
196 net.ipv4.conf.all.accept_source_route=0
197 net.ipv4.conf.all.log_martians=1
198 net.ipv4.conf.all.rp_filter=1
199 net.ipv4.conf.all.secure_redirects=1
200 net.ipv4.conf.all.send_redirects=0
201 net.ipv4.icmp_echo_ignore_broadcasts=1
202 net.ipv4.icmp_ignore_bogus_error_responses=1
203 net.ipv4.ip_forward=0
204 net.ipv4.ip_local_port_range=10000 65000
205 net.ipv4.tcp_congestion_control=cubic
206 net.ipv4.tcp_ecn=0
207 net.ipv4.tcp_max_syn_backlog=8192
208 net.ipv4.tcp_retries1=2
209 net.ipv4.tcp_rfc1337=1
210 net.ipv4.tcp_syncookies=1
211 vm.mmap_min_addr=65536
212 EOF
213
214 # old kernel params
215 if [ -e /etc/sysctl.conf ]; then
216   #cat /etc/sysctl.conf >> /etc/sysctl.conf.$$
217   #ignore some of 2.4 stuff
218   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' \
219     /etc/sysctl.conf >> /etc/sysctl.conf.$$
220 fi
221
222 # add sysctl.conf Debian headers
223 rm -f /etc/sysctl.conf-head
224 cat > /etc/sysctl.conf-head <<EOF
225 #
226 # /etc/sysctl.conf - Configuration file for setting system variables
227 # See sysctl.conf (5) for information.
228 #
229 EOF
230
231 # merge old and new in one conf, primarily respecting old
232 script='
233 my %confhash = ();
234 my ($key, $value);
235 while (<>)
236 {
237   chomp();
238   if (/^\s*(\S+)\s*=\s*(.+)\s*$/o)
239   {
240     my ($key, $value) = ($1, $2);
241     $key =~ s/\//./go;
242     $confhash{$key} = $value;
243   }
244 }
245 for (sort { $a cmp $b } keys %confhash)
246 {
247   print $_, "=", $confhash{$_}, "\n";
248 }
249 '
250 rm -f /etc/sysctl.conf-new
251 perl -e "$script" < /etc/sysctl.conf.$$ > /etc/sysctl.conf-new
252 cat /etc/sysctl.conf-head /etc/sysctl.conf-new > /etc/sysctl.conf.$$
253 rm -f /etc/sysctl.conf-head /etc/sysctl.conf-new
254
255 # finished with merging, move into sysctl.conf
256 cp_mv /etc/sysctl.conf.$$ /etc/sysctl.conf
257 echo -n " sysctl.conf"
258
259 # finished with basic kernel-2.6-cn stuff
260 echo "."
261
262 ################################################################################
263
264 # intro
265 echo -n "CN: Setting up PAM configurations:"
266
267 # update pam_limits accordingly
268 if [ -e /etc/security/limits.conf ]; then
269   rm -f /etc/security/limits.conf.$$
270   cp /etc/security/limits.conf /etc/security/limits.conf.$$
271   cp-update kernel-2.6-cn /etc/security/limits.conf.$$ <<EOF
272 *               soft    core            0
273 *               hard    nofile          4096
274 *               soft    nofile          4096
275 EOF
276   cp_mv /etc/security/limits.conf.$$ /etc/security/limits.conf
277   echo -n " limits"
278 fi
279
280 # check pam.d/login
281 if [ -e /etc/pam.d/login ]; then
282   cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
283     's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
284     /etc/pam.d/login || true
285   echo -n " login"
286 fi
287
288 # check pam.d/ssh
289 if [ -e /etc/pam.d/ssh ]; then
290   cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
291     's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
292     /etc/pam.d/ssh || true
293   echo -n " ssh"
294 fi
295
296 # finished with PAM
297 echo "."
298
299 ################################################################################
300
301 # remove obsolete links
302 rm -f /boot/vmlinuz /boot/vmlinuz.old /boot/vmlinuz.old2 \
303   /boot/vmlinuz.plain /vmlinuz /vmlinuz.old /boot/vmlinuz.plain
304 echo "CN: Removed old symlinks in / and /boot."
305
306 ################################################################################
307
308 # fix old kernel-2.4-cn postrm
309 if [ -e /var/lib/dpkg/info/kernel-2.4-cn.postrm ]; then
310     echo "CN: Fixed old kernel-2.4-cn postrm."
311     cat > /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ <<EOF
312 #!/bin/sh
313
314 set -e
315
316 # be sure, be safe
317 if [ "$1" != "remove" ]; then
318   exit 0
319 fi
320
321 # import CN-functions
322 . /usr/share/carnet-tools/functions.sh
323
324 # remove us from limits.conf
325 cp-update -r kernel-2.4-cn /etc/security/limits.conf
326
327 # remove us from modules
328 cp-update -r kernel-2.4-cn /etc/modules
329 EOF
330     if ! cmp -s /var/lib/dpkg/info/kernel-2.4-cn.postrm \
331         /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$; then
332         mv /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ \
333             /var/lib/dpkg/info/kernel-2.4-cn.postrm
334         chmod +x /var/lib/dpkg/info/kernel-2.4-cn.postrm
335     fi
336     rm -f /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$
337 fi
338
339 ################################################################################
340
341 # fix old kernel-cn postrm
342 if [ -e /var/lib/dpkg/info/kernel-cn.postrm ]; then
343     echo "CN: Fixed old kernel-cn postrm."
344     cat > /var/lib/dpkg/info/kernel-cn.postrm.$$ <<EOF
345 #!/bin/sh
346
347 set -e
348
349 # be sure, be safe
350 if [ "$1" != "remove" ]; then
351   exit 0
352 fi
353
354 # import CN-functions
355 . /usr/share/carnet-tools/functions.sh
356
357 # remove us from limits.conf
358 cp-update -r kernel-cn /etc/security/limits.conf
359
360 # remove us from modules
361 cp-update -r kernel-cn /etc/modules
362 EOF
363     if ! cmp -s /var/lib/dpkg/info/kernel-cn.postrm \
364         /var/lib/dpkg/info/kernel-cn.postrm.$$; then
365         mv /var/lib/dpkg/info/kernel-cn.postrm.$$ \
366             /var/lib/dpkg/info/kernel-cn.postrm
367         chmod +x /var/lib/dpkg/info/kernel-cn.postrm
368     fi
369     rm -f /var/lib/dpkg/info/kernel-cn.postrm.$$
370 fi
371
372 ################################################################################
373
374 # dh_installdeb will replace this with shell code automatically
375 # generated by other debhelper scripts.
376
377 #DEBHELPER#
378
379 exit 0