File: kernel_grub_rm.sh

package info (click to toggle)
kernel-package 8.135
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,008 kB
  • ctags: 696
  • sloc: perl: 3,089; makefile: 2,344; sh: 538
file content (90 lines) | stat: -rwxr-xr-x 2,579 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
#                               -*- Mode: Sh -*- 
# kernel_grub_rm.sh --- 
# Author           : Manoj Srivastava ( srivasta@glaurung.green-gryphon.com ) 
# Created On       : Wed Jul  4 22:18:43 2001
# Created On Node  : glaurung.green-gryphon.com
# Last Modified By : Manoj Srivastava
# Last Modified On : Mon Jan 10 18:00:26 2005
# Last Machine Used: glaurung.internal.golden-gryphon.com
# Update Count     : 9
# Status           : Unknown, Use with caution!
# HISTORY          : 
# Description      : 
# 
# 

CONFIG_FILE=/etc/kernel_grub.conf
if [ -x /bin/mktemp ]; then
    TMPFILE=$(mktemp -t kpkg-postrm-grub.XXXXXX) || \
        { echo "Cannot create temporary file" >&2 ; exit 1; }
elif [ -x /bin/tempfile ]; then
    TMPFILE=$(tempfile -p kpkg-postrm-grub -m 0600 )|| \
        { echo "Cannot create temporary file" >&2 ; exit 1; };
else
    set -e
    mkdir /tmp/kpkg-postrm-grub.$$
    TMPFILE=/tmp/kpkg-postrm-grub.$$/tmpfile
    set +e
fi
trap "[ -f $TMPFILE ] && rm -f $TMPFILE; exit 1" 1 2 3 13 15


### Defaults
grub_menu_lst=/boot/grub/menu.lst
grub_kernel_partition='(hd0,0)'
grub_root_partition='(hd0,0)'             # the location of root filesystem.
# Set this to 'YES' if /boot and / are on different partitions
kernel_not_on_root_partition=''
# kernel_boot_options="hdc=ide-scsi"    # any options come here.

if [ -e $CONFIG_FILE ]; then
    . $CONFIG_FILE
fi

if [ $# -ne 2 ]; then
    echo "Usage: $0 version location"
    exit 2
fi

version="$1"
vmlinuz_location="$2"

# This means we have a separate boot partition
if [ "$kernel_not_on_root_partition" == 'YES' ]; then
    vmlinuz_location=`basename "$vmlinuz_location"`
    echo $vmlinuz_location
fi

if [ -f $grub_menu_lst ]; then
    if grep "^kernel $grub_kernel_partition.*$vmlinuz_location"  $grub_menu_lst >/dev/null 2>&1; then
	echo "Removing kernel entry from $grub_menu_lst"
	perl -nle "print unless /^#Autogenerated by kernel-image $version/ .. /^#End kernel-image $version/" < $grub_menu_lst > $TMPFILE
	mv -f $TMPFILE $grub_menu_lst
    else
	echo "Seems like this kernel (version $version) is not"
	echo "installed in $grub_menu_lst. Skipping."
    fi
fi

rm -f $TMPFILE
if [ -d /tmp/kpkg-postrm-grub.$$ ]; then
    rmdir /tmp/kpkg-postrm-grub.$$
fi

exit 0


version="$1"

if [ -f $grub_menu_lst ]; then
    perl -nle "print unless /^#Autogenerated by kernel-image $version/ .. /^#End kernel-image $version/" < $grub_menu_lst > $TMPFILE
    mv -f $TMPFILE $grub_menu_lst
fi


rm -f $TMPFILE
if [ -d /tmp/kpkg-postrm-grub.$$ ]; then
    rmdir /tmp/kpkg-postrm-grub.$$
fi
exit 0