summaryrefslogtreecommitdiff
blob: 274e73e80d61c51cda2b304d76fb1060d5bfbc51 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash

source /sbin/functions.sh
source /etc/make.globals
esyslog() {
	echo &> /dev/null
}
echo ""

# is modules-rebuild available ?
if [ ! -x "/usr/sbin/module-rebuild" ] ; then
    MODULE_REBUILD="false"
else
    MODULE_REBUILD="true"
fi

## runs with UID=0 ?
if [[ `id -u` -ne 0 ]] ; then
    eerror "This script requires root privileges"
    eerror "Exiting!"
    echo ""
    exit 1
fi

## check if we are in the kernel root-dir
if [[ ! -f ${PWD}/Makefile ]] ; then
	eerror "You are either in a subdirectory of your kernel dir or not in any kernel dir."
	eerror "You better change to your kernel top level directory and run this script again,"
	eerror "or the kernel will not get installed ...."
	echo ""
	exit 1
fi

if [[ -z "${KERNEL_ARCH}" ]] ; then
    ARCH="$( uname -m )"
fi

case "${ARCH}" in
    i*86)
	KERNEL_ARCH="i386"
	;;
    x86_64)
	KERNEL_ARCH="${ARCH}"
	;;
    alpha*)
	KERNEL_ARCH="${ARCH}"
	;;
esac

if [[ ! -e ${PWD}/arch/${KERNEL_ARCH}/boot/bzImage ]] ; then
    eerror "${PWD}/arch/${KERNEL_ARCH}/boot does not contain an compressed kernel image."
    eerror "If you are in the top-level directory of your kernel, please run"
    eerror "'make' first. Otherwise, if you are not in /usr/src/linux"
    eerror "change into your top-level kerneldirectory!"
    exit 1
fi

if [[ -n "${ROOT}" && ! -d "${ROOT}" ]] ; then
    eerror "The given ROOT does not exist. Please create it first."
    exit 1
fi

if [[ "$1" == "-p" ]] ; then
    PRETEND="true"
fi

getmakefilevar() {
    grep $1 $2 | head -n 1 | cut -d = -f 2- | awk '{ print $1 }'
}

# to get a version number out of the Makefile
KV_MAJOR="`getmakefilevar VERSION Makefile`"
KV_MINOR="`getmakefilevar PATCHLEVEL Makefile`"
KV_PATCH="`getmakefilevar SUBLEVEL Makefile`"
KV_TYPE="`getmakefilevar EXTRAVERSION Makefile`"
KV_CONFIG="`grep CONFIG_LOCALVERSION .config | head -n 1 | cut -d'"' -f 2`"

einfo "\033[01mPhase 1:\033[0m"
ebegin "  [1/2] Gathering kernel version"
KV_FULL="$KV_MAJOR.$KV_MINOR.$KV_PATCH$KV_TYPE$KV_CONFIG"
eend $?

if [[ -z "`grep /boot /etc/mtab`" && -z "${ROOT}" ]] ; then
    ebegin "  [2/2] Mounting /boot"
    mount /boot 2> /dev/null
    eend $?
else
    einfo "  [2/2] Skipping 'mount /boot', already mounted ..."
fi
echo

einfo "\033[01mPhase 2:\033[0m"
einfo "  You're going to install the following files:"
einfo "    ${ROOT}/boot/kernel-${KV_FULL}"
einfo "    ${ROOT}/boot/config-${KV_FULL}"
einfo "    ${ROOT}/lib/modules/${KV_FULL}"

if [[ -z "${PRETEND}" ]] ; then
    echo
    ewarn "You are going to install kernel-${KV_FULL}."
    ewarn "If this is not desired, then hit \033[01;31mCTRL+C\033[0m now!"
    echo
    echo -ne "\033[01m Waiting ${EMERGE_WARNING_DELAY} seconds: "

    for i in `seq ${EMERGE_WARNING_DELAY} -1 1`; do
	echo -en "\033[01;31m${i}\033[0m "
	sleep 1
    done
    echo
    echo

    einfo "\033[01mPhase 3:\033[0m"

    ebegin "  [1/3] bzImage"
    cp -pf arch/${KERNEL_ARCH}/boot/bzImage ${ROOT}/boot/kernel-${KV_FULL} 2>/dev/null
    eend $?

    ebegin "  [2/3] .config"
    cp -pf .config ${ROOT}/boot/config-${KV_FULL} 2> /dev/null
    eend $?

    ebegin "  [3/3] modules"
    if [[ -z "${ROOT}" ]] ; then
	make modules_install &> /dev/null
    elif [[ -n "${ROOT}" && -d "${ROOT}" ]] ; then
        INSTALL_MOD_PATH="${ROOT}" make modules_install &> /dev/null
    fi

    if [ "${MODULE_REBUILD}" = "true" ] ; then
	einfo "\033[01mPhase 4:\033[0m"

	echo
	echo -ne "\033[01m Waiting ${EMERGE_WARNING_DELAY} seconds: "

	for i in `seq ${EMERGE_WARNING_DELAY} -1 1`; do
	    echo -en "\033[01;31m${i}\033[0m "
	    sleep 1
	done
	echo

	ebegin "  [1/1] rebuilding external modules"

	for i in $( /usr/sbin/module-rebuild list )
	do
	    einfo "Remerging ${i}"
	    /usr/bin/emerge "${i}"
	done

	eend $?
    else
	ewarn "Be sure to remerge any depending external modules, otherwise they won't be"
	ewarn "available when you reboot to your new kernel (i.e. alsa-driver, nvidia-kernel, ...)"
    fi

    echo
    ewarn "Please add the following lines to your grub.conf:"
    echo "  title   GNU/Linux ${KV_FULL}"
    echo "  root    (hd0,0)"
    echo "  kernel  (hd0,0)/kernel-${KV_FULL} `cat /proc/cmdline`"
    echo
fi
echo