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 "$grub_dir" ]; then
113 if [ -d /usr/lib/grub/i386-pc ]; then
114 cp -a /usr/lib/grub/i386-pc/* "$grub_dir"
116 elif [ -d /usr/lib/grub/x86_64-pc ]; then
117 cp -a /usr/lib/grub/x86_64-pc/* "$grub_dir"
122 # create/update grub configuration
123 if [ -e "$menu_file" ]; then
124 # is there uncompatibile grub conf present?
125 if ! grep -q 'AUTOMAGIC KERNELS LIST' "$menu_file"; then
126 mv -f "$menu_file" "$menu_file.old"
129 if [ ! -e "$menu_file" ]; then
130 yes | /usr/sbin/update-grub >/dev/null 2>&1 || true
132 /usr/sbin/update-grub >/dev/null 2>&1 || true
137 if uname -a | grep -q grsec; then
138 if [ -x /sbin/chpax ]; then
140 if [ -x /usr/sbin/grub.real ]; then
141 chpax -spmrx /usr/sbin/grub.real >/dev/null 2>&1 || true
142 elif [ -x /usr/sbin/grub ]; then
143 chpax -spmrx /usr/sbin/grub >/dev/null 2>&1 || true
147 if [ -x /usr/sbin/grub-probe.real ]; then
148 chpax -spmrx /usr/sbin/grub-probe.real >/dev/null 2>&1 || true
149 elif [ -x /usr/sbin/grub-probe ]; then
150 chpax -spmrx /usr/sbin/grub-probe >/dev/null 2>&1 || true
157 # remove obsolete devfs/compat links and restore normal udev behaviour
158 rm -f /etc/udev/rules.d/devfs.rules /etc/udev/rules.d/compat.rules \
159 /etc/udev/rules.d/compat-full.rules
160 #if [ ! -e /etc/udev/rules.d/udev.rules ]; then
161 # ln -s ../udev.rules /etc/udev/rules.d/udev.rules
163 udevadm control --reload_rules >/dev/null 2>&1 || true
167 # update device map if possible
168 if [ -f "$device_map" ]; then
169 mv -f "$device_map" "$device_map.old"
171 grub --batch --no-floppy --device-map="$device_map" <<EOF >/dev/null 2>&1
174 if [ ! -s "$device_map" ]; then
175 if [ -f "$device_map.old" ]; then
176 mv -f "$device_map.old" "$device_map"
180 rm -f "$device_map.old"
184 # import GRUB helper functions (again, updated device map)
185 . /usr/share/kernel-2.6-cn/grub-functions.sh
187 # get install device (0x80 BIOS device)
188 install_device=$(grep '^(hd0)' "$device_map" | \
189 sed -e 's%[^[:space:]]*[[:space:]]*\([^[:space:]]*\)%\1%')
190 if [ -z "$install_device" ]; then
192 echo "CN: FATAL ERROR while detecting boot disk!"
193 echo "CN: Do not reboot your server and report this to OTRS immediately!"
197 # oops, install device is a symlink...
198 if [ -h "$install_device" ]; then
199 install_device_resolved=$(resolve_symlink "$install_device")
200 if [ -z "$install_device_resolved" ]; then
201 install_device_resolved="$install_device"
204 # try to fix device map with symlink resolved device
205 if [ "x$install_device_resolved" != "x$install_device" ]; then
206 cp_check_and_sed '^\(hd0\)' \
207 "s;^(hd0).*;(hd0) $install_device_resolved;" "$device_map" \
213 # install GRUB loader
214 if ! grub-install --no-floppy "$install_device" >/dev/null 2>&1; then
216 echo "CN: FATAL ERROR while running grub-install!"
217 echo "CN: Do not reboot your server and report this to OTRS immediately!"
222 # fix possible wrong params in menu.lst
223 cp_check_and_sed '^# groot=' \
224 "s;^# groot=.*;# groot=$grub_root_device;g" \
226 cp_check_and_sed '^# kopt=' \
227 "s;^# kopt=\(.*\)root=[^[:space:]]*\(.*\);# kopt=\1root=$root_device\2;g" \
229 /usr/sbin/update-grub >/dev/null 2>&1 || true
232 # and final stage of devfs/udev brokeness fix
233 if [ "x$install_device_resolved" != "x$install_device" ]; then
234 # get original (symlinked device)
235 root_device=$(find_device_nonresolved "/")
236 if [ -z "$root_device" ]; then
237 root_device=$(find_root_device)
241 cp_check_and_sed '^\(hd0\)' \
242 "s;^(hd0).*;(hd0) $install_device;" "$device_map" \
245 # fix global root= invocation
246 cp_check_and_sed '^# kopt=' \
247 "s;^# kopt=\(.*\)root=[^[:space:]]*\(.*\);# kopt=\1root=$root_device\2;g" \
250 # fix root= invocation for individual kernel profiles
251 cp_check_and_sed '^kernel' \
252 "s;\(^kernel.*\)root=[^[:space:]]*\(.*\);\1root=$root_device\2;g" \
258 if [ -e /etc/lilo.conf ]; then
259 mv -f /etc/lilo.conf /etc/lilo.conf.old
264 if [ -x /usr/share/mdadm/mkconf ]; then
265 if [ ! -e /etc/mdadm/mdadm.conf ]; then
266 touch /etc/mdadm/mdadm.conf
269 /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.$$
270 if ! cmp -s /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf; then
271 mv /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf
273 rm -f /etc/mdadm/mdadm.conf.$$ /etc/initramfs-tools/hooks/md \
274 /var/lib/mdadm/CONF-UNCHECKED
278 # update initramfs accordingly (because of mdadm and udev)
279 update-initramfs -u -k all >/dev/null 2>&1 || true
285 ################################################################################
287 # rest of configuration...
288 echo -n "CN: Modifying the neccessary system files:"
291 if getent group proc >/dev/null 2>&1; then
292 groupdel proc >/dev/null 2>&1
296 # remove oidentd from oident group
297 if getent group oident >/dev/null 2>&1; then
299 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup' \
300 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup/OIDENT_GROUP=oident/g' \
301 /etc/default/oidentd || true
303 # old kernel-2.6-cn default
304 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc' \
305 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc/OIDENT_GROUP=oident/g' \
306 /etc/default/oidentd || true
311 # default kernel parameters
312 rm -f /etc/sysctl.conf.$$
313 cat > /etc/sysctl.conf.$$ <<EOF
314 kernel.maps_protect=1
315 net.core.rmem_default=1048576
316 net.core.wmem_default=1048576
317 net.ipv4.conf.all.accept_redirects=0
318 net.ipv4.conf.all.accept_source_route=0
319 net.ipv4.conf.all.log_martians=1
320 net.ipv4.conf.all.rp_filter=1
321 net.ipv4.conf.all.secure_redirects=1
322 net.ipv4.conf.all.send_redirects=0
323 net.ipv4.icmp_echo_ignore_broadcasts=1
324 net.ipv4.icmp_ignore_bogus_error_responses=1
325 net.ipv4.ip_forward=0
326 net.ipv4.ip_local_port_range=10000 65000
328 net.ipv4.tcp_max_syn_backlog=1024
329 net.ipv4.tcp_retries1=2
330 net.ipv4.tcp_rfc1337=1
331 net.ipv4.tcp_syncookies=1
332 vm.mmap_min_addr=65536
336 if [ -e /etc/sysctl.conf ]; then
337 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' \
338 /etc/sysctl.conf >> /etc/sysctl.conf.$$
341 # add sysctl.conf Debian headers
342 rm -f /etc/sysctl.conf-head
343 cat > /etc/sysctl.conf-head <<EOF
345 # /etc/sysctl.conf - Configuration file for setting system variables
346 # See sysctl.conf (5) for information.
350 # merge old and new in one conf, primarily respecting old
357 if (/^\s*(\S+)\s*=\s*(.+)\s*$/o)
359 my ($key, $value) = ($1, $2);
361 $confhash{$key} = $value;
364 for (sort { $a cmp $b } keys %confhash)
366 print $_, "=", $confhash{$_}, "\n";
369 rm -f /etc/sysctl.conf-new
370 perl -e "$script" < /etc/sysctl.conf.$$ > /etc/sysctl.conf-new
371 cat /etc/sysctl.conf-head /etc/sysctl.conf-new > /etc/sysctl.conf.$$
372 rm -f /etc/sysctl.conf-head /etc/sysctl.conf-new
374 # finished with merging, move into sysctl.conf
375 cp_mv /etc/sysctl.conf.$$ /etc/sysctl.conf
376 echo -n " sysctl.conf"
378 # finished with basic kernel-2.6-cn stuff
381 ################################################################################
384 echo -n "CN: Setting up PAM configurations:"
386 # update pam_limits accordingly
387 if [ -e /etc/security/limits.conf ]; then
388 rm -f /etc/security/limits.conf.$$
389 cp /etc/security/limits.conf /etc/security/limits.conf.$$
390 cp-update kernel-2.6-cn /etc/security/limits.conf.$$ <<EOF
395 cp_mv /etc/security/limits.conf.$$ /etc/security/limits.conf
400 if [ -e /etc/pam.d/login ]; then
401 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
402 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
403 /etc/pam.d/login || true
408 if [ -e /etc/pam.d/ssh ]; then
409 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
410 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
411 /etc/pam.d/ssh || true
418 ################################################################################
420 # fix old kernel-2.4-cn postrm
421 if [ -e /var/lib/dpkg/info/kernel-2.4-cn.postrm ]; then
422 echo "CN: Fixed old kernel-2.4-cn postrm."
423 cat > /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ <<EOF
429 if [ "$1" != "remove" ]; then
433 # import CN-functions
434 . /usr/share/carnet-tools/functions.sh
436 # remove us from limits.conf
437 cp-update -r kernel-2.4-cn /etc/security/limits.conf
439 # remove us from modules
440 cp-update -r kernel-2.4-cn /etc/modules
442 if ! cmp -s /var/lib/dpkg/info/kernel-2.4-cn.postrm \
443 /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$; then
444 mv /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ \
445 /var/lib/dpkg/info/kernel-2.4-cn.postrm
446 chmod +x /var/lib/dpkg/info/kernel-2.4-cn.postrm
448 rm -f /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$
451 ################################################################################
453 # fix old kernel-cn postrm
454 if [ -e /var/lib/dpkg/info/kernel-cn.postrm ]; then
455 echo "CN: Fixed old kernel-cn postrm."
456 cat > /var/lib/dpkg/info/kernel-cn.postrm.$$ <<EOF
462 if [ "$1" != "remove" ]; then
466 # import CN-functions
467 . /usr/share/carnet-tools/functions.sh
469 # remove us from limits.conf
470 cp-update -r kernel-cn /etc/security/limits.conf
472 # remove us from modules
473 cp-update -r kernel-cn /etc/modules
475 if ! cmp -s /var/lib/dpkg/info/kernel-cn.postrm \
476 /var/lib/dpkg/info/kernel-cn.postrm.$$; then
477 mv /var/lib/dpkg/info/kernel-cn.postrm.$$ \
478 /var/lib/dpkg/info/kernel-cn.postrm
479 chmod +x /var/lib/dpkg/info/kernel-cn.postrm
481 rm -f /var/lib/dpkg/info/kernel-cn.postrm.$$
484 ################################################################################
486 # dh_installdeb will replace this with shell code automatically
487 # generated by other debhelper scripts.