5 [ "$1" = "configure" ] || exit 0
6 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
9 . /usr/share/debconf/confmodule
12 . /usr/share/carnet-tools/functions.sh
14 # import GRUB helper functions
15 . /usr/share/kernel-cn/grub-functions.sh
17 ################################################################################
20 echo -n "CN: Backed up to /var/backups:"
23 if [ -e /etc/lilo.conf ]; then
24 cp_backup_conffile /etc/lilo.conf
28 # backup old kernel params
29 if [ -e /etc/sysctl.conf ]; then
30 cp_backup_conffile /etc/sysctl.conf
31 echo -n " sysctl.conf"
34 # backup old kernel params
35 if [ -e /etc/kernel-img.conf ]; then
36 cp_backup_conffile /etc/kernel-img.conf
37 echo -n " kernel-img.conf"
43 ################################################################################
45 # remove obsolete symlinks and kernels
46 rm -f /boot/vmlinuz /boot/vmlinuz.old /boot/vmlinuz.old2 \
47 /boot/vmlinuz.plain /vmlinuz /vmlinuz.old /boot/vmlinuz.plain \
48 /boot/vmlinuz.generic /boot/vmlinuz-generic /boot/vmlinuz-old
49 echo "CN: Removed old symlinks in / and /boot."
51 ################################################################################
53 DIVERT_TO="grub grub-probe"
55 echo -n "CN: Undiverting binaries if necessary:"
56 for i in $DIVERT_TO; do
57 if [ -e /usr/sbin/$i.real ]; then
58 dpkg-divert --remove --rename --package 'kernel-2.6-cn' \
59 --divert /usr/sbin/$i.real /usr/sbin/$i >/dev/null
65 ################################################################################
67 # detect existing Grub2 installation
70 if [ \( -e /boot/grub/grub.cfg \) -o \( -e /boot/grub/core.img \) -o \( -e /usr/lib/grub/i386-pc/ext2.mod \) ]; then
71 echo "CN: Detected GRUB2 installation, will try to use it."
73 if [ -e /boot/grub/menu.lst ]; then
74 echo "CN: Oops, GRUB1 (Legacy) installation detected. Will try to upgrade to GRUB2."
77 echo "CN: No GRUB2 detected, will continue with GRUB1 as default option."
80 ################################################################################
82 # check if we are under Xen DomU PV
83 # (perhaps check /sys/hypervisor/uuid in the future)
86 if [ \( -w /dev/xvda \) -o \( -w /dev/xvdb \) ]; then
87 echo "CN: Detected DomU instance, won't install Grub MBR."
91 ################################################################################
94 echo -n "CN: Configuring system (this will take a while):"
96 # generate kernel-img.conf
97 if [ ! -e /etc/kernel-img.conf ]; then
98 touch /etc/kernel-img.conf
101 # update postinst_hook for grub/grub2
102 if grep -q postinst_hook /etc/kernel-img.conf; then
103 cp_check_and_sed '^postinst_hook' \
104 's;^postinst_hook[[:blank:]]*=.*;postinst_hook = /usr/sbin/update-grub;g' \
105 /etc/kernel-img.conf || true
107 echo "postinst_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
110 # update postrm_hook for grub/grub2
111 if grep -q postrm_hook /etc/kernel-img.conf; then
112 cp_check_and_sed '^postrm_hook' \
113 's;^postrm_hook[[:blank:]]*=.*;postrm_hook = /usr/sbin/update-grub;g' \
114 /etc/kernel-img.conf || true
116 echo "postrm_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
120 if grep -q do_initrd /etc/kernel-img.conf; then
121 cp_check_and_sed '^do_initrd' \
122 's/^do_initrd[[:blank:]]*=.*/do_initrd = yes/g' \
123 /etc/kernel-img.conf || true
125 echo "do_initrd = yes" >> /etc/kernel-img.conf
128 echo -n " kernel-img.conf"
130 # generate initial grub loaders
131 if [ "x$GRUB2" = "xno" ]; then
133 if [ ! -d "$grub_dir" ]; then
136 if [ -d /usr/lib/grub/i386-pc ]; then
137 cp -a /usr/lib/grub/i386-pc/* "$grub_dir"
139 elif [ -d /usr/lib/grub/x86_64-pc ]; then
140 cp -a /usr/lib/grub/x86_64-pc/* "$grub_dir"
145 if [ ! -d /boot/grub ]; then
147 if [ -d /usr/lib/grub/i386-pc ]; then
148 cp -a /usr/lib/grub/i386-pc/* /boot/grub
154 # create/update grub configuration
155 if [ "x$GRUB2" = "xno" ]; then
157 if [ -e "$menu_file" ]; then
158 # is there uncompatibile grub conf present?
159 if ! grep -q 'AUTOMAGIC KERNELS LIST' "$menu_file"; then
160 mv -f "$menu_file" "$menu_file.old"
163 if [ ! -e "$menu_file" ]; then
164 yes | update-grub >/dev/null 2>&1 || true
166 update-grub >/dev/null 2>&1 || true
170 touch /boot/grub/grub.cfg
171 update-grub >/dev/null 2>&1 || true
176 if uname -a | grep -q grsec; then
177 if [ -x /sbin/chpax ]; then
179 if [ -x /usr/sbin/grub.real ]; then
180 chpax -spmrx /usr/sbin/grub.real >/dev/null 2>&1 || true
181 elif [ -x /usr/sbin/grub ]; then
182 chpax -spmrx /usr/sbin/grub >/dev/null 2>&1 || true
186 if [ -x /usr/sbin/grub-probe.real ]; then
187 chpax -spmrx /usr/sbin/grub-probe.real >/dev/null 2>&1 || true
188 elif [ -x /usr/sbin/grub-probe ]; then
189 chpax -spmrx /usr/sbin/grub-probe >/dev/null 2>&1 || true
196 # remove obsolete devfs/compat links and restore normal udev behaviour
197 rm -f /etc/udev/rules.d/devfs.rules /etc/udev/rules.d/compat.rules \
198 /etc/udev/rules.d/compat-full.rules
199 #if [ ! -e /etc/udev/rules.d/udev.rules ]; then
200 # ln -s ../udev.rules /etc/udev/rules.d/udev.rules
202 udevadm control --reload_rules >/dev/null 2>&1 || true
203 udevadm settle || true
206 # update device map if possible
207 if [ "x$GRUB2" = "xno" ]; then
209 if [ -f "$device_map" ]; then
210 mv -f "$device_map" "$device_map.old"
212 # possible situation when upgrading from Grub1 to Grub2
213 if [ ! -x /usr/sbin/grub ]; then
215 echo "CN: FATAL ERROR while trying to execute GRUB1!"
216 echo "CN: Do not reboot your server and report this to syshelp@carnet.hr immediately!"
219 grub --batch --no-floppy --device-map="$device_map" <<'EOF' >/dev/null 2>&1 || true
222 if [ ! -s "$device_map" ]; then
223 if [ -f "$device_map.old" ]; then
224 mv -f "$device_map.old" "$device_map"
228 rm -f "$device_map.old"
232 grub-mkdevicemap --no-floppy >/dev/null 2>&1 || true
233 grub-install --no-floppy --grub-setup=/bin/true "$(grub-probe -t drive /boot/grub)" >/dev/null 2>&1 || true
237 # import GRUB helper functions (again, updated device map)
238 . /usr/share/kernel-cn/grub-functions.sh
240 if [ "x$GRUB2" = "xno" ]; then
242 # get install device (0x80 BIOS device)
243 install_device=$(grep '^(hd0)' "$device_map" | \
244 sed -e 's%[^[:space:]]*[[:space:]]*\([^[:space:]]*\)%\1%')
245 if [ -z "$install_device" ]; then
247 echo "CN: FATAL ERROR while detecting boot disk!"
248 echo "CN: Do not reboot your server and report this to syshelp@carnet.hr immediately!"
252 # oops, install device is a symlink...
253 if [ -h "$install_device" ]; then
254 install_device_resolved=$(resolve_symlink "$install_device")
255 if [ -z "$install_device_resolved" ]; then
256 install_device_resolved="$install_device"
259 # try to fix device map with symlink resolved device
260 if [ "x$install_device_resolved" != "x$install_device" ]; then
261 cp_check_and_sed '^\(hd0\)' \
262 "s;^(hd0).*;(hd0) $install_device_resolved;" "$device_map" \
268 install_device="(hd0)"
272 # install GRUB loader: this will work for both Grub1 and Grub2
273 if [ "x$GRUB_MBR" = "xyes" ]; then
274 if ! grub-install --no-floppy "$install_device" >/dev/null 2>&1; then
276 echo "CN: FATAL ERROR while running grub-install on $install_device!"
277 echo "CN: Do not reboot your server and report this to syshelp@carnet.hr immediately!"
283 # fix possible wrong params in menu.lst
284 if [ "x$GRUB2" = "xno" ]; then
286 cp_check_and_sed '^# groot=' \
287 "s;^# groot=.*;# groot=$grub_root_device;g" \
289 cp_check_and_sed '^# kopt=' \
290 "s;^# kopt=\(.*\)root=[^[:space:]]*\(.*\);# kopt=\1root=$root_device\2;g" \
293 update-grub >/dev/null 2>&1 || true
296 # fix possible wrong params in menu.lst
297 if [ "x$GRUB2" = "xno" ]; then
299 # ... and final stage of devfs/udev brokeness fix
300 if [ "x$install_device_resolved" != "x$install_device" ]; then
301 # get original (symlinked device)
302 root_device=$(find_device_nonresolved "/")
303 if [ -z "$root_device" ]; then
304 root_device=$(find_root_device)
308 cp_check_and_sed '^\(hd0\)' \
309 "s;^(hd0).*;(hd0) $install_device;" "$device_map" \
312 # fix global root= invocation
313 cp_check_and_sed '^# kopt=' \
314 "s;^# kopt=\(.*\)root=[^[:space:]]*\(.*\);# kopt=\1root=$root_device\2;g" \
317 # fix root= invocation for individual kernel profiles
318 cp_check_and_sed '^kernel' \
319 "s;\(^kernel.*\)root=[^[:space:]]*\(.*\);\1root=$root_device\2;g" \
325 # install to other boot sectors if needed (better safe than sorry)
326 if [ "x$GRUB_MBR" = "xyes" ]; then
327 if [ "x$GRUB2" = "xyes" ]; then
329 db_get grub-pc/install_devices
330 for i in `echo $RET | sed -e 's/,/ /g'`; do
331 real_device="$(readlink -f "$i")"
332 if [ -e "$real_device" ]; then
333 grub-install --force --no-floppy $real_device \
334 >/dev/null 2>&1 || true
342 if [ -e /etc/lilo.conf ]; then
343 mv -f /etc/lilo.conf /etc/lilo.conf.old
348 if [ -x /usr/share/mdadm/mkconf ]; then
349 if [ ! -e /etc/mdadm/mdadm.conf ]; then
350 touch /etc/mdadm/mdadm.conf
353 /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.$$
354 if ! cmp -s /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf; then
355 mv /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf
357 rm -f /etc/mdadm/mdadm.conf.$$ /etc/initramfs-tools/hooks/md \
358 /var/lib/mdadm/CONF-UNCHECKED
362 # update initramfs accordingly (because of mdadm and udev)
363 update-initramfs -u -k all >/dev/null 2>&1 || true
369 ################################################################################
371 # rest of configuration...
372 echo -n "CN: Modifying the neccessary system files:"
375 if getent group proc >/dev/null 2>&1; then
376 groupdel proc >/dev/null 2>&1
380 # remove oidentd from oident group
381 if getent group oident >/dev/null 2>&1; then
383 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup' \
384 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup/OIDENT_GROUP=oident/g' \
385 /etc/default/oidentd || true
387 # old kernel-2.6-cn default
388 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc' \
389 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc/OIDENT_GROUP=oident/g' \
390 /etc/default/oidentd || true
395 # default kernel parameters
396 rm -f /etc/sysctl.conf.$$
398 # old kernel params (skipping some of the obsolete or overrided entries)
399 if [ -e /etc/sysctl.conf ]; then
400 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\.maps_protect' \
401 /etc/sysctl.conf >> /etc/sysctl.conf.$$
404 # finished with merging, move into sysctl.conf
405 cp_mv /etc/sysctl.conf.$$ /etc/sysctl.conf
406 echo -n " sysctl.conf"
409 service procps restart
411 # finished with basic kernel-cn stuff
414 ################################################################################
417 echo -n "CN: Setting up PAM configurations:"
419 # update pam_limits accordingly
420 if [ -e /etc/security/limits.conf ]; then
421 rm -f /etc/security/limits.conf.$$
422 cp /etc/security/limits.conf /etc/security/limits.conf.$$
423 cp-update kernel-cn /etc/security/limits.conf.$$ <<'EOF'
427 @users soft nproc 100
428 @users hard nproc 150
430 cp_mv /etc/security/limits.conf.$$ /etc/security/limits.conf
435 if [ -e /etc/pam.d/login ]; then
436 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
437 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
438 /etc/pam.d/login || true
443 if [ -e /etc/pam.d/ssh ]; then
444 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
445 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
446 /etc/pam.d/ssh || true
453 ################################################################################
455 # dh_installdeb will replace this with shell code automatically
456 # generated by other debhelper scripts.