2 # postinst script for kernel-2.6-cn
4 # see: dh_installdeb(1)
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>
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
21 configure|reconfigure)
31 . /usr/share/carnet-tools/functions.sh
33 # import GRUB helper functions
34 . /usr/share/kernel-2.6-cn/grub-functions.sh
36 ################################################################################
39 echo -n "CN: Backed up to /var/backups:"
42 if [ -e /etc/lilo.conf ]; then
43 cp_backup_conffile /etc/lilo.conf
47 # backup old kernel params
48 if [ -e /etc/sysctl.conf ]; then
49 cp_backup_conffile /etc/sysctl.conf
50 echo -n " sysctl.conf"
53 # backup old kernel params
54 if [ -e /etc/kernel-img.conf ]; then
55 cp_backup_conffile /etc/kernel-img.conf
56 echo -n " kernel-img.conf"
62 ################################################################################
64 # remove obsolete symlinks and kernels
65 rm -f /boot/vmlinuz /boot/vmlinuz.old /boot/vmlinuz.old2 \
66 /boot/vmlinuz.plain /vmlinuz /vmlinuz.old /boot/vmlinuz.plain \
67 /boot/vmlinuz.generic /boot/vmlinuz-generic /boot/vmlinuz-old
68 echo "CN: Removed old symlinks in / and /boot."
70 ################################################################################
73 echo -n "CN: Configuring system (this will take a while):"
75 # generate kernel-img.conf
76 if [ ! -e /etc/kernel-img.conf ]; then
77 touch /etc/kernel-img.conf
80 # update postinst_hook for grub
81 if grep -q postinst_hook /etc/kernel-img.conf; then
82 cp_check_and_sed '^postinst_hook' \
83 's;^postinst_hook[[:blank:]]*=.*;postinst_hook = /usr/sbin/update-grub;g' \
84 /etc/kernel-img.conf || true
86 echo "postinst_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
89 # update postrm_hook for grub
90 if grep -q postrm_hook /etc/kernel-img.conf; then
91 cp_check_and_sed '^postrm_hook' \
92 's;^postrm_hook[[:blank:]]*=.*;postrm_hook = /usr/sbin/update-grub;g' \
93 /etc/kernel-img.conf || true
95 echo "postrm_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
99 if grep -q do_initrd /etc/kernel-img.conf; then
100 cp_check_and_sed '^do_initrd' \
101 's/^do_initrd[[:blank:]]*=.*/do_initrd = yes/g' \
102 /etc/kernel-img.conf || true
104 echo "do_initrd = yes" >> /etc/kernel-img.conf
107 echo -n " kernel-img.conf"
109 # generate initial grub loaders
110 if [ ! -d /boot/grub ]; then
112 if [ -d /usr/lib/grub/i386-pc ]; then
113 cp -a /usr/lib/grub/i386-pc/* /boot/grub
118 # create/update grub configuration
119 if [ -e /boot/grub/menu.lst ]; then
120 # is there uncompatibile grub conf present?
121 if ! grep -q 'AUTOMAGIC KERNELS LIST' /boot/grub/menu.lst; then
122 mv -f /boot/grub/menu.lst /boot/grub/menu.lst.old
125 if [ ! -e /boot/grub/menu.lst ]; then
126 yes | /usr/sbin/update-grub >/dev/null 2>&1 || true
128 /usr/sbin/update-grub >/dev/null 2>&1 || true
133 if [ -x /sbin/chpax ]; then
134 if [ -x /usr/sbin/grub ]; then
135 chpax -spmrx /usr/sbin/grub || true
137 if [ -x /usr/sbin/grub-probe ]; then
138 chpax -spmrx /usr/sbin/grub-probe || true
143 # workaround execshield
144 SHIELD=$(sysctl -e -n kernel.exec-shield)
145 if [ ! -z "$SHIELD" ]; then
146 sysctl -w -e kernel.exec-shield=0 >/dev/null 2>&1
147 echo -n " execshield1"
150 # remove obsolete devfs/compat links and restore normal udev behaviour
151 rm -f /etc/udev/rules.d/devfs.rules /etc/udev/rules.d/compat.rules \
152 /etc/udev/rules.d/compat-full.rules
153 if [ ! -e /etc/udev/rules.d/udev.rules ]; then
154 ln -s ../udev.rules /etc/udev/rules.d/udev.rules
156 udevcontrol reload_rules >/dev/null 2>&1 || true
159 # update device map if possible
160 device_map=/boot/grub/device.map
161 if [ -f $device_map ]; then
162 mv -f $device_map $device_map.old
164 grub --batch --no-floppy --device-map=$device_map <<EOF >/dev/null 2>&1
167 if [ ! -s $device_map ]; then
168 if [ -f $device_map.old ]; then
169 mv -f $device_map.old $device_map
172 rm -f $device_map.old
176 # install GRUB loader
177 install_device=$(grep '^(hd0)' $device_map | \
178 sed -e 's%[^[:space:]]*[[:space:]]*\([^[:space:]]*\)%\1%')
179 if [ -z "$install_device" ]; then
181 echo "CN: FATAL ERROR while detecting boot disk!"
182 echo "CN: Do not reboot your server and report this to OTRS immediately!"
185 if ! grub-install --no-floppy "$install_device" >/dev/null 2>&1; then
187 echo "CN: FATAL ERROR while running grub-install!"
188 echo "CN: Do not reboot your server and report this to OTRS immediately!"
193 # fix possible wrong params in menu.lst
194 cp_check_and_sed '^# groot=' \
195 "s;^# groot=.*;# groot=$grub_root_device;g" \
196 /boot/grub/menu.lst || true
197 cp_check_and_sed '^# kopt=' \
198 "s;^# kopt=\(.*\)root=[^[:space:]]*\(.*\);# kopt=\1root=$root_device\2;g" \
199 /boot/grub/menu.lst || true
200 /usr/sbin/update-grub >/dev/null 2>&1 || true
203 # restore execshield state
204 if [ ! -z "$SHIELD" ]; then
205 sysctl -w -e "kernel.exec-shield=$SHIELD" >/dev/null 2>&1
206 echo -n " execshield2"
210 if [ -e /etc/lilo.conf ]; then
211 mv -f /etc/lilo.conf /etc/lilo.conf.old
216 if [ -x /usr/share/mdadm/mkconf ]; then
217 if [ ! -e /etc/mdadm/mdadm.conf ]; then
218 touch /etc/mdadm/mdadm.conf
221 /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.$$
222 if ! cmp -s /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf; then
223 mv /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf
225 rm -f /etc/mdadm/mdadm.conf.$$ /etc/initramfs-tools/hooks/md \
226 /var/lib/mdadm/CONF-UNCHECKED
230 # update initramfs accordingly
231 update-initramfs -u -k all >/dev/null 2>&1 || true
237 ################################################################################
239 # rest of configuration...
240 echo -n "CN: Modifying the neccessary system files:"
243 if getent group proc >/dev/null 2>&1; then
244 groupdel proc >/dev/null 2>&1
248 # remove oidentd from oident group
249 if getent group oident >/dev/null 2>&1; then
251 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup' \
252 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup/OIDENT_GROUP=oident/g' \
253 /etc/default/oidentd || true
255 # old kernel-2.6-cn default
256 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc' \
257 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc/OIDENT_GROUP=oident/g' \
258 /etc/default/oidentd || true
263 # default kernel parameters
264 rm -f /etc/sysctl.conf.$$
265 cat > /etc/sysctl.conf.$$ <<EOF
267 kernel.maps_protect=1
268 net.core.rmem_default=1048576
269 net.core.wmem_default=1048576
270 net.ipv4.conf.all.accept_redirects=0
271 net.ipv4.conf.all.accept_source_route=0
272 net.ipv4.conf.all.log_martians=1
273 net.ipv4.conf.all.rp_filter=1
274 net.ipv4.conf.all.secure_redirects=1
275 net.ipv4.conf.all.send_redirects=0
276 net.ipv4.icmp_echo_ignore_broadcasts=1
277 net.ipv4.icmp_ignore_bogus_error_responses=1
278 net.ipv4.ip_forward=0
279 net.ipv4.ip_local_port_range=10000 65000
280 net.ipv4.tcp_congestion_control=cubic
282 net.ipv4.tcp_max_syn_backlog=8192
283 net.ipv4.tcp_retries1=2
284 net.ipv4.tcp_rfc1337=1
285 net.ipv4.tcp_syncookies=1
286 vm.mmap_min_addr=65536
290 if [ -e /etc/sysctl.conf ]; then
291 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' \
292 /etc/sysctl.conf >> /etc/sysctl.conf.$$
295 # add sysctl.conf Debian headers
296 rm -f /etc/sysctl.conf-head
297 cat > /etc/sysctl.conf-head <<EOF
299 # /etc/sysctl.conf - Configuration file for setting system variables
300 # See sysctl.conf (5) for information.
304 # merge old and new in one conf, primarily respecting old
311 if (/^\s*(\S+)\s*=\s*(.+)\s*$/o)
313 my ($key, $value) = ($1, $2);
315 $confhash{$key} = $value;
318 for (sort { $a cmp $b } keys %confhash)
320 print $_, "=", $confhash{$_}, "\n";
323 rm -f /etc/sysctl.conf-new
324 perl -e "$script" < /etc/sysctl.conf.$$ > /etc/sysctl.conf-new
325 cat /etc/sysctl.conf-head /etc/sysctl.conf-new > /etc/sysctl.conf.$$
326 rm -f /etc/sysctl.conf-head /etc/sysctl.conf-new
328 # finished with merging, move into sysctl.conf
329 cp_mv /etc/sysctl.conf.$$ /etc/sysctl.conf
330 echo -n " sysctl.conf"
332 # finished with basic kernel-2.6-cn stuff
335 ################################################################################
338 echo -n "CN: Setting up PAM configurations:"
340 # update pam_limits accordingly
341 if [ -e /etc/security/limits.conf ]; then
342 rm -f /etc/security/limits.conf.$$
343 cp /etc/security/limits.conf /etc/security/limits.conf.$$
344 cp-update kernel-2.6-cn /etc/security/limits.conf.$$ <<EOF
349 cp_mv /etc/security/limits.conf.$$ /etc/security/limits.conf
354 if [ -e /etc/pam.d/login ]; then
355 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
356 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
357 /etc/pam.d/login || true
362 if [ -e /etc/pam.d/ssh ]; then
363 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
364 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
365 /etc/pam.d/ssh || true
372 ################################################################################
374 # fix old kernel-2.4-cn postrm
375 if [ -e /var/lib/dpkg/info/kernel-2.4-cn.postrm ]; then
376 echo "CN: Fixed old kernel-2.4-cn postrm."
377 cat > /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ <<EOF
383 if [ "$1" != "remove" ]; then
387 # import CN-functions
388 . /usr/share/carnet-tools/functions.sh
390 # remove us from limits.conf
391 cp-update -r kernel-2.4-cn /etc/security/limits.conf
393 # remove us from modules
394 cp-update -r kernel-2.4-cn /etc/modules
396 if ! cmp -s /var/lib/dpkg/info/kernel-2.4-cn.postrm \
397 /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$; then
398 mv /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ \
399 /var/lib/dpkg/info/kernel-2.4-cn.postrm
400 chmod +x /var/lib/dpkg/info/kernel-2.4-cn.postrm
402 rm -f /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$
405 ################################################################################
407 # fix old kernel-cn postrm
408 if [ -e /var/lib/dpkg/info/kernel-cn.postrm ]; then
409 echo "CN: Fixed old kernel-cn postrm."
410 cat > /var/lib/dpkg/info/kernel-cn.postrm.$$ <<EOF
416 if [ "$1" != "remove" ]; then
420 # import CN-functions
421 . /usr/share/carnet-tools/functions.sh
423 # remove us from limits.conf
424 cp-update -r kernel-cn /etc/security/limits.conf
426 # remove us from modules
427 cp-update -r kernel-cn /etc/modules
429 if ! cmp -s /var/lib/dpkg/info/kernel-cn.postrm \
430 /var/lib/dpkg/info/kernel-cn.postrm.$$; then
431 mv /var/lib/dpkg/info/kernel-cn.postrm.$$ \
432 /var/lib/dpkg/info/kernel-cn.postrm
433 chmod +x /var/lib/dpkg/info/kernel-cn.postrm
435 rm -f /var/lib/dpkg/info/kernel-cn.postrm.$$
438 ################################################################################
440 # dh_installdeb will replace this with shell code automatically
441 # generated by other debhelper scripts.