- nova inacica paketa koja prestaje ovisiti o ExecShield ojacanoj verziji,
[kernel-cn.git] / debian / postinst
index 79a5a79..2167bed 100755 (executable)
@@ -109,8 +109,12 @@ echo -n " kernel-img.conf"
 # generate initial grub loaders
 if [ ! -d "$grub_dir" ]; then
     mkdir -p "$grub_dir"
+    # x86
     if [ -d /usr/lib/grub/i386-pc ]; then
         cp -a /usr/lib/grub/i386-pc/* "$grub_dir"
+    # x86_64
+    elif [ -d /usr/lib/grub/x86_64-pc ]; then
+        cp -a /usr/lib/grub/x86_64-pc/* "$grub_dir"
     fi
 fi
 echo -n " grub1"
@@ -130,30 +134,34 @@ fi
 echo -n " grub2"
 
 # workaround grsec
-if [ -x /sbin/chpax ]; then
-    if [ -x /usr/sbin/grub ]; then
-        chpax -spmrx /usr/sbin/grub || true
+if uname -a | grep -q grsec; then
+    if [ -x /sbin/chpax ]; then
+        # grub
+        if [ -x /usr/sbin/grub.real ]; then
+            chpax -spmrx /usr/sbin/grub.real >/dev/null 2>&1 || true
+        elif [ -x /usr/sbin/grub ]; then
+            chpax -spmrx /usr/sbin/grub >/dev/null 2>&1 || true
+        fi
+
+        # grub-probe
+        if [ -x /usr/sbin/grub-probe.real ]; then
+            chpax -spmrx /usr/sbin/grub-probe.real >/dev/null 2>&1 || true
+        elif [ -x /usr/sbin/grub-probe ]; then
+            chpax -spmrx /usr/sbin/grub-probe >/dev/null 2>&1 || true
+        fi
+
+        echo -n " grsec"
     fi
-    if [ -x /usr/sbin/grub-probe ]; then
-        chpax -spmrx /usr/sbin/grub-probe || true
-    fi
-fi
-echo -n " grub3"
-
-# workaround execshield
-SHIELD=$(sysctl -e -n kernel.exec-shield)
-if [ ! -z "$SHIELD" ]; then
-    sysctl -w -e kernel.exec-shield=0 >/dev/null 2>&1
-    echo -n " execshield1"
 fi
 
 # remove obsolete devfs/compat links and restore normal udev behaviour
 rm -f /etc/udev/rules.d/devfs.rules /etc/udev/rules.d/compat.rules \
     /etc/udev/rules.d/compat-full.rules
-if [ ! -e /etc/udev/rules.d/udev.rules ]; then
-    ln -s ../udev.rules /etc/udev/rules.d/udev.rules
-fi
-udevcontrol reload_rules >/dev/null 2>&1 || true
+#if [ ! -e /etc/udev/rules.d/udev.rules ]; then
+#    ln -s ../udev.rules /etc/udev/rules.d/udev.rules
+#fi
+udevadm control --reload_rules >/dev/null 2>&1 || true
+udevsettle || true
 echo -n " udev"
 
 # update device map if possible
@@ -168,10 +176,13 @@ if [ ! -s "$device_map" ]; then
         mv -f "$device_map.old" "$device_map"
     fi
 
-:q!else
+else
     rm -f "$device_map.old"
 fi
-echo -n " grub4"
+echo -n " grub3"
+
+# import GRUB helper functions (again, updated device map)
+. /usr/share/kernel-2.6-cn/grub-functions.sh
 
 # get install device (0x80 BIOS device)
 install_device=$(grep '^(hd0)' "$device_map" | \
@@ -189,6 +200,7 @@ if [ -h "$install_device" ]; then
     if [ -z "$install_device_resolved" ]; then
         install_device_resolved="$install_device"
     fi
+
     # try to fix device map with symlink resolved device
     if [ "x$install_device_resolved" != "x$install_device" ]; then
         cp_check_and_sed '^\(hd0\)' \
@@ -196,7 +208,7 @@ if [ -h "$install_device" ]; then
             || true
     fi
 fi
-echo -n " grub5"
+echo -n " grub4"
 
 # install GRUB loader
 if ! grub-install --no-floppy "$install_device" >/dev/null 2>&1; then
@@ -205,7 +217,7 @@ if ! grub-install --no-floppy "$install_device" >/dev/null 2>&1; then
     echo "CN: Do not reboot your server and report this to OTRS immediately!"
     exit 1
 fi
-echo -n " grub6"
+echo -n " grub5"
 
 # fix possible wrong params in menu.lst
 cp_check_and_sed '^# groot=' \
@@ -215,13 +227,32 @@ cp_check_and_sed '^# kopt=' \
   "s;^# kopt=\(.*\)root=[^[:space:]]*\(.*\);# kopt=\1root=$root_device\2;g" \
       "$menu_file" || true
 /usr/sbin/update-grub >/dev/null 2>&1 || true
-echo -n " grub7"
+echo -n " grub6"
 
-# restore execshield state
-if [ ! -z "$SHIELD" ]; then
-    sysctl -w -e "kernel.exec-shield=$SHIELD" >/dev/null 2>&1
-    echo -n " execshield2"
+# and final stage of devfs/udev brokeness fix
+if [ "x$install_device_resolved" != "x$install_device" ]; then
+    # get original (symlinked device)
+    root_device=$(find_device_nonresolved "/")
+    if [ -z "$root_device" ]; then
+        root_device=$(find_root_device)
+    fi
+
+    # fix (hd0) mapping
+    cp_check_and_sed '^\(hd0\)' \
+        "s;^(hd0).*;(hd0)      $install_device;" "$device_map" \
+        || true
+
+    # fix global root= invocation
+    cp_check_and_sed '^# kopt=' \
+      "s;^# kopt=\(.*\)root=[^[:space:]]*\(.*\);# kopt=\1root=$root_device\2;g" \
+          "$menu_file" || true
+
+    # fix root= invocation for individual kernel profiles
+    cp_check_and_sed '^kernel' \
+      "s;\(^kernel.*\)root=[^[:space:]]*\(.*\);\1root=$root_device\2;g" \
+          "$menu_file" || true
 fi
+echo -n " grub7"
 
 # disable lilo
 if [ -e /etc/lilo.conf ]; then
@@ -280,7 +311,6 @@ fi
 # default kernel parameters
 rm -f /etc/sysctl.conf.$$
 cat > /etc/sysctl.conf.$$ <<EOF
-kernel.exec-shield=3
 kernel.maps_protect=1
 net.core.rmem_default=1048576
 net.core.wmem_default=1048576
@@ -305,7 +335,7 @@ EOF
 
 # old kernel params
 if [ -e /etc/sysctl.conf ]; then
-    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' \
+    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' \
         /etc/sysctl.conf >> /etc/sysctl.conf.$$
 fi