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)
30 # Source debconf library.
31 . /usr/share/debconf/confmodule
34 . /usr/share/carnet-tools/functions.sh
36 # import GRUB helper functions
37 . /usr/share/kernel-2.6-cn/grub-functions.sh
39 ################################################################################
42 echo -n "CN: Backed up to /var/backups:"
45 if [ -e /etc/lilo.conf ]; then
46 cp_backup_conffile /etc/lilo.conf
50 # backup old kernel params
51 if [ -e /etc/sysctl.conf ]; then
52 cp_backup_conffile /etc/sysctl.conf
53 echo -n " sysctl.conf"
56 # backup old kernel params
57 if [ -e /etc/kernel-img.conf ]; then
58 cp_backup_conffile /etc/kernel-img.conf
59 echo -n " kernel-img.conf"
65 ################################################################################
67 # remove obsolete symlinks and kernels
68 rm -f /boot/vmlinuz /boot/vmlinuz.old /boot/vmlinuz.old2 \
69 /boot/vmlinuz.plain /vmlinuz /vmlinuz.old /boot/vmlinuz.plain \
70 /boot/vmlinuz.generic /boot/vmlinuz-generic /boot/vmlinuz-old
71 echo "CN: Removed old symlinks in / and /boot."
73 ################################################################################
75 DIVERT_TO="grub grub-probe"
77 echo -n "CN: Undiverting binaries if necessary:"
78 for i in $DIVERT_TO; do
79 if [ -e /usr/sbin/$i.real ]; then
80 dpkg-divert --remove --rename --package 'kernel-2.6-cn' \
81 --divert /usr/sbin/$i.real /usr/sbin/$i >/dev/null
87 ################################################################################
89 # detect existing Grub2 installation
92 if [ -e /boot/grub/grub.cfg ]; then
93 echo "CN: Detected GRUB2 installation, will try to use it."
95 if [ -e /boot/grub/menu.lst ]; then
96 echo "CN: Oops, GRUB1 (Legacy) installation detected. Will try to upgrade to GRUB2."
99 echo "CN: No GRUB2 detected, will continue with GRUB1 as default option."
102 ################################################################################
105 echo -n "CN: Configuring system (this will take a while):"
107 # generate kernel-img.conf
108 if [ ! -e /etc/kernel-img.conf ]; then
109 touch /etc/kernel-img.conf
112 # update postinst_hook for grub/grub2
113 if grep -q postinst_hook /etc/kernel-img.conf; then
114 cp_check_and_sed '^postinst_hook' \
115 's;^postinst_hook[[:blank:]]*=.*;postinst_hook = /usr/sbin/update-grub;g' \
116 /etc/kernel-img.conf || true
118 echo "postinst_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
121 # update postrm_hook for grub/grub2
122 if grep -q postrm_hook /etc/kernel-img.conf; then
123 cp_check_and_sed '^postrm_hook' \
124 's;^postrm_hook[[:blank:]]*=.*;postrm_hook = /usr/sbin/update-grub;g' \
125 /etc/kernel-img.conf || true
127 echo "postrm_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
131 if grep -q do_initrd /etc/kernel-img.conf; then
132 cp_check_and_sed '^do_initrd' \
133 's/^do_initrd[[:blank:]]*=.*/do_initrd = yes/g' \
134 /etc/kernel-img.conf || true
136 echo "do_initrd = yes" >> /etc/kernel-img.conf
139 echo -n " kernel-img.conf"
141 # generate initial grub loaders
142 if [ "x$GRUB2" = "xno" ]; then
144 if [ ! -d "$grub_dir" ]; then
147 if [ -d /usr/lib/grub/i386-pc ]; then
148 cp -a /usr/lib/grub/i386-pc/* "$grub_dir"
150 elif [ -d /usr/lib/grub/x86_64-pc ]; then
151 cp -a /usr/lib/grub/x86_64-pc/* "$grub_dir"
156 if [ ! -d /boot/grub ]; then
158 if [ -d /usr/lib/grub/i386-pc ]; then
159 cp -a /usr/lib/grub/i386-pc/* /boot/grub
165 # create/update grub configuration
166 if [ "x$GRUB2" = "xno" ]; then
168 if [ -e "$menu_file" ]; then
169 # is there uncompatibile grub conf present?
170 if ! grep -q 'AUTOMAGIC KERNELS LIST' "$menu_file"; then
171 mv -f "$menu_file" "$menu_file.old"
174 if [ ! -e "$menu_file" ]; then
175 yes | update-grub >/dev/null 2>&1 || true
177 update-grub >/dev/null 2>&1 || true
181 update-grub >/dev/null 2>&1 || true
186 if uname -a | grep -q grsec; then
187 if [ -x /sbin/chpax ]; then
189 if [ -x /usr/sbin/grub.real ]; then
190 chpax -spmrx /usr/sbin/grub.real >/dev/null 2>&1 || true
191 elif [ -x /usr/sbin/grub ]; then
192 chpax -spmrx /usr/sbin/grub >/dev/null 2>&1 || true
196 if [ -x /usr/sbin/grub-probe.real ]; then
197 chpax -spmrx /usr/sbin/grub-probe.real >/dev/null 2>&1 || true
198 elif [ -x /usr/sbin/grub-probe ]; then
199 chpax -spmrx /usr/sbin/grub-probe >/dev/null 2>&1 || true
206 # remove obsolete devfs/compat links and restore normal udev behaviour
207 rm -f /etc/udev/rules.d/devfs.rules /etc/udev/rules.d/compat.rules \
208 /etc/udev/rules.d/compat-full.rules
209 #if [ ! -e /etc/udev/rules.d/udev.rules ]; then
210 # ln -s ../udev.rules /etc/udev/rules.d/udev.rules
212 udevadm control --reload_rules >/dev/null 2>&1 || true
213 udevadm settle || true
216 # update device map if possible
217 if [ "x$GRUB2" = "xno" ]; then
219 if [ -f "$device_map" ]; then
220 mv -f "$device_map" "$device_map.old"
222 grub --batch --no-floppy --device-map="$device_map" <<'EOF' >/dev/null 2>&1
225 if [ ! -s "$device_map" ]; then
226 if [ -f "$device_map.old" ]; then
227 mv -f "$device_map.old" "$device_map"
231 rm -f "$device_map.old"
239 # import GRUB helper functions (again, updated device map)
240 . /usr/share/kernel-2.6-cn/grub-functions.sh
242 if [ "x$GRUB2" = "xno" ]; then
244 # get install device (0x80 BIOS device)
245 install_device=$(grep '^(hd0)' "$device_map" | \
246 sed -e 's%[^[:space:]]*[[:space:]]*\([^[:space:]]*\)%\1%')
247 if [ -z "$install_device" ]; then
249 echo "CN: FATAL ERROR while detecting boot disk!"
250 echo "CN: Do not reboot your server and report this to OTRS immediately!"
254 # oops, install device is a symlink...
255 if [ -h "$install_device" ]; then
256 install_device_resolved=$(resolve_symlink "$install_device")
257 if [ -z "$install_device_resolved" ]; then
258 install_device_resolved="$install_device"
261 # try to fix device map with symlink resolved device
262 if [ "x$install_device_resolved" != "x$install_device" ]; then
263 cp_check_and_sed '^\(hd0\)' \
264 "s;^(hd0).*;(hd0) $install_device_resolved;" "$device_map" \
270 install_device='(hd0)'
274 # install GRUB loader
275 # this will work for both Grub1 and Grub2
276 if ! grub-install --no-floppy "$install_device" >/dev/null 2>&1; then
278 echo "CN: FATAL ERROR while running grub-install on $install_device!"
279 echo "CN: Do not reboot your server and report this to OTRS immediately!"
284 # fix possible wrong params in menu.lst
285 if [ "x$GRUB2" = "xno" ]; then
287 cp_check_and_sed '^# groot=' \
288 "s;^# groot=.*;# groot=$grub_root_device;g" \
290 cp_check_and_sed '^# kopt=' \
291 "s;^# kopt=\(.*\)root=[^[:space:]]*\(.*\);# kopt=\1root=$root_device\2;g" \
294 update-grub >/dev/null 2>&1 || true
297 # fix possible wrong params in menu.lst
298 if [ "x$GRUB2" = "xno" ]; then
300 # ... and final stage of devfs/udev brokeness fix
301 if [ "x$install_device_resolved" != "x$install_device" ]; then
302 # get original (symlinked device)
303 root_device=$(find_device_nonresolved "/")
304 if [ -z "$root_device" ]; then
305 root_device=$(find_root_device)
309 cp_check_and_sed '^\(hd0\)' \
310 "s;^(hd0).*;(hd0) $install_device;" "$device_map" \
313 # fix global root= invocation
314 cp_check_and_sed '^# kopt=' \
315 "s;^# kopt=\(.*\)root=[^[:space:]]*\(.*\);# kopt=\1root=$root_device\2;g" \
318 # fix root= invocation for individual kernel profiles
319 cp_check_and_sed '^kernel' \
320 "s;\(^kernel.*\)root=[^[:space:]]*\(.*\);\1root=$root_device\2;g" \
327 if [ -e /etc/lilo.conf ]; then
328 mv -f /etc/lilo.conf /etc/lilo.conf.old
333 if [ -x /usr/share/mdadm/mkconf ]; then
334 if [ ! -e /etc/mdadm/mdadm.conf ]; then
335 touch /etc/mdadm/mdadm.conf
338 /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.$$
339 if ! cmp -s /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf; then
340 mv /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf
342 rm -f /etc/mdadm/mdadm.conf.$$ /etc/initramfs-tools/hooks/md \
343 /var/lib/mdadm/CONF-UNCHECKED
347 # update initramfs accordingly (because of mdadm and udev)
348 update-initramfs -u -k all >/dev/null 2>&1 || true
354 ################################################################################
356 # rest of configuration...
357 echo -n "CN: Modifying the neccessary system files:"
360 if getent group proc >/dev/null 2>&1; then
361 groupdel proc >/dev/null 2>&1
365 # remove oidentd from oident group
366 if getent group oident >/dev/null 2>&1; then
368 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup' \
369 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup/OIDENT_GROUP=oident/g' \
370 /etc/default/oidentd || true
372 # old kernel-2.6-cn default
373 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc' \
374 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc/OIDENT_GROUP=oident/g' \
375 /etc/default/oidentd || true
380 # default kernel parameters
381 rm -f /etc/sysctl.conf.$$
383 # old kernel params (skipping some of the obsolete or overrided entries)
384 if [ -e /etc/sysctl.conf ]; then
385 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|kernel\.exec-shield|net\.ipv4\.tcp_max_syn_backlog|net\.ipv4\.tcp_congestion_control|kernel\.exec-shield|kernel\.maps_protect' \
386 /etc/sysctl.conf >> /etc/sysctl.conf.$$
389 # finished with merging, move into sysctl.conf
390 cp_mv /etc/sysctl.conf.$$ /etc/sysctl.conf
391 echo -n " sysctl.conf"
394 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
395 invoke-rc.d procps restart >/dev/null 2>&1 || true
397 /etc/init.d/procps restart >/dev/null 2>&1 || true
400 # finished with basic kernel-2.6-cn stuff
403 ################################################################################
406 echo -n "CN: Setting up PAM configurations:"
408 # update pam_limits accordingly
409 if [ -e /etc/security/limits.conf ]; then
410 rm -f /etc/security/limits.conf.$$
411 cp /etc/security/limits.conf /etc/security/limits.conf.$$
412 cp-update kernel-2.6-cn /etc/security/limits.conf.$$ <<'EOF'
416 @users soft nproc 100
417 @users hard nproc 150
419 cp_mv /etc/security/limits.conf.$$ /etc/security/limits.conf
424 if [ -e /etc/pam.d/login ]; then
425 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
426 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
427 /etc/pam.d/login || true
432 if [ -e /etc/pam.d/ssh ]; then
433 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
434 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
435 /etc/pam.d/ssh || true
442 ################################################################################
444 # fix old kernel-2.4-cn postrm
445 if [ -e /var/lib/dpkg/info/kernel-2.4-cn.postrm ]; then
446 echo "CN: Fixed old kernel-2.4-cn postrm."
447 cat > /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ <<'EOF'
453 if [ "$1" != "remove" ]; then
457 # import CN-functions
458 . /usr/share/carnet-tools/functions.sh
460 # remove us from limits.conf
461 cp-update -r kernel-2.4-cn /etc/security/limits.conf
463 # remove us from modules
464 cp-update -r kernel-2.4-cn /etc/modules
466 if ! cmp -s /var/lib/dpkg/info/kernel-2.4-cn.postrm \
467 /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$; then
468 mv /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ \
469 /var/lib/dpkg/info/kernel-2.4-cn.postrm
470 chmod +x /var/lib/dpkg/info/kernel-2.4-cn.postrm
472 rm -f /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$
475 ################################################################################
477 # fix old kernel-cn postrm
478 if [ -e /var/lib/dpkg/info/kernel-cn.postrm ]; then
479 echo "CN: Fixed old kernel-cn postrm."
480 cat > /var/lib/dpkg/info/kernel-cn.postrm.$$ <<'EOF'
486 if [ "$1" != "remove" ]; then
490 # import CN-functions
491 . /usr/share/carnet-tools/functions.sh
493 # remove us from limits.conf
494 cp-update -r kernel-cn /etc/security/limits.conf
496 # remove us from modules
497 cp-update -r kernel-cn /etc/modules
499 if ! cmp -s /var/lib/dpkg/info/kernel-cn.postrm \
500 /var/lib/dpkg/info/kernel-cn.postrm.$$; then
501 mv /var/lib/dpkg/info/kernel-cn.postrm.$$ \
502 /var/lib/dpkg/info/kernel-cn.postrm
503 chmod +x /var/lib/dpkg/info/kernel-cn.postrm
505 rm -f /var/lib/dpkg/info/kernel-cn.postrm.$$
508 ################################################################################
510 # dh_installdeb will replace this with shell code automatically
511 # generated by other debhelper scripts.