#!/bin/sh TMPDIR=/tmp/unsupported-patch-for-87262.$$ mkdir $TMPDIR cd $TMPDIR OLD_VERSION=2.6.20-15-generic NEW_VERSION=2.6.20-15-generic-with-unsupported-patch-for-87262 OLD_VMLINUZ=/boot/vmlinuz-$OLD_VERSION NEW_VMLINUZ=/boot/vmlinuz-$NEW_VERSION OLD_INITRD=/boot/initrd.img-$OLD_VERSION NEW_INITRD=/boot/initrd.img-$NEW_VERSION PREPATCH_MD5=`md5sum $OLD_VMLINUZ | colrm 33` if [ x"$PREPATCH_MD5" != x"11e0cbf44b1dc1bacdcfaa6780161b54" ]; then echo "unexpected version of $OLD_VMLINUZ" exit 1 fi echo working... dd bs=7810 count=1 if=$OLD_VMLINUZ of=headers 2>/dev/null dd bs=7810 skip=1 if=$OLD_VMLINUZ of=kernel.gz+extrabytes 2>/dev/null echo working.... KERNEL_GZ_SIZE=`zcat kernel.gz+extrabytes 2>/dev/null | gzip -nc9 | wc -c` dd skip=$KERNEL_GZ_SIZE bs=1 if=kernel.gz+extrabytes of=extrabytes 2>/dev/null dd bs=$KERNEL_GZ_SIZE count=1 if=kernel.gz+extrabytes of=kernel.gz 2>/dev/null echo working...... SIZE1=`stat -c%s kernel.gz+extrabytes` SIZE2=$(echo `stat -c%s kernel.gz` + `stat -c%s extrabytes` | bc) if [ ! $SIZE1 -eq $SIZE2 ]; then echo "error 1: sizes dont match" exit 1 fi zcat kernel.gz > kernel.unpatched zcat kernel.gz > kernel.patched /bin/echo -ne '\0100\0100' \ | dd conv=notrunc bs=1 seek=1499078 count=2 of=kernel.patched 2>/dev/null echo working......... od -Ax -tx1z kernel.unpatched > kernel.unpatched.hex 2>/dev/null echo working............ od -Ax -tx1z kernel.patched > kernel.patched.hex 2>/dev/null echo "diff of patch:" diff kernel.unpatched.hex kernel.patched.hex gzip -nc9 kernel.patched > kernel.patched.gz # reset the patched kernel.gz timestamp to the original one dd conv=notrunc bs=8 count=1 if=kernel.gz of=kernel.patched.gz 2>/dev/null SIZE1=`stat -c%s kernel.gz` SIZE2=`stat -c%s kernel.patched.gz` if [ ! $SIZE1 -eq $SIZE2 ]; then echo "error 2: sizes dont match" exit 2 fi mkdir -p boot cat headers kernel.patched.gz extrabytes > .$NEW_VMLINUZ SIZE1=`stat -c%s $OLD_VMLINUZ` SIZE2=`stat -c%s .$NEW_VMLINUZ` if [ ! $SIZE1 -eq $SIZE2 ]; then echo "error 3: sizes dont match" exit 3 fi POSTPATCH_MD5=`md5sum .$NEW_VMLINUZ | colrm 33` if [ x"$POSTPATCH_MD5" != x"d153dd91c1a1bff4d806df73b0ee5e7e" ]; then echo "patch failed. final md5sum didnt match expected value $POSTPATCH_MD5" exit 1 fi echo echo "patch succeeded - found expected md5sum." echo echo "copying patched kernel into /boot. old kernel is untouched." sudo mv .$NEW_VMLINUZ /boot sudo cp -p $OLD_INITRD $NEW_INITRD echo echo "update-grub menu.lst?" echo "hit ctrl-c if youve changed your mind or you want to do " echo "it manually, otherwise hit enter to continue." read line sudo /usr/sbin/update-grub echo echo "unhiding grub menu, in case new kernel doesnt work." sudo sed -i -e "s/^hiddenmenu/#hiddenmenu/" /boot/grub/menu.lst echo echo "creating uninstall script in /boot" UNINSTALL=/boot/uninstall-unsupported-patch-for-87262.sh echo "#!/bin/sh" > $TMPDIR/$UNINSTALL echo "sudo rm -f $NEW_VMLINUZ" >> $TMPDIR/$UNINSTALL echo "sudo rm -f $NEW_INITRD" >> $TMPDIR/$UNINSTALL echo "sudo update-grub" >> $TMPDIR/$UNINSTALL echo "sudo rm -f $UNINSTALL" >> $TMPDIR/$UNINSTALL sudo mv $TMPDIR/$UNINSTALL $UNINSTALL sudo chmod a+rx $UNINSTALL echo echo "all done. you can reboot now." echo "if you get a kernel panic, or it doesnt work for you, select " echo "the previous, unpatched kernel, at startup time, and then run " echo "$UNINSTALL" echo "... to get rid of the patched kernel " echo