parent
6e47f147d8
commit
0a98792990
@ -1,94 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set_bootloader() {
|
|
||||||
if [ "x${BOOTLOADER}" == 'xgrub' ]
|
|
||||||
then
|
|
||||||
set_grub_bootloader
|
|
||||||
else
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
set_grub_bootloader() {
|
|
||||||
local GRUB_CONF="${BOOTDIR}/grub/grub.conf"
|
|
||||||
|
|
||||||
print_info 1 ''
|
|
||||||
print_info 1 "Adding kernel to ${GRUB_CONF}..."
|
|
||||||
if [ "${BOOTFS}" != '' ]
|
|
||||||
then
|
|
||||||
GRUB_BOOTFS=${BOOTFS}
|
|
||||||
else
|
|
||||||
# Extract block device information from /etc/fstab
|
|
||||||
GRUB_ROOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "/" ) { print $1; exit }' /etc/fstab)
|
|
||||||
GRUB_BOOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "'${BOOTDIR}'") { print $1; exit }' /etc/fstab)
|
|
||||||
|
|
||||||
# If ${BOOTDIR} is not defined in /etc/fstab, it must be the same as /
|
|
||||||
[ "x${GRUB_BOOTFS}" == 'x' ] && GRUB_BOOTFS=${GRUB_ROOTFS}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Read GRUB device map
|
|
||||||
[ ! -d ${TEMP} ] && mkdir ${TEMP}
|
|
||||||
grub --batch --device-map=${TEMP}/grub.map <<EOF >/dev/null 2>&1
|
|
||||||
quit
|
|
||||||
EOF
|
|
||||||
# Get the GRUB mapping for our device
|
|
||||||
local GRUB_BOOT_DISK1=$(echo ${GRUB_BOOTFS} | sed -e 's#\(/dev/.\+\)[[:digit:]]\+#\1#')
|
|
||||||
local GRUB_BOOT_DISK=$(awk '{if ($2 == "'${GRUB_BOOT_DISK1}'") {gsub(/(\(|\))/, "", $1); print $1;}}' ${TEMP}/grub.map)
|
|
||||||
|
|
||||||
local GRUB_BOOT_PARTITION=$(echo ${GRUB_BOOTFS} | sed -e 's#/dev/.\+\([[:digit:]]?*\)#\1#')
|
|
||||||
[ ! -d ${TEMP} ] && rm -r ${TEMP}
|
|
||||||
|
|
||||||
# Create grub configuration directory and file if it doesn't exist.
|
|
||||||
[ ! -e `dirname ${GRUB_CONF}` ] && mkdir -p `dirname ${GRUB_CONF}`
|
|
||||||
|
|
||||||
if [ ! -e ${GRUB_CONF} ]
|
|
||||||
then
|
|
||||||
if [ "${GRUB_BOOT_DISK}" != '' -a "${GRUB_BOOT_PARTITION}" != '' ]
|
|
||||||
then
|
|
||||||
GRUB_BOOT_PARTITION=`expr ${GRUB_BOOT_PARTITION} - 1`
|
|
||||||
# grub.conf doesn't exist - create it with standard defaults
|
|
||||||
touch ${GRUB_CONF}
|
|
||||||
echo 'default 0' >> ${GRUB_CONF}
|
|
||||||
echo 'timeout 5' >> ${GRUB_CONF}
|
|
||||||
echo >> ${GRUB_CONF}
|
|
||||||
|
|
||||||
# Add grub configuration to grub.conf
|
|
||||||
echo "# Genkernel generated entry, see GRUB documentation for details" >> ${GRUB_CONF}
|
|
||||||
echo "title=Gentoo Linux ($KV)" >> ${GRUB_CONF}
|
|
||||||
echo -e "\troot (${GRUB_BOOT_DISK},${GRUB_BOOT_PARTITION})" >> ${GRUB_CONF}
|
|
||||||
if [ "${BUILD_RAMDISK}" -eq '0' ]
|
|
||||||
then
|
|
||||||
echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=${GRUB_ROOTFS}" >> ${GRUB_CONF}
|
|
||||||
else
|
|
||||||
echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=/dev/ram0 init=/linuxrc real_root=${GRUB_ROOTFS}" >> ${GRUB_CONF}
|
|
||||||
echo -e "\tinitrd /initramfs-${KNAME}-${ARCH}-${KV}" >> ${GRUB_CONF}
|
|
||||||
fi
|
|
||||||
echo >> ${GRUB_CONF}
|
|
||||||
else
|
|
||||||
print_error 1 "Error! ${BOOTDIR}/grub/grub.conf does not exist and the correct settings can not be automatically detected."
|
|
||||||
print_error 1 "Please manually create your ${BOOTDIR}/grub/grub.conf file."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# grub.conf already exists; so...
|
|
||||||
# ... Clone the first boot definition and change the version.
|
|
||||||
local TYPE='ramfs'
|
|
||||||
|
|
||||||
cp -f ${GRUB_CONF} ${GRUB_CONF}.bak
|
|
||||||
awk 'BEGIN { RS="\n"; }
|
|
||||||
{
|
|
||||||
if(match($0, "kernel-" KNAME "-" ARCH "-" KV))
|
|
||||||
{ have_k="1" }
|
|
||||||
if(match($0, "init" TYPE "-" KNAME "-" ARCH "-" KV))
|
|
||||||
{ have_i="1" }
|
|
||||||
if(have_k == "1" && have_i == "1")
|
|
||||||
{ exit 1; }
|
|
||||||
}' KNAME=${KNAME} ARCH=${ARCH} KV=${KV} TYPE=${TYPE} ${GRUB_CONF}.bak
|
|
||||||
if [ "$?" -eq '0' ]
|
|
||||||
then
|
|
||||||
local LIMIT=$(wc -l ${GRUB_CONF}.bak)
|
|
||||||
awk -f ${GK_SHARE}/gen_bootloader_grub.awk LIMIT=${LIMIT/ */} KNAME=${KNAME} ARCH=${ARCH} KV=${KV} TYPE=${TYPE} ${GRUB_CONF}.bak > ${GRUB_CONF}
|
|
||||||
else
|
|
||||||
print_info 1 "GRUB: Definition found, not duplicating."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
BEGIN { RS="\n"; FS=""; OFS=""; ORS=""; state="0"; }
|
|
||||||
{
|
|
||||||
if(state == "0")
|
|
||||||
{
|
|
||||||
if (match($0, /^title=/) || match($0, /^title */))
|
|
||||||
{
|
|
||||||
state = "1";
|
|
||||||
ORIG = ORIG $0 "\n";
|
|
||||||
next;
|
|
||||||
} else {
|
|
||||||
if(match($0, /^[[:space:]]*#/))
|
|
||||||
ORIG = ORIG $0 "\n";
|
|
||||||
extraA = extraA $0 "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(state == "1")
|
|
||||||
{
|
|
||||||
if(match($0, /^[[:space:]]*kernel /))
|
|
||||||
{
|
|
||||||
ORIG = ORIG $0 "\n";
|
|
||||||
i = 0;
|
|
||||||
have_k = "1";
|
|
||||||
my_kernel = $0;
|
|
||||||
sub(/kernel-[[:alnum:][:punct:]]+/, "kernel-" KNAME "-" ARCH "-" KV, my_kernel);
|
|
||||||
} else {
|
|
||||||
if(match($0, /^[[:space:]]*initrd /))
|
|
||||||
{
|
|
||||||
ORIG = ORIG $0 "\n";
|
|
||||||
i = 0;
|
|
||||||
extraC = extraC commentLookahead;
|
|
||||||
|
|
||||||
have_i = "1";
|
|
||||||
my_initrd = "\n" $0;
|
|
||||||
sub(/initr(d|amfs)-[[:alnum:][:punct:]]+/, "init" TYPE "-" KNAME "-" ARCH "-" KV, my_initrd);
|
|
||||||
} else {
|
|
||||||
if($0 == "\n")
|
|
||||||
next;
|
|
||||||
ORIG = ORIG $0 "\n";
|
|
||||||
if(match($0, /^[[:space:]]*#/))
|
|
||||||
{
|
|
||||||
i = 1;
|
|
||||||
if(commentLookahead)
|
|
||||||
commentLookahead = commentLookahead "\n" $0;
|
|
||||||
else
|
|
||||||
commentLookahead = $0;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!(match($0, /^title=/) || match($0, /^title */) ))
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
commentLookahead = "";
|
|
||||||
|
|
||||||
if(have_k != "1")
|
|
||||||
extraB = extraB commentLookahead $0 "\n";
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(have_i != "1")
|
|
||||||
extraC = extraC commentLookahead $0 "\n";
|
|
||||||
else
|
|
||||||
extraD = extraD commentLookahead $0 "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(have_k == "1" && ((match($0, /^title=/) || match($0, /^title */)) || NR == LIMIT))
|
|
||||||
{
|
|
||||||
state = "2";
|
|
||||||
print extraA "title=Gentoo Linux (" KV ")\n";
|
|
||||||
print extraB my_kernel;
|
|
||||||
if(extraC)
|
|
||||||
print "\n" extraC;
|
|
||||||
print my_initrd extraD "\n";
|
|
||||||
if(i == 0)
|
|
||||||
print commentLookahead;
|
|
||||||
print ORIG;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(state == "2")
|
|
||||||
print $0 "\n";
|
|
||||||
}
|
|
Loading…
Reference in new issue