From ce1e10241bb0ca0ec859a515631802e49cc167e9 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 26 Aug 2013 19:33:08 +0200 Subject: [PATCH] genkernel: migrate ALL the code to 4-spaces tabs \t must die! --- README | 39 - defaults/initrd.scripts | 3472 ++++++++++++++++++------------------- defaults/linuxrc | 418 ++--- defaults/udhcpc.scripts | 56 +- doc/genkernel.8.txt | 36 +- gen_arch.sh | 166 +- gen_bootloader.sh | 296 ++-- gen_cmdline.sh | 1166 ++++++------- gen_compile.sh | 678 ++++---- gen_configkernel.sh | 182 +- gen_determineargs.sh | 418 ++--- gen_funcs.sh | 782 ++++----- gen_initramfs.sh | 1962 ++++++++++----------- gen_moddeps.sh | 76 +- gen_package.sh | 366 ++-- genkernel | 402 ++--- genkernel.bash | 36 +- maintenance/docmatcher.py | 364 ++-- 18 files changed, 5438 insertions(+), 5477 deletions(-) delete mode 100644 README mode change 100644 => 100755 defaults/initrd.scripts mode change 100644 => 100755 defaults/linuxrc diff --git a/README b/README deleted file mode 100644 index c202a54..0000000 --- a/README +++ /dev/null @@ -1,39 +0,0 @@ -# $Id$ - -DEPENDENCIES: - - GCC and binutils - - GNU Bash - - PaX Utilities - -USAGE: - See http://www.gentoo.org/doc/en/genkernel.xml or - issue ``genkernel --help''. - -PORTING: - To port to other arches: - - # cd /usr/share/genkernel - # cp -Rp x86 ${myarch} - # mkdir /usr/share/genkernel/pkg/${myarch} - - Modify what is needed in the /usr/share/genkernel/${myarch} - directory, as well making a generic kernel-config. - -IMPORTANT KERNEL NOTES: - - You MUST have /dev/pts turned on. - - To boot genkernel properly, the kernel config must have - Initial RAM disk support. - -BOOTING A KERNEL WITH INITRD: - - GRUB: - root= needs to point to your root partition - vga= should be the resolution you want your screen. 0x317 is - 1024x768 - 16bpp and you'll get a pretty splash if - configured properly - - GRUB EXAMPLE ENTRY: - title=2.6.0 [ Genkernel ] - root (hd0,0) - kernel (hd0,0)/boot/kernel-2.6.0-gentoo root=/dev/hda3 vga=0x317 - initrd (hd0,0)/boot/initrd-2.6.0-gentoo diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts old mode 100644 new mode 100755 index 0534ce5..78deda1 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -3,611 +3,611 @@ . /etc/initrd.defaults splash() { - return 0 + return 0 } [ -e "${INITRD_SPLASH}" ] && . "${INITRD_SPLASH}" is_fbsplash() { - if [ -e "${INITRD_SPLASH}" ] && [ "${FBSPLASH}" = '1' ] - then - return 0 - fi - return 1 + if [ -e "${INITRD_SPLASH}" ] && [ "${FBSPLASH}" = '1' ] + then + return 0 + fi + return 1 } is_plymouth() { - if [ "${PLYMOUTH}" = '1' ] && [ "${QUIET}" = '1' ] \ - && [ -e "${PLYMOUTHD_BIN}" ] - then - return 0 - fi - return 1 + if [ "${PLYMOUTH}" = '1' ] && [ "${QUIET}" = '1' ] \ + && [ -e "${PLYMOUTHD_BIN}" ] + then + return 0 + fi + return 1 } is_plymouth_started() { - [ -n "${PLYMOUTH_FAILURE}" ] && return 1 - is_plymouth && "${PLYMOUTH_BIN}" --ping 2>/dev/null && return 0 - return 1 + [ -n "${PLYMOUTH_FAILURE}" ] && return 1 + is_plymouth && "${PLYMOUTH_BIN}" --ping 2>/dev/null && return 0 + return 1 } splashcmd() { - # plymouth support - local cmd="${1}" - shift - - case "${cmd}" in - init) - is_fbsplash && splash init - is_plymouth && plymouth_init - ;; - - verbose) - is_fbsplash && splash verbose - plymouth_hide - ;; - - quiet) - # no fbsplash support - plymouth_show - ;; - - set_msg) - is_fbsplash && splash set_msg "${1}" - plymouth_message "${1}" - ;; - - hasroot) - # no fbsplash support - plymouth_newroot "${1}" - ;; - esac + # plymouth support + local cmd="${1}" + shift + + case "${cmd}" in + init) + is_fbsplash && splash init + is_plymouth && plymouth_init + ;; + + verbose) + is_fbsplash && splash verbose + plymouth_hide + ;; + + quiet) + # no fbsplash support + plymouth_show + ;; + + set_msg) + is_fbsplash && splash set_msg "${1}" + plymouth_message "${1}" + ;; + + hasroot) + # no fbsplash support + plymouth_newroot "${1}" + ;; + esac } plymouth_init() { - good_msg "Enabling Plymouth" - mkdir -p /run/plymouth || return 1 - - # Make sure that udev is done loading tty and drm - if is_udev - then - udevadm trigger --action=add --attr-match=class=0x030000 \ - >/dev/null 2>&1 - udevadm trigger --action=add --subsystem-match=graphics \ - --subsystem-match=drm --subsystem-match=tty \ - >/dev/null 2>&1 - udevadm settle - fi - - local consoledev= - local other= - read consoledev other < /sys/class/tty/console/active - consoledev=${consoledev:-tty0} - "${PLYMOUTHD_BIN}" --attach-to-session --pid-file /run/plymouth/pid \ - || { - bad_msg "Plymouth load error"; - PLYMOUTH_FAILURE=1 - return 1; - } - plymouth_show - good_msg "Plymouth enabled" + good_msg "Enabling Plymouth" + mkdir -p /run/plymouth || return 1 + + # Make sure that udev is done loading tty and drm + if is_udev + then + udevadm trigger --action=add --attr-match=class=0x030000 \ + >/dev/null 2>&1 + udevadm trigger --action=add --subsystem-match=graphics \ + --subsystem-match=drm --subsystem-match=tty \ + >/dev/null 2>&1 + udevadm settle + fi + + local consoledev= + local other= + read consoledev other < /sys/class/tty/console/active + consoledev=${consoledev:-tty0} + "${PLYMOUTHD_BIN}" --attach-to-session --pid-file /run/plymouth/pid \ + || { + bad_msg "Plymouth load error"; + PLYMOUTH_FAILURE=1 + return 1; + } + plymouth_show + good_msg "Plymouth enabled" } plymouth_hide() { - is_plymouth_started && "${PLYMOUTH_BIN}" --hide-splash + is_plymouth_started && "${PLYMOUTH_BIN}" --hide-splash } plymouth_show() { - is_plymouth_started && "${PLYMOUTH_BIN}" --show-splash + is_plymouth_started && "${PLYMOUTH_BIN}" --show-splash } plymouth_message() { - is_plymouth_started && "${PLYMOUTH_BIN}" --update="${1}" + is_plymouth_started && "${PLYMOUTH_BIN}" --update="${1}" } plymouth_newroot() { - is_plymouth_started && "${PLYMOUTH_BIN}" --newroot="${1}" + is_plymouth_started && "${PLYMOUTH_BIN}" --newroot="${1}" } splash_init() { - if is_udev; then - # if udev, we can load the splash earlier - # In the plymouth case, udev will load KMS automatically - splashcmd init - fi + if is_udev; then + # if udev, we can load the splash earlier + # In the plymouth case, udev will load KMS automatically + splashcmd init + fi } call_func_timeout() { - local func=$1 timeout=$2 pid watcher - [ $# -ne 2 ] && gen_die "call_func_timeout() called with $# arguments" + local func=$1 timeout=$2 pid watcher + [ $# -ne 2 ] && gen_die "call_func_timeout() called with $# arguments" - ( ${func} ) & pid=$! - ( sleep ${timeout} && kill -HUP ${pid} ) 2>/dev/null & watcher=$! - if wait ${pid} 2>/dev/null; then - kill -HUP $watcher 2> /dev/null - wait $watcher 2>/dev/null - return 1 - fi + ( ${func} ) & pid=$! + ( sleep ${timeout} && kill -HUP ${pid} ) 2>/dev/null & watcher=$! + if wait ${pid} 2>/dev/null; then + kill -HUP $watcher 2> /dev/null + wait $watcher 2>/dev/null + return 1 + fi - return 0 + return 0 } modules_load() { - for module in $* - do - echo ${module} >> /etc/modules/extra_load - done + for module in $* + do + echo ${module} >> /etc/modules/extra_load + done - modules_scan extra_load + modules_scan extra_load } modules_scan() { - local MODS - local loaded - - MODS=$(cat /etc/modules/${1} 2>/dev/null) - [ -n "${MODS}" ] && [ -z "${QUIET}" ] && \ - echo -ne "${BOLD} ::${NORMAL} Loading from ${1}: " - - for x in ${MODS} - do - MLOAD=$(echo ${MLIST} | sed -e "s/.*${x}.*/${x}/") - if [ "${MLOAD}" = "${x}" ] # Only module to no-load - then - [ -z "${QUIET}" ] && \ - echo -e "${BOLD} ::${NORMAL} Skipping ${x}..." - elif [ "${MLOAD}" = "${MLIST}" ] - then - if [ -n "${DEBUG}" ]; then - echo -ne "${BOLD} ::${NORMAL} " - echo -ne "Scanning for ${x}..." - fi - modprobe ${x} > /dev/null 2>&1 - loaded=${?} - - [ -n "${DEBUG}" -a "${loaded}" = "0" ] && \ - echo "loaded" - [ -n "${DEBUG}" -a "${loaded}" != "0" ] && \ - echo "not loaded" - - [ -z "${DEBUG}" -a "${loaded}" = "0" ] && \ - [ -z "${QUIET}" ] && \ - echo -en "${x} " - else - [ -z "${QUIET}" ] && \ - echo -e "${BOLD} ::${NORMAL} Skipping ${x}..." - fi - done - [ -n "${MODS}" ] && [ -z "${QUIET}" ] && echo + local MODS + local loaded + + MODS=$(cat /etc/modules/${1} 2>/dev/null) + [ -n "${MODS}" ] && [ -z "${QUIET}" ] && \ + echo -ne "${BOLD} ::${NORMAL} Loading from ${1}: " + + for x in ${MODS} + do + MLOAD=$(echo ${MLIST} | sed -e "s/.*${x}.*/${x}/") + if [ "${MLOAD}" = "${x}" ] # Only module to no-load + then + [ -z "${QUIET}" ] && \ + echo -e "${BOLD} ::${NORMAL} Skipping ${x}..." + elif [ "${MLOAD}" = "${MLIST}" ] + then + if [ -n "${DEBUG}" ]; then + echo -ne "${BOLD} ::${NORMAL} " + echo -ne "Scanning for ${x}..." + fi + modprobe ${x} > /dev/null 2>&1 + loaded=${?} + + [ -n "${DEBUG}" -a "${loaded}" = "0" ] && \ + echo "loaded" + [ -n "${DEBUG}" -a "${loaded}" != "0" ] && \ + echo "not loaded" + + [ -z "${DEBUG}" -a "${loaded}" = "0" ] && \ + [ -z "${QUIET}" ] && \ + echo -en "${x} " + else + [ -z "${QUIET}" ] && \ + echo -e "${BOLD} ::${NORMAL} Skipping ${x}..." + fi + done + [ -n "${MODS}" ] && [ -z "${QUIET}" ] && echo } modules_init() { - if [ -z "${DO_modules}" ]; then - good_msg 'Skipping module load; disabled via commandline' - elif [ -d "/lib/modules/${KV}" ]; then - good_msg 'Loading modules' - # Load appropriate kernel modules - if [ "${NODETECT}" != '1' ]; then - for modules in ${MY_HWOPTS} - do - modules_scan ${modules} - done - fi - # Always eval doload=... - modules_load ${MDOLIST} - else - good_msg 'Skipping module load; no modules in the ramdisk!' - fi - - # Give udev time to execute all the rules. This may be beneficial - # for usb-storage devices. - is_udev && udevadm settle + if [ -z "${DO_modules}" ]; then + good_msg 'Skipping module load; disabled via commandline' + elif [ -d "/lib/modules/${KV}" ]; then + good_msg 'Loading modules' + # Load appropriate kernel modules + if [ "${NODETECT}" != '1' ]; then + for modules in ${MY_HWOPTS} + do + modules_scan ${modules} + done + fi + # Always eval doload=... + modules_load ${MDOLIST} + else + good_msg 'Skipping module load; no modules in the ramdisk!' + fi + + # Give udev time to execute all the rules. This may be beneficial + # for usb-storage devices. + is_udev && udevadm settle } uppercase() { - # needs tr on busybox - echo $1 | tr 'a-z' 'A-Z' + # needs tr on busybox + echo $1 | tr 'a-z' 'A-Z' } is_livecd() { - [ "${CDROOT}" = "1" ] && return 0 - return 1 + [ "${CDROOT}" = "1" ] && return 0 + return 1 } is_nfs() { - [ "${REAL_ROOT}" = "/dev/nfs" ] && return 0 - return 1 + [ "${REAL_ROOT}" = "/dev/nfs" ] && return 0 + return 1 } is_aufs() { - [ "${USE_AUFS}" = "1" ] && return 0 - return 1 + [ "${USE_AUFS}" = "1" ] && return 0 + return 1 } setup_real_root() { - if [ -z "${REAL_ROOT}" -a "${FAKE_ROOT}" != "/dev/ram0" ]; then - REAL_ROOT="${FAKE_ROOT}" - fi - if [ -z "${REAL_INIT}" -a "${FAKE_INIT}" != "/linuxrc" ]; then - REAL_INIT="${FAKE_INIT}" - fi - if [ -z "${REAL_ROOTFLAGS}" ]; then - REAL_ROOTFLAGS="${FAKE_ROOTFLAGS}" - fi + if [ -z "${REAL_ROOT}" -a "${FAKE_ROOT}" != "/dev/ram0" ]; then + REAL_ROOT="${FAKE_ROOT}" + fi + if [ -z "${REAL_INIT}" -a "${FAKE_INIT}" != "/linuxrc" ]; then + REAL_INIT="${FAKE_INIT}" + fi + if [ -z "${REAL_ROOTFLAGS}" ]; then + REAL_ROOTFLAGS="${FAKE_ROOTFLAGS}" + fi } findmediamount() { - # $1 = mount dir name / media name - # $2 = recognition file - # $3 = variable to have the device path - # $4 = actual mount dir path (full path) - # args remaining are possible devices - - local media=$1 recon=$2 vrbl=$3 mntdir=$4 - shift 4 - - good_msg "Looking for the ${media}" ${CRYPT_SILENT} - - if [ "$#" -gt "0" ] - then - [ ! -d "${mntdir}" ] && mkdir -p ${mntdir} 2>/dev/null >/dev/null - if [ -n "${ISOBOOT}" ] - then - mntcddir="${mntdir%${media}}iso" - if [ ! -f ${mntcddir} ] - then - mkdir ${mntcddir} - fi - else - mntcddir=${mntdir} - fi - - for x in $* - do - # Check for a block device to mount - if [ -b "${x}" ] - then - skip=0 - bsn=$(basename "${x}") - # - # If disk and it has at least one partition, skip. - # We use /sys/block/${bsn}/${bsn}[0-9]* to make sure that we - # don't skip device mapper devices. Even the craziest scenario - # deserves a fair chance. - # - for part in $(ls /sys/block/${bsn}/${bsn}*[0-9]* 2>/dev/null) - do - skip=1 - break; - done - if [ ${skip} -eq 1 ] - then - continue - fi - good_msg "Attempting to mount media: ${x}" ${CRYPT_SILENT} - - mount -r -t ${CDROOT_TYPE} ${x} ${mntcddir} >/dev/null 2>&1 - if [ "$?" = '0' ] - then - if [ -n "${ISOBOOT}" ]; then - if [ -f ${mntcddir}/${ISOBOOT} ]; then - mount -o loop ${mntcddir}/${ISOBOOT} ${mntdir} - if [ "$?" = "0" ]; then - good_msg "iso mounted on ${mntdir}" - fi - fi - fi - - # Check for the media - if [ -f "${mntdir}/${recon}" ] - then - #set REAL_ROOT, CRYPT_ROOT_KEYDEV or whatever ${vrbl} is - eval ${vrbl}'='"${x}" - good_msg "Media found on ${x}" ${CRYPT_SILENT} - break - else - umount ${mntcddir} - fi - fi - fi - done - fi - - eval local result='$'${vrbl} - - [ -n "${result}" ] || bad_msg "Media not found" ${CRYPT_SILENT} + # $1 = mount dir name / media name + # $2 = recognition file + # $3 = variable to have the device path + # $4 = actual mount dir path (full path) + # args remaining are possible devices + + local media=$1 recon=$2 vrbl=$3 mntdir=$4 + shift 4 + + good_msg "Looking for the ${media}" ${CRYPT_SILENT} + + if [ "$#" -gt "0" ] + then + [ ! -d "${mntdir}" ] && mkdir -p ${mntdir} 2>/dev/null >/dev/null + if [ -n "${ISOBOOT}" ] + then + mntcddir="${mntdir%${media}}iso" + if [ ! -f ${mntcddir} ] + then + mkdir ${mntcddir} + fi + else + mntcddir=${mntdir} + fi + + for x in $* + do + # Check for a block device to mount + if [ -b "${x}" ] + then + skip=0 + bsn=$(basename "${x}") + # + # If disk and it has at least one partition, skip. + # We use /sys/block/${bsn}/${bsn}[0-9]* to make sure that we + # don't skip device mapper devices. Even the craziest scenario + # deserves a fair chance. + # + for part in $(ls /sys/block/${bsn}/${bsn}*[0-9]* 2>/dev/null) + do + skip=1 + break; + done + if [ ${skip} -eq 1 ] + then + continue + fi + good_msg "Attempting to mount media: ${x}" ${CRYPT_SILENT} + + mount -r -t ${CDROOT_TYPE} ${x} ${mntcddir} >/dev/null 2>&1 + if [ "$?" = '0' ] + then + if [ -n "${ISOBOOT}" ]; then + if [ -f ${mntcddir}/${ISOBOOT} ]; then + mount -o loop ${mntcddir}/${ISOBOOT} ${mntdir} + if [ "$?" = "0" ]; then + good_msg "iso mounted on ${mntdir}" + fi + fi + fi + + # Check for the media + if [ -f "${mntdir}/${recon}" ] + then + #set REAL_ROOT, CRYPT_ROOT_KEYDEV or whatever ${vrbl} is + eval ${vrbl}'='"${x}" + good_msg "Media found on ${x}" ${CRYPT_SILENT} + break + else + umount ${mntcddir} + fi + fi + fi + done + fi + + eval local result='$'${vrbl} + + [ -n "${result}" ] || bad_msg "Media not found" ${CRYPT_SILENT} } devicelist() { - # Locate the cdrom device with our media on it. - # CDROM DEVICES - local DEVICES="/dev/cdroms/* /dev/ide/cd/* /dev/sr*" - # USB Keychain/Storage - DEVICES="$DEVICES /dev/sd*" - # IDE devices - DEVICES="$DEVICES /dev/hd*" - # virtio devices - DEVICES="$DEVICES /dev/vd*" - # USB using the USB Block Driver - DEVICES="$DEVICES /dev/ubd* /dev/ubd/*" - # iSeries devices - DEVICES="$DEVICES /dev/iseries/vcd*" - # builtin mmc/sd card reader devices - DEVICES="$DEVICES /dev/mmcblk* /dev/mmcblk*/*" - # fallback scanning, this might scan something twice, but it's better than - # failing to boot. - [ -e /proc/partitions ] && DEVICES="${DEVICES} $(awk '/([0-9]+[[:space:]]+)/{print "/dev/" $4}' /proc/partitions)" - echo ${DEVICES} + # Locate the cdrom device with our media on it. + # CDROM DEVICES + local DEVICES="/dev/cdroms/* /dev/ide/cd/* /dev/sr*" + # USB Keychain/Storage + DEVICES="$DEVICES /dev/sd*" + # IDE devices + DEVICES="$DEVICES /dev/hd*" + # virtio devices + DEVICES="$DEVICES /dev/vd*" + # USB using the USB Block Driver + DEVICES="$DEVICES /dev/ubd* /dev/ubd/*" + # iSeries devices + DEVICES="$DEVICES /dev/iseries/vcd*" + # builtin mmc/sd card reader devices + DEVICES="$DEVICES /dev/mmcblk* /dev/mmcblk*/*" + # fallback scanning, this might scan something twice, but it's better than + # failing to boot. + [ -e /proc/partitions ] && DEVICES="${DEVICES} $(awk '/([0-9]+[[:space:]]+)/{print "/dev/" $4}' /proc/partitions)" + echo ${DEVICES} } bootstrap_cd() { - local DEVICES= + local DEVICES= - # The device was specified on the command line, so there's no need - # to scan a bunch of extra devices - [ -n "${CDROOT_DEV}" ] && DEVICES="${CDROOT_DEV}" - [ -z "${CDROOT_DEV}" ] && DEVICES=$(devicelist) + # The device was specified on the command line, so there's no need + # to scan a bunch of extra devices + [ -n "${CDROOT_DEV}" ] && DEVICES="${CDROOT_DEV}" + [ -z "${CDROOT_DEV}" ] && DEVICES=$(devicelist) - findmediamount "cdrom" "${SUBDIR}/${CDROOT_MARKER}" \ - "REAL_ROOT" "${CDROOT_PATH}" ${DEVICES} + findmediamount "cdrom" "${SUBDIR}/${CDROOT_MARKER}" \ + "REAL_ROOT" "${CDROOT_PATH}" ${DEVICES} } bootstrap_key() { - # $1 = ROOT/SWAP - local KEYDEVS=$(devicelist) - eval local keyloc='"${CRYPT_'${1}'_KEY}"' + # $1 = ROOT/SWAP + local KEYDEVS=$(devicelist) + eval local keyloc='"${CRYPT_'${1}'_KEY}"' - findmediamount "key" "${keyloc}" "CRYPT_${1}_KEYDEV" "/mnt/key" ${KEYDEVS} + findmediamount "key" "${keyloc}" "CRYPT_${1}_KEYDEV" "/mnt/key" ${KEYDEVS} } cache_cd_contents() { - # Check loop file exists and cache to ramdisk if DO_cache is enabled - if [ "${LOOPTYPE}" != "noloop" ] && [ "${LOOPTYPE}" != "sgimips" ] - then - check_loop - if [ "${DO_cache}" ] - then - # TODO: Check the size of the image versus the size of our tmpfs - # along with the amount of available RAM and increase tmpfs size - # if necessary. (Not having awk sucks...) - # z=0 - # for i in $(cat /proc/meminfo | grep -e ^MemFree -e ^Cached | \ - # cut -d: -f2 | cut -dk -f1 | sed -e "s/^\s*//") ; do - # z=$(($z + $i)) ; done - # echo $z - good_msg "Copying loop file for caching..." - # Verify that the needed directory exists - mkdir -p "$(dirname ${NEW_ROOT}/mnt/${LOOP})" - cp -a ${CDROOT_PATH}/${LOOP} ${NEW_ROOT}/mnt/${LOOP} - if [ $? -ne 0 ] - then - warn_msg "Failed to cache the loop file! Lack of RAM?" - rm -rf ${NEW_ROOT}/mnt/${LOOP} 2>/dev/null - rm -rf ${NEW_ROOT}/mnt/livecd.* 2>/dev/null - rm -rf ${NEW_ROOT}/mnt/image.* 2>/dev/null - rm -rf ${NEW_ROOT}/mnt/zisofs 2>/dev/null - fi - fi - fi + # Check loop file exists and cache to ramdisk if DO_cache is enabled + if [ "${LOOPTYPE}" != "noloop" ] && [ "${LOOPTYPE}" != "sgimips" ] + then + check_loop + if [ "${DO_cache}" ] + then + # TODO: Check the size of the image versus the size of our tmpfs + # along with the amount of available RAM and increase tmpfs size + # if necessary. (Not having awk sucks...) + # z=0 + # for i in $(cat /proc/meminfo | grep -e ^MemFree -e ^Cached | \ + # cut -d: -f2 | cut -dk -f1 | sed -e "s/^\s*//") ; do + # z=$(($z + $i)) ; done + # echo $z + good_msg "Copying loop file for caching..." + # Verify that the needed directory exists + mkdir -p "$(dirname ${NEW_ROOT}/mnt/${LOOP})" + cp -a ${CDROOT_PATH}/${LOOP} ${NEW_ROOT}/mnt/${LOOP} + if [ $? -ne 0 ] + then + warn_msg "Failed to cache the loop file! Lack of RAM?" + rm -rf ${NEW_ROOT}/mnt/${LOOP} 2>/dev/null + rm -rf ${NEW_ROOT}/mnt/livecd.* 2>/dev/null + rm -rf ${NEW_ROOT}/mnt/image.* 2>/dev/null + rm -rf ${NEW_ROOT}/mnt/zisofs 2>/dev/null + fi + fi + fi } mount_sysfs() { - mount -t sysfs sysfs /sys -o noexec,nosuid,nodev >/dev/null 2>&1 - ret=$? - [ ${ret} -eq 0 ] || bad_msg "Failed to mount /sys!" + mount -t sysfs sysfs /sys -o noexec,nosuid,nodev >/dev/null 2>&1 + ret=$? + [ ${ret} -eq 0 ] || bad_msg "Failed to mount /sys!" } findnfsmount() { - if [ "${IP}" != '' ] || busybox udhcpc -n -T 15 -q - then - [ -e /rootpath ] && NFSROOT=$(cat /rootpath) - - if [ "${NFSROOT}" = '' ] - then - # Obtain NFSIP - OPTIONS=$(busybox dmesg | grep rootserver | sed -e "s/,/ /g") - for OPTION in $OPTIONS - do - if [ $(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1) = 'rootserver' ] - then - NFSIP=$(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2) - fi - done - # Obtain NFSPATH - OPTIONS=$(busybox dmesg | grep rootpath | sed -e "s/,/ /g") - for OPTION in $OPTIONS - do - if [ $(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1) = 'rootpath' ] - then - NFSPATH=$(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2) - fi - done - - # Setup NFSROOT - if [ "${NFSIP}" != '' ] && [ "$NFSPATH" != '' ] - then - NFSROOT="${NFSIP}:${NFSPATH}" - else - bad_msg "The DHCP Server did not send a valid root-path." - bad_msg "Please check your DHCP setup, or provide a nfsroot=<...> parameter." - fi - fi - - if [ "${NFSROOT}" != '' ] - then - NFSOPTIONS=${NFSROOT#*,} - NFSROOT=${NFSROOT%%,*} - if [ "${NFSOPTIONS}" = "${NFSROOT}" ] - then - NFSOPTIONS=$DEFAULT_NFSOPTIONS - else - NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}" - fi - - if is_livecd - then - good_msg "Attempting to mount NFS CD image on ${NFSROOT} with options ${NFSOPTIONS}" - mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${CDROOT_PATH} - if [ "$?" = '0' ] - then - REAL_ROOT="/dev/nfs" - else - bad_msg "NFS Mounting failed. Is the path corrent ?" - fi - else - good_msg "Attempting to mount NFS root on ${NFSROOT} with options ${NFSOPTIONS}" - mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${NEW_ROOT} - if [ "$?" = '0' ] - then - REAL_ROOT="/dev/nfs" - else - bad_msg "NFS Mounting failed. Is the path correct ?" - fi - # FIXME: Need to start portmap and the other rpc daemons in - # order to remount rw. - fi - - fi - fi + if [ "${IP}" != '' ] || busybox udhcpc -n -T 15 -q + then + [ -e /rootpath ] && NFSROOT=$(cat /rootpath) + + if [ "${NFSROOT}" = '' ] + then + # Obtain NFSIP + OPTIONS=$(busybox dmesg | grep rootserver | sed -e "s/,/ /g") + for OPTION in $OPTIONS + do + if [ $(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1) = 'rootserver' ] + then + NFSIP=$(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2) + fi + done + # Obtain NFSPATH + OPTIONS=$(busybox dmesg | grep rootpath | sed -e "s/,/ /g") + for OPTION in $OPTIONS + do + if [ $(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1) = 'rootpath' ] + then + NFSPATH=$(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2) + fi + done + + # Setup NFSROOT + if [ "${NFSIP}" != '' ] && [ "$NFSPATH" != '' ] + then + NFSROOT="${NFSIP}:${NFSPATH}" + else + bad_msg "The DHCP Server did not send a valid root-path." + bad_msg "Please check your DHCP setup, or provide a nfsroot=<...> parameter." + fi + fi + + if [ "${NFSROOT}" != '' ] + then + NFSOPTIONS=${NFSROOT#*,} + NFSROOT=${NFSROOT%%,*} + if [ "${NFSOPTIONS}" = "${NFSROOT}" ] + then + NFSOPTIONS=$DEFAULT_NFSOPTIONS + else + NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}" + fi + + if is_livecd + then + good_msg "Attempting to mount NFS CD image on ${NFSROOT} with options ${NFSOPTIONS}" + mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${CDROOT_PATH} + if [ "$?" = '0' ] + then + REAL_ROOT="/dev/nfs" + else + bad_msg "NFS Mounting failed. Is the path corrent ?" + fi + else + good_msg "Attempting to mount NFS root on ${NFSROOT} with options ${NFSOPTIONS}" + mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${NEW_ROOT} + if [ "$?" = '0' ] + then + REAL_ROOT="/dev/nfs" + else + bad_msg "NFS Mounting failed. Is the path correct ?" + fi + # FIXME: Need to start portmap and the other rpc daemons in + # order to remount rw. + fi + + fi + fi } find_real_device() { - local device="${1}" - local out= - case "${device}" in - UUID=*|LABEL=*) - local REAL_DEVICE="" - local retval=1 - - if [ "${retval}" -ne 0 ]; then - REAL_DEVICE=$(findfs "${device}" 2>/dev/null) - retval=$? - fi - - if [ "$retval" -ne 0 ]; then - REAL_DEVICE=$(busybox findfs "${device}" 2>/dev/null) - retval=$? - fi - - if [ "${retval}" -ne 0 ]; then - REAL_DEVICE=$(blkid -o device -l -t "${device}") - retval=$? - fi - - if [ "${retval}" -eq 0 ] && [ -n "${REAL_DEVICE}" ]; then - out="${REAL_DEVICE}" - fi - ;; - *) - out="${device}" - ;; - esac - echo -n "${out}" + local device="${1}" + local out= + case "${device}" in + UUID=*|LABEL=*) + local REAL_DEVICE="" + local retval=1 + + if [ "${retval}" -ne 0 ]; then + REAL_DEVICE=$(findfs "${device}" 2>/dev/null) + retval=$? + fi + + if [ "$retval" -ne 0 ]; then + REAL_DEVICE=$(busybox findfs "${device}" 2>/dev/null) + retval=$? + fi + + if [ "${retval}" -ne 0 ]; then + REAL_DEVICE=$(blkid -o device -l -t "${device}") + retval=$? + fi + + if [ "${retval}" -eq 0 ] && [ -n "${REAL_DEVICE}" ]; then + out="${REAL_DEVICE}" + fi + ;; + *) + out="${device}" + ;; + esac + echo -n "${out}" } get_device_fstype() { - local device=$(find_real_device "${1}") - if [ -n "${device}" ]; then - blkid -o value -s TYPE "${device}" - return ${?} # readability - else - echo "Cannot resolve device: ${1}" >&2 - return 1 - fi + local device=$(find_real_device "${1}") + if [ -n "${device}" ]; then + blkid -o value -s TYPE "${device}" + return ${?} # readability + else + echo "Cannot resolve device: ${1}" >&2 + return 1 + fi } check_loop() { - if [ "${LOOP}" = '' -o ! -e "${CDROOT_PATH}/${LOOP}" ] - then - bad_msg "Invalid loop location: ${LOOP}" - bad_msg 'Please export LOOP with a valid location, or reboot and pass a proper loop=...' - bad_msg 'kernel command line!' - run_shell - fi + if [ "${LOOP}" = '' -o ! -e "${CDROOT_PATH}/${LOOP}" ] + then + bad_msg "Invalid loop location: ${LOOP}" + bad_msg 'Please export LOOP with a valid location, or reboot and pass a proper loop=...' + bad_msg 'kernel command line!' + run_shell + fi } run_shell() { - /bin/ash + /bin/ash } fs_type_in_use() { - fs_type=$1 - cut -d ' ' -f 3 < /proc/mounts | fgrep -q "${fs_type}" + fs_type=$1 + cut -d ' ' -f 3 < /proc/mounts | fgrep -q "${fs_type}" } is_udev() { - [ -x "${UDEVD}" ] && [ -z "${USE_MDEV}" ] && return 0 - return 1 + [ -x "${UDEVD}" ] && [ -z "${USE_MDEV}" ] && return 0 + return 1 } is_mdev() { - if [ ! -x "${UDEVD}" ] || [ -n "${USE_MDEV}" ] - then - return 0 - fi - return 1 + if [ ! -x "${UDEVD}" ] || [ -n "${USE_MDEV}" ] + then + return 0 + fi + return 1 } devmgr_init() { - if is_udev; then - good_msg 'Activating udev' - echo "${UDEVD}" > /proc/sys/kernel/hotplug - echo "" > /sys/kernel/uevent_helper - "${UDEVD}" --daemon --resolve-names=never && \ - udevadm trigger --action=add && \ - udevadm settle || bad_msg "udevd failed to run" - elif is_mdev; then - good_msg 'Activating mdev' - # Serialize hotplug events - touch /dev/mdev.seq - echo "${MDEVD}" > /proc/sys/kernel/hotplug - # Ensure that device nodes are properly configured - "${MDEVD}" -s || bad_msg "mdev -s failed" - else - bad_msg "Cannot find either udev or mdev" - fi + if is_udev; then + good_msg 'Activating udev' + echo "${UDEVD}" > /proc/sys/kernel/hotplug + echo "" > /sys/kernel/uevent_helper + "${UDEVD}" --daemon --resolve-names=never && \ + udevadm trigger --action=add && \ + udevadm settle || bad_msg "udevd failed to run" + elif is_mdev; then + good_msg 'Activating mdev' + # Serialize hotplug events + touch /dev/mdev.seq + echo "${MDEVD}" > /proc/sys/kernel/hotplug + # Ensure that device nodes are properly configured + "${MDEVD}" -s || bad_msg "mdev -s failed" + else + bad_msg "Cannot find either udev or mdev" + fi } # Terminate the device manager, this happens right before pivot_root devmgr_terminate() { - if is_udev; then - udevadm settle - udevadm control --exit || bad_msg "Unable to terminate udevd" - fi - # mdev doesn't require anything, it seems + if is_udev; then + udevadm settle + udevadm control --exit || bad_msg "Unable to terminate udevd" + fi + # mdev doesn't require anything, it seems } mount_devfs () { - # Use devtmpfs if enabled in kernel, - # else tmpfs. Always run mdev just in case - devfs=tmpfs - if grep -qs devtmpfs /proc/filesystems ; then - devfs=devtmpfs - fi - - # Options copied from /etc/init.d/udev-mount, should probably be kept in sync - if ! fs_type_in_use devtmpfs; then - mount -t $devfs -o "exec,nosuid,mode=0755,size=10M" udev /dev \ - || bad_msg "Failed to mount /dev as ${devfs}" - fi - - # http://git.busybox.net/busybox/plain/docs/mdev.txt - if ! fs_type_in_use devpts; then - mkdir -m 0755 /dev/pts - mount -t devpts -o gid=5,mode=0620 devpts /dev/pts || bad_msg "Failed to mount /dev/pts" - fi + # Use devtmpfs if enabled in kernel, + # else tmpfs. Always run mdev just in case + devfs=tmpfs + if grep -qs devtmpfs /proc/filesystems ; then + devfs=devtmpfs + fi + + # Options copied from /etc/init.d/udev-mount, should probably be kept in sync + if ! fs_type_in_use devtmpfs; then + mount -t $devfs -o "exec,nosuid,mode=0755,size=10M" udev /dev \ + || bad_msg "Failed to mount /dev as ${devfs}" + fi + + # http://git.busybox.net/busybox/plain/docs/mdev.txt + if ! fs_type_in_use devpts; then + mkdir -m 0755 /dev/pts + mount -t devpts -o gid=5,mode=0620 devpts /dev/pts || bad_msg "Failed to mount /dev/pts" + fi } test_success() { - retcode=$? - # If last command failed send error message and fall back to a shell - if [ "$retcode" != '0' ] - then - error_string=$1 - error_string="${error_string:-run command}" - bad_msg 'Failed to $1; failing back to the shell...' - run_shell - fi + retcode=$? + # If last command failed send error message and fall back to a shell + if [ "$retcode" != '0' ] + then + error_string=$1 + error_string="${error_string:-run command}" + bad_msg 'Failed to $1; failing back to the shell...' + run_shell + fi } @@ -616,27 +616,27 @@ test_success() { # $2 hide flag good_msg() { - [ -n "${QUIET}" ] && [ -z "${DEBUG}" ] && return 0 + [ -n "${QUIET}" ] && [ -z "${DEBUG}" ] && return 0 - msg_string=$1 - msg_string="${msg_string:-...}" - [ "$2" != 1 ] && echo -e "${GOOD}>>${NORMAL}${BOLD} ${msg_string} ${NORMAL}" + msg_string=$1 + msg_string="${msg_string:-...}" + [ "$2" != 1 ] && echo -e "${GOOD}>>${NORMAL}${BOLD} ${msg_string} ${NORMAL}" } bad_msg() { - msg_string=$1 - msg_string="${msg_string:-...}" - if [ "$2" != 1 ] - then - splashcmd verbose - echo -e "${BAD}!!${NORMAL}${BOLD} ${msg_string} ${NORMAL}" - fi + msg_string=$1 + msg_string="${msg_string:-...}" + if [ "$2" != 1 ] + then + splashcmd verbose + echo -e "${BAD}!!${NORMAL}${BOLD} ${msg_string} ${NORMAL}" + fi } warn_msg() { - msg_string=$1 - msg_string="${msg_string:-...}" - [ "$2" != 1 ] && echo -e "${WARN}**${NORMAL}${BOLD} ${msg_string} ${NORMAL}" + msg_string=$1 + msg_string="${msg_string:-...}" + [ "$2" != 1 ] && echo -e "${WARN}**${NORMAL}${BOLD} ${msg_string} ${NORMAL}" } # Courtesy of dracut. Licensed under GPL-2. @@ -661,272 +661,272 @@ warn_msg() { # Turn off input echo before tty command is executed and turn on after. # It's useful when password is read from stdin. ask_for_password() { - local cmd; local prompt; local tries=3 - local ply_cmd; local ply_prompt; local ply_tries=3 - local tty_cmd; local tty_prompt; local tty_tries=3 - local ret - - while [ $# -gt 0 ]; do - case "$1" in - --cmd) ply_cmd="$2"; tty_cmd="$2" shift;; - --ply-cmd) ply_cmd="$2"; shift;; - --tty-cmd) tty_cmd="$2"; shift;; - --prompt) ply_prompt="$2"; tty_prompt="$2" shift;; - --ply-prompt) ply_prompt="$2"; shift;; - --tty-prompt) tty_prompt="$2"; shift;; - --tries) ply_tries="$2"; tty_tries="$2"; shift;; - --ply-tries) ply_tries="$2"; shift;; - --tty-tries) tty_tries="$2"; shift;; - --tty-echo-off) tty_echo_off=yes;; - esac - shift - done - - { flock -s 9; - # Prompt for password with plymouth, if installed and running. - if is_plymouth_started - then - "${PLYMOUTH_BIN}" ask-for-password \ - --prompt="$ply_prompt" \ - --number-of-tries=$ply_tries \ - --command="$ply_cmd" - ret=$? - else - splashcmd verbose - if [ "$tty_echo_off" = yes ]; then - stty_orig="$(stty -g)" - stty -echo - fi - - local i=1 - while [ $i -le $tty_tries ]; do - [ -n "$tty_prompt" ] && \ - printf "$tty_prompt [$i/$tty_tries]:" >&2 - eval "$tty_cmd" && ret=0 && break - ret=$? - i=$(($i+1)) - [ -n "$tty_prompt" ] && printf '\n' >&2 - done - - [ "$tty_echo_off" = yes ] && stty $stty_orig - - # no need for: splashcmd quiet - # since fbsplash does not support it - if [ $ret -ne 0 ] && is_fbsplash - then - splashcmd set_msg 'Disk unlocked.' - fi - fi - } 9>/.console_lock - - [ $ret -ne 0 ] && bad_msg "Wrong password" - return $ret + local cmd; local prompt; local tries=3 + local ply_cmd; local ply_prompt; local ply_tries=3 + local tty_cmd; local tty_prompt; local tty_tries=3 + local ret + + while [ $# -gt 0 ]; do + case "$1" in + --cmd) ply_cmd="$2"; tty_cmd="$2" shift;; + --ply-cmd) ply_cmd="$2"; shift;; + --tty-cmd) tty_cmd="$2"; shift;; + --prompt) ply_prompt="$2"; tty_prompt="$2" shift;; + --ply-prompt) ply_prompt="$2"; shift;; + --tty-prompt) tty_prompt="$2"; shift;; + --tries) ply_tries="$2"; tty_tries="$2"; shift;; + --ply-tries) ply_tries="$2"; shift;; + --tty-tries) tty_tries="$2"; shift;; + --tty-echo-off) tty_echo_off=yes;; + esac + shift + done + + { flock -s 9; + # Prompt for password with plymouth, if installed and running. + if is_plymouth_started + then + "${PLYMOUTH_BIN}" ask-for-password \ + --prompt="$ply_prompt" \ + --number-of-tries=$ply_tries \ + --command="$ply_cmd" + ret=$? + else + splashcmd verbose + if [ "$tty_echo_off" = yes ]; then + stty_orig="$(stty -g)" + stty -echo + fi + + local i=1 + while [ $i -le $tty_tries ]; do + [ -n "$tty_prompt" ] && \ + printf "$tty_prompt [$i/$tty_tries]:" >&2 + eval "$tty_cmd" && ret=0 && break + ret=$? + i=$(($i+1)) + [ -n "$tty_prompt" ] && printf '\n' >&2 + done + + [ "$tty_echo_off" = yes ] && stty $stty_orig + + # no need for: splashcmd quiet + # since fbsplash does not support it + if [ $ret -ne 0 ] && is_fbsplash + then + splashcmd set_msg 'Disk unlocked.' + fi + fi + } 9>/.console_lock + + [ $ret -ne 0 ] && bad_msg "Wrong password" + return $ret } crypt_exec() { - if [ "${CRYPT_SILENT}" = '1' ] - then - eval ${1} >/dev/null 2>/dev/null - else - ask_for_password --ply-tries 5 \ - --ply-cmd "${1}" \ - --ply-prompt "Encryption password (${LUKS_DEVICE}): " \ - --tty-tries 5 \ - --tty-cmd "${1}" || return 1 - return 0 - fi + if [ "${CRYPT_SILENT}" = '1' ] + then + eval ${1} >/dev/null 2>/dev/null + else + ask_for_password --ply-tries 5 \ + --ply-cmd "${1}" \ + --ply-prompt "Encryption password (${LUKS_DEVICE}): " \ + --tty-tries 5 \ + --tty-cmd "${1}" || return 1 + return 0 + fi } prompt_user() { - # $1 = variable whose value is the path (examples: "REAL_ROOT", - # "LUKS_KEYDEV") - # $2 = label - # $3 = optional explanations for failure - - eval local oldvalue='$'${1} - - [ $# != 2 -a $# != 3 ] && \ - bad_msg "Bad invocation of function prompt_user." - bad_msg "Please file a bug report with this message" && exit 1 - [ -n "${3}" ] && local explnt=" or : ${3}" || local explnt="." - - splashcmd verbose - bad_msg "Could not find the ${2} in ${oldvalue}${explnt}" - bad_msg "Please specify another value or:" - bad_msg "- press Enter for the same" - bad_msg '- type "shell" for a shell' - bad_msg '- type "q" to skip...' - echo -n "${2}(${oldvalue}) :: " - read ${1} - case $(eval echo '$'${1}) in - 'q') - eval ${1}'='${oldvalue} - warn_msg "Skipping step, this will likely cause a boot failure." - break - ;; - 'shell') - eval ${1}'='${oldvalue} - warn_msg "To leave and try again just press +D" - run_shell - ;; - '') - eval ${1}'='${oldvalue} - ;; - esac - splashcmd quiet + # $1 = variable whose value is the path (examples: "REAL_ROOT", + # "LUKS_KEYDEV") + # $2 = label + # $3 = optional explanations for failure + + eval local oldvalue='$'${1} + + [ $# != 2 -a $# != 3 ] && \ + bad_msg "Bad invocation of function prompt_user." + bad_msg "Please file a bug report with this message" && exit 1 + [ -n "${3}" ] && local explnt=" or : ${3}" || local explnt="." + + splashcmd verbose + bad_msg "Could not find the ${2} in ${oldvalue}${explnt}" + bad_msg "Please specify another value or:" + bad_msg "- press Enter for the same" + bad_msg '- type "shell" for a shell' + bad_msg '- type "q" to skip...' + echo -n "${2}(${oldvalue}) :: " + read ${1} + case $(eval echo '$'${1}) in + 'q') + eval ${1}'='${oldvalue} + warn_msg "Skipping step, this will likely cause a boot failure." + break + ;; + 'shell') + eval ${1}'='${oldvalue} + warn_msg "To leave and try again just press +D" + run_shell + ;; + '') + eval ${1}'='${oldvalue} + ;; + esac + splashcmd quiet } cmdline_hwopts() { - # Scan CMDLINE for any "doscsi" or "noscsi"-type arguments - local FOUND - local TMP_HWOPTS - - for x in $HWOPTS - do - for y in $CMDLINE - do - if [ "${y}" = "do${x}" ] - then - MY_HWOPTS="${MY_HWOPTS} $x" - elif [ "${y}" = "no${x}" ] - then - MY_HWOPTS="$(echo ${MY_HWOPTS} | sed -e \"s/${x}//g\" -)" - fi - if [ "$(echo ${y} | cut -b -7)" = "keymap=" ] - then - MY_HWOPTS="${MY_HWOPTS} keymap" - fi - done - done - - # Shouldnt need to sort this as the following loop should figure out the - # duplicates and strip them out - #MY_HWOPTS=$(echo ${MY_HWOPTS}| sort) - for x in ${MY_HWOPTS} - do - FOUND=0 - for y in ${TMP_HWOPTS} - do - if [ "${y}" = "${x}" ] - then - continue 2 - fi - done - TMP_HWOPTS="${TMP_HWOPTS} ${x}" - eval DO_$(echo ${x} | sed 's/-//')=1 - done - - MY_HWOPTS=${TMP_HWOPTS} + # Scan CMDLINE for any "doscsi" or "noscsi"-type arguments + local FOUND + local TMP_HWOPTS + + for x in $HWOPTS + do + for y in $CMDLINE + do + if [ "${y}" = "do${x}" ] + then + MY_HWOPTS="${MY_HWOPTS} $x" + elif [ "${y}" = "no${x}" ] + then + MY_HWOPTS="$(echo ${MY_HWOPTS} | sed -e \"s/${x}//g\" -)" + fi + if [ "$(echo ${y} | cut -b -7)" = "keymap=" ] + then + MY_HWOPTS="${MY_HWOPTS} keymap" + fi + done + done + + # Shouldnt need to sort this as the following loop should figure out the + # duplicates and strip them out + #MY_HWOPTS=$(echo ${MY_HWOPTS}| sort) + for x in ${MY_HWOPTS} + do + FOUND=0 + for y in ${TMP_HWOPTS} + do + if [ "${y}" = "${x}" ] + then + continue 2 + fi + done + TMP_HWOPTS="${TMP_HWOPTS} ${x}" + eval DO_$(echo ${x} | sed 's/-//')=1 + done + + MY_HWOPTS=${TMP_HWOPTS} } load_modules() { - # Load modules listed in MY_HWOPTS if /lib/modules exists for the running - # kernel version - if [ -d "/lib/modules/${KV}" ] - then - good_msg 'Loading modules' - # Load appropriate kernel modules - for modules in $MY_HWOPTS - do - modules_scan $modules - done - else - good_msg 'Skipping module load; no modules in the ramdisk!' - fi + # Load modules listed in MY_HWOPTS if /lib/modules exists for the running + # kernel version + if [ -d "/lib/modules/${KV}" ] + then + good_msg 'Loading modules' + # Load appropriate kernel modules + for modules in $MY_HWOPTS + do + modules_scan $modules + done + else + good_msg 'Skipping module load; no modules in the ramdisk!' + fi } setup_keymap() { - if [ "${DO_keymap}" ] - then - if [ ! -e /dev/vc/0 -a ! -e /dev/tty0 ] - then - DEVBIND=1 - mount -o bind ${NEW_ROOT}/dev /dev - fi - [ ! -e /dev/tty0 ] && ln -s /dev/tty1 /dev/tty0 + if [ "${DO_keymap}" ] + then + if [ ! -e /dev/vc/0 -a ! -e /dev/tty0 ] + then + DEVBIND=1 + mount -o bind ${NEW_ROOT}/dev /dev + fi + [ ! -e /dev/tty0 ] && ln -s /dev/tty1 /dev/tty0 - [ -f /lib/keymaps/keymapList ] && choose_keymap + [ -f /lib/keymaps/keymapList ] && choose_keymap - [ "${DEVBIND}" = '1' ] && umount /dev + [ "${DEVBIND}" = '1' ] && umount /dev - if [ -e /etc/sysconfig/keyboard ] && is_livecd - then - mkdir -p ${NEW_ROOT}/etc/sysconfig/ - cp /etc/sysconfig/keyboard ${NEW_ROOT}/etc/sysconfig/keyboard - fi - fi + if [ -e /etc/sysconfig/keyboard ] && is_livecd + then + mkdir -p ${NEW_ROOT}/etc/sysconfig/ + cp /etc/sysconfig/keyboard ${NEW_ROOT}/etc/sysconfig/keyboard + fi + fi } choose_keymap() { - good_msg "Loading keymaps" - if [ -z "${keymap}" ] - then - splashcmd verbose - cat /lib/keymaps/keymapList - read -t 10 -p '<< Load keymap (Enter for default): ' keymap - case ${keymap} in - 1|azerty) keymap=azerty ;; - 2|be) keymap=be ;; - 3|bg) keymap=bg ;; - 4|br-a) keymap=br-a ;; - 5|br-l) keymap=br-l ;; - 6|by) keymap=by ;; - 7|cf) keymap=cf ;; - 8|croat) keymap=croat ;; - 9|cz) keymap=cz ;; - 10|de) keymap=de ;; - 11|dk) keymap=dk ;; - 12|dvorak) keymap=dvorak ;; - 13|es) keymap=es ;; - 14|et) keymap=et ;; - 15|fi) keymap=fi ;; - 16|fr) keymap=fr ;; - 17|gr) keymap=gr ;; - 18|hu) keymap=hu ;; - 19|il) keymap=il ;; - 20|is) keymap=is ;; - 21|it) keymap=it ;; - 22|jp) keymap=jp ;; - 23|la) keymap=la ;; - 24|lt) keymap=lt ;; - 25|mk) keymap=mk ;; - 26|nl) keymap=nl ;; - 27|no) keymap=no ;; - 28|pl) keymap=pl ;; - 29|pt) keymap=pt ;; - 30|ro) keymap=ro ;; - 31|ru) keymap=ru ;; - 32|se) keymap=se ;; - 33|sg) keymap=sg ;; - 34|sk-y) keymap=sk-y ;; - 35|sk-z) keymap=sk-z ;; - 36|slovene) keymap=slovene ;; - 37|trf) keymap=trf ;; - 38|trq) keymap=trq ;; - 39|ua) keymap=ua ;; - 40|uk) keymap=uk ;; - 41|us) keymap=us ;; - 42|wangbe) keymap=wangbe ;; - 43|sf|ch*) keymap=sf ;; - esac - fi - if [ -e /lib/keymaps/${keymap}.map ] - then - good_msg "Loading the ''${keymap}'' keymap" - loadkmap < /lib/keymaps/${keymap}.map - mkdir -p /etc/sysconfig - echo "XKEYBOARD=${keymap}" > /etc/sysconfig/keyboard - splashcmd set_msg "Set keymap to ${keymap}" - elif [ -z "${keymap}" ] - then - good_msg - good_msg "Keeping default keymap" - splashcmd set_msg "Keeping default keymap" - else - bad_msg "Sorry, but keymap ''${keymap}'' is invalid!" - unset keymap - choose_keymap - fi + good_msg "Loading keymaps" + if [ -z "${keymap}" ] + then + splashcmd verbose + cat /lib/keymaps/keymapList + read -t 10 -p '<< Load keymap (Enter for default): ' keymap + case ${keymap} in + 1|azerty) keymap=azerty ;; + 2|be) keymap=be ;; + 3|bg) keymap=bg ;; + 4|br-a) keymap=br-a ;; + 5|br-l) keymap=br-l ;; + 6|by) keymap=by ;; + 7|cf) keymap=cf ;; + 8|croat) keymap=croat ;; + 9|cz) keymap=cz ;; + 10|de) keymap=de ;; + 11|dk) keymap=dk ;; + 12|dvorak) keymap=dvorak ;; + 13|es) keymap=es ;; + 14|et) keymap=et ;; + 15|fi) keymap=fi ;; + 16|fr) keymap=fr ;; + 17|gr) keymap=gr ;; + 18|hu) keymap=hu ;; + 19|il) keymap=il ;; + 20|is) keymap=is ;; + 21|it) keymap=it ;; + 22|jp) keymap=jp ;; + 23|la) keymap=la ;; + 24|lt) keymap=lt ;; + 25|mk) keymap=mk ;; + 26|nl) keymap=nl ;; + 27|no) keymap=no ;; + 28|pl) keymap=pl ;; + 29|pt) keymap=pt ;; + 30|ro) keymap=ro ;; + 31|ru) keymap=ru ;; + 32|se) keymap=se ;; + 33|sg) keymap=sg ;; + 34|sk-y) keymap=sk-y ;; + 35|sk-z) keymap=sk-z ;; + 36|slovene) keymap=slovene ;; + 37|trf) keymap=trf ;; + 38|trq) keymap=trq ;; + 39|ua) keymap=ua ;; + 40|uk) keymap=uk ;; + 41|us) keymap=us ;; + 42|wangbe) keymap=wangbe ;; + 43|sf|ch*) keymap=sf ;; + esac + fi + if [ -e /lib/keymaps/${keymap}.map ] + then + good_msg "Loading the ''${keymap}'' keymap" + loadkmap < /lib/keymaps/${keymap}.map + mkdir -p /etc/sysconfig + echo "XKEYBOARD=${keymap}" > /etc/sysconfig/keyboard + splashcmd set_msg "Set keymap to ${keymap}" + elif [ -z "${keymap}" ] + then + good_msg + good_msg "Keeping default keymap" + splashcmd set_msg "Keeping default keymap" + else + bad_msg "Sorry, but keymap ''${keymap}'' is invalid!" + unset keymap + choose_keymap + fi } # This helper function is to be called using call_func_timeout. @@ -934,686 +934,686 @@ choose_keymap() { # dependencies. This also enables us to wait a reasonable amount of time until # /dev/zfs appears. wait_for_zfs() { - while [ ! -c /dev/zfs ]; do modprobe zfs 2> /dev/null; done; + while [ ! -c /dev/zfs ]; do modprobe zfs 2> /dev/null; done; } zfs_init() { - # Set variables based on the value of REAL_ROOT - case "${REAL_ROOT}" in - ZFS=*) - ZFS_POOL=${REAL_ROOT#*=} - ZFS_POOL=${ZFS_POOL%%/*} - USE_ZFS=1 - ;; - ZFS) - USE_ZFS=1 - ;; - esac - - # Verify that it is safe to use ZFS - if [ "USE_ZFS" = "1" ] - then - for i in /sbin/zfs /sbin/zpool - do - if [ ! -x ${i} ] - then - USE_ZFS=0 - bad_msg 'Aborting use of zfs because ${i} not found!' - break - fi - done - fi + # Set variables based on the value of REAL_ROOT + case "${REAL_ROOT}" in + ZFS=*) + ZFS_POOL=${REAL_ROOT#*=} + ZFS_POOL=${ZFS_POOL%%/*} + USE_ZFS=1 + ;; + ZFS) + USE_ZFS=1 + ;; + esac + + # Verify that it is safe to use ZFS + if [ "USE_ZFS" = "1" ] + then + for i in /sbin/zfs /sbin/zpool + do + if [ ! -x ${i} ] + then + USE_ZFS=0 + bad_msg 'Aborting use of zfs because ${i} not found!' + break + fi + done + fi } start_volumes() { - #good_msg 'Checking if volumes need to be started...' - - # Here, we check for /dev/device-mapper, and if it exists, we setup a - # a symlink, which should hopefully fix bug #142775 and bug #147015 - if [ -e /dev/device-mapper ] && [ ! -e /dev/mapper/control ] - then - mkdir -p /dev/mapper - ln -sf /dev/device-mapper /dev/mapper/control - fi - - if [ "${USE_MDADM}" = '1' ] - then - if [ -e '/sbin/mdadm' ] - then - /sbin/mdadm --assemble --scan - else - bad_msg "mdadm not found: skipping mdadm raid assembly!" - fi - fi - - if [ "${USE_MULTIPATH_NORMAL}" = '1' ] - then - good_msg "Scanning for multipath devices" - /sbin/multipath -v 0 - sleep 2 - good_msg "Activating multipath devices" - /sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -v" - #for MULTIPATH_VOLUMES in /dev/mapper/*; do kpartx -a $MULTIPATH_VOLUMES; done - fi - - if [ "${USE_DMRAID_NORMAL}" = '1' ] - then - if [ -e '/sbin/dmraid' ] - then - good_msg "Activating Device-Mapper RAID(s)" - if [ '${DMRAID_OPTS}' = '' ] - then - /sbin/dmraid -ay - else - /sbin/dmraid -ay ${DMRAID_OPTS} - fi - fi - fi - - if [ "${USE_LVM_NORMAL}" = '1' ] - then - if [ -e '/sbin/lvm' ] - then - - if is_mdev - then - for dev in ${RAID_DEVICES} - do - setup_md_device "${dev}" - done - fi - - # This is needed for /sbin/lvm to accept the following logic - lvm_commands="#! /sbin/lvm" - - # If there is a cahe, update it. Unbreak at least dmcrypt - [ -d /etc/lvm/cache ] && lvm_commands="${lvm_commands} \nvgscan" - - # To activate volumegroups on all devices in the cache - lvm_commands="${lvm_commands} \nvgchange -ay --sysinit" - if is_mdev - then - # To create symlinks so users can use - # real_root=/dev/vg/root - # This needs to run after vgchange, using - # vgchange --mknodes is too early. - lvm_commands="${lvm_commands} \nvgmknodes --ignorelockingfailure" - fi - - # And finally execute it all (/proc/... needed if lvm is compiled without readline) - good_msg "Scanning for and activating Volume Groups" - printf "%b\n" "${lvm_commands}" | /sbin/lvm /proc/self/fd/0 - else - bad_msg "vgscan or vgchange not found: skipping LVM volume group activation!" - fi - fi - - if [ "${USE_ZFS}" = '1' ] - then - - # Avoid race involving asynchronous module loading - if call_func_timeout wait_for_zfs 5 - then - bad_msg "Cannot import ZFS pool because /dev/zfs is missing" - elif [ -z "${ZFS_POOL}" ] - then - good_msg "Importing ZFS pools" - - /sbin/zpool import -N -a ${ZPOOL_FORCE} - - if [ "$?" = '0' ] - then - good_msg "Importing ZFS pools succeeded" - else - bad_msg "Imported ZFS pools failed" - fi - else - - if [ "$(zpool list -H -o name ${ZFS_POOL} 2>&1)" = "$ZFS_POOL" ] - then - good_msg "ZFS pool ${ZFS_POOL} already imported." - - if [ -n "${CRYPT_ROOT}" -o -n "${CRYPT_SWAP}" ] - then - good_msg "LUKS detected. Reimporting ${ZFS_POOL}" - /sbin/zpool export -f "${ZFS_POOL}" - /sbin/zpool import -N ${ZPOOL_FORCE} "${ZFS_POOL}" - fi - else - good_msg "Importing ZFS pool ${ZFS_POOL}" - - /sbin/zpool import -N ${ZPOOL_FORCE} "${ZFS_POOL}" - - if [ "$?" = '0' ] - then - good_msg "Import of ${ZFS_POOL} succeeded" - else - bad_msg "Import of ${ZFS_POOL} failed" - fi - fi - fi - fi - - is_udev && udevadm settle + #good_msg 'Checking if volumes need to be started...' + + # Here, we check for /dev/device-mapper, and if it exists, we setup a + # a symlink, which should hopefully fix bug #142775 and bug #147015 + if [ -e /dev/device-mapper ] && [ ! -e /dev/mapper/control ] + then + mkdir -p /dev/mapper + ln -sf /dev/device-mapper /dev/mapper/control + fi + + if [ "${USE_MDADM}" = '1' ] + then + if [ -e '/sbin/mdadm' ] + then + /sbin/mdadm --assemble --scan + else + bad_msg "mdadm not found: skipping mdadm raid assembly!" + fi + fi + + if [ "${USE_MULTIPATH_NORMAL}" = '1' ] + then + good_msg "Scanning for multipath devices" + /sbin/multipath -v 0 + sleep 2 + good_msg "Activating multipath devices" + /sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -v" + #for MULTIPATH_VOLUMES in /dev/mapper/*; do kpartx -a $MULTIPATH_VOLUMES; done + fi + + if [ "${USE_DMRAID_NORMAL}" = '1' ] + then + if [ -e '/sbin/dmraid' ] + then + good_msg "Activating Device-Mapper RAID(s)" + if [ '${DMRAID_OPTS}' = '' ] + then + /sbin/dmraid -ay + else + /sbin/dmraid -ay ${DMRAID_OPTS} + fi + fi + fi + + if [ "${USE_LVM_NORMAL}" = '1' ] + then + if [ -e '/sbin/lvm' ] + then + + if is_mdev + then + for dev in ${RAID_DEVICES} + do + setup_md_device "${dev}" + done + fi + + # This is needed for /sbin/lvm to accept the following logic + lvm_commands="#! /sbin/lvm" + + # If there is a cahe, update it. Unbreak at least dmcrypt + [ -d /etc/lvm/cache ] && lvm_commands="${lvm_commands} \nvgscan" + + # To activate volumegroups on all devices in the cache + lvm_commands="${lvm_commands} \nvgchange -ay --sysinit" + if is_mdev + then + # To create symlinks so users can use + # real_root=/dev/vg/root + # This needs to run after vgchange, using + # vgchange --mknodes is too early. + lvm_commands="${lvm_commands} \nvgmknodes --ignorelockingfailure" + fi + + # And finally execute it all (/proc/... needed if lvm is compiled without readline) + good_msg "Scanning for and activating Volume Groups" + printf "%b\n" "${lvm_commands}" | /sbin/lvm /proc/self/fd/0 + else + bad_msg "vgscan or vgchange not found: skipping LVM volume group activation!" + fi + fi + + if [ "${USE_ZFS}" = '1' ] + then + + # Avoid race involving asynchronous module loading + if call_func_timeout wait_for_zfs 5 + then + bad_msg "Cannot import ZFS pool because /dev/zfs is missing" + elif [ -z "${ZFS_POOL}" ] + then + good_msg "Importing ZFS pools" + + /sbin/zpool import -N -a ${ZPOOL_FORCE} + + if [ "$?" = '0' ] + then + good_msg "Importing ZFS pools succeeded" + else + bad_msg "Imported ZFS pools failed" + fi + else + + if [ "$(zpool list -H -o name ${ZFS_POOL} 2>&1)" = "$ZFS_POOL" ] + then + good_msg "ZFS pool ${ZFS_POOL} already imported." + + if [ -n "${CRYPT_ROOT}" -o -n "${CRYPT_SWAP}" ] + then + good_msg "LUKS detected. Reimporting ${ZFS_POOL}" + /sbin/zpool export -f "${ZFS_POOL}" + /sbin/zpool import -N ${ZPOOL_FORCE} "${ZFS_POOL}" + fi + else + good_msg "Importing ZFS pool ${ZFS_POOL}" + + /sbin/zpool import -N ${ZPOOL_FORCE} "${ZFS_POOL}" + + if [ "$?" = '0' ] + then + good_msg "Import of ${ZFS_POOL} succeeded" + else + bad_msg "Import of ${ZFS_POOL} failed" + fi + fi + fi + fi + + is_udev && udevadm settle } start_iscsi() { - if [ ! -e /usr/sbin/iscsistart ]; then - return 0 # disabled - fi - - if [ ! -n "${ISCSI_NOIBFT}" ] - then - good_msg "Activating iSCSI via iBFT" - iscsistart -b - fi - - if [ -n "${ISCSI_INITIATORNAME}" ] && [ -n "${ISCSI_TARGET}" ] && [ -n "${ISCSI_ADDRESS}" ] - then - good_msg "Activating iSCSI via cmdline" - - if [ "${ISCSI_TGPT}" ] - then - ADDITIONAL="${ADDITIONAL} -g ${ISCSI_TGPT}" - else - ADDITIONAL="${ADDITIONAL} -g 1" - fi - if [ "${ISCSI_PORT}" ] - then - ADDITIONAL="${ADDITIONAL} -p ${ISCSI_PORT}" - fi - - if [ "${ISCSI_USERNAME}" ] - then - ADDITIONAL="${ADDITIONAL} -u ${ISCSI_USERNAME}" - fi - - if [ "${ISCSI_PASSWORD}" ] - then - ADDITIONAL="${ADDITIONAL} -w ${ISCSI_PASSWORD}" - fi - - if [ "${ISCSI_USERNAME_IN}" ] - then - ADDITIONAL="${ADDITIONAL} -U ${ISCSI_USERNAME_IN}" - fi - - if [ "${ISCSI_PASSWORD_IN}" ] - then - ADDITIONAL="${ADDITIONAL} -W ${ISCSI_PASSWORD_IN}" - fi - - if [ "${ISCSI_DEBUG}" ] - then - ADDITIONAL="${ADDITIONAL} -d ${ISCSI_DEBUG}" - fi - - iscsistart -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" \ - -a "${ISCSI_ADDRESS}" ${ADDITIONAL} - - # let iscsid settle - otherwise mounting the iSCSI-disk - # will fail (very rarely, though) - sleep 1 - fi + if [ ! -e /usr/sbin/iscsistart ]; then + return 0 # disabled + fi + + if [ ! -n "${ISCSI_NOIBFT}" ] + then + good_msg "Activating iSCSI via iBFT" + iscsistart -b + fi + + if [ -n "${ISCSI_INITIATORNAME}" ] && [ -n "${ISCSI_TARGET}" ] && [ -n "${ISCSI_ADDRESS}" ] + then + good_msg "Activating iSCSI via cmdline" + + if [ "${ISCSI_TGPT}" ] + then + ADDITIONAL="${ADDITIONAL} -g ${ISCSI_TGPT}" + else + ADDITIONAL="${ADDITIONAL} -g 1" + fi + if [ "${ISCSI_PORT}" ] + then + ADDITIONAL="${ADDITIONAL} -p ${ISCSI_PORT}" + fi + + if [ "${ISCSI_USERNAME}" ] + then + ADDITIONAL="${ADDITIONAL} -u ${ISCSI_USERNAME}" + fi + + if [ "${ISCSI_PASSWORD}" ] + then + ADDITIONAL="${ADDITIONAL} -w ${ISCSI_PASSWORD}" + fi + + if [ "${ISCSI_USERNAME_IN}" ] + then + ADDITIONAL="${ADDITIONAL} -U ${ISCSI_USERNAME_IN}" + fi + + if [ "${ISCSI_PASSWORD_IN}" ] + then + ADDITIONAL="${ADDITIONAL} -W ${ISCSI_PASSWORD_IN}" + fi + + if [ "${ISCSI_DEBUG}" ] + then + ADDITIONAL="${ADDITIONAL} -d ${ISCSI_DEBUG}" + fi + + iscsistart -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" \ + -a "${ISCSI_ADDRESS}" ${ADDITIONAL} + + # let iscsid settle - otherwise mounting the iSCSI-disk + # will fail (very rarely, though) + sleep 1 + fi } # Open a LUKS device # It is either the root or a swap, other devices are supported in the scripts provided with sys-fs/cryptsetup-luks # $1 - root/swap open_luks() { - # TODO(lxnay): what has been seen, cannot be unseen. - # TODO(lxnay): there is so much wrong in this function... - - # please use 'tr' and this line, or remove it - # eval local TYPE=$(uppercase $1) - - case $1 in - root) - local TYPE=ROOT - ;; - swap) - local TYPE=SWAP - ;; - esac - - eval local LUKS_DEVICE='"${CRYPT_'${TYPE}'}"' LUKS_NAME="$1" LUKS_KEY='"${CRYPT_'${TYPE}'_KEY}"' LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"' LUKS_TRIM='"${CRYPT_'${TYPE}'_TRIM}"' - local DEV_ERROR=0 KEY_ERROR=0 KEYDEV_ERROR=0 - local mntkey="/mnt/key/" cryptsetup_options='' - - [ ! -e /sbin/cryptsetup ] && bad_msg "The ramdisk does not support LUKS" && exit 1 - while [ 1 ] - do - local gpg_cmd="" - # if crypt_silent=1 and some error occurs, enter shell quietly - if [ \( ${CRYPT_SILENT} -eq 1 \) -a \( \( \( ${DEV_ERROR} -eq 1 \) -o \( ${KEY_ERROR} -eq 1 \) \) -o \( ${KEYDEV_ERROR} -eq 1 \) \) ] - then - run_shell - elif [ ${DEV_ERROR} -eq 1 ] - then - prompt_user "LUKS_DEVICE" "${LUKS_NAME}" - DEV_ERROR=0 - elif [ ${KEY_ERROR} -eq 1 ] - then - prompt_user "LUKS_KEY" "${LUKS_NAME} key" - KEY_ERROR=0 - elif [ ${KEYDEV_ERROR} -eq 1 ] - then - prompt_user "LUKS_KEYDEV" "${LUKS_NAME} key device" - KEYDEV_ERROR=0 - else - local luks_dev=$(find_real_device "${LUKS_DEVICE}") - [ -n "${luks_dev}" ] && LUKS_DEVICE="${luks_dev}" # otherwise hope... - - setup_md_device "${LUKS_DEVICE}" - /sbin/cryptsetup isLuks "${LUKS_DEVICE}" - if [ $? -ne 0 ] - then - bad_msg "The LUKS device ${LUKS_DEVICE} does not contain a LUKS header" ${CRYPT_SILENT} - DEV_ERROR=1 - continue - else - # Handle keys - if [ "x${LUKS_TRIM}" = "xyes" ] - then - good_msg "Enabling TRIM support for ${LUKS_NAME}." ${CRYPT_SILENT} - cryptsetup_options="${cryptsetup_options} --allow-discards" - fi - - if [ -n "${LUKS_KEY}" ] - then - local REAL_LUKS_KEYDEV="${LUKS_KEYDEV}" - if [ ! -e "${mntkey}${LUKS_KEY}" ] - then - REAL_LUKS_KEYDEV=$(find_real_device "${LUKS_KEYDEV}") - if [ -b "${REAL_LUKS_KEYDEV}" ] && [ -n "${REAL_LUKS_KEYDEV}" ] - then good_msg "Using key device ${REAL_LUKS_KEYDEV}." ${CRYPT_SILENT} - else - good_msg "Please insert removable device ${LUKS_KEYDEV} for ${LUKS_NAME}" ${CRYPT_SILENT} - # abort after 10 secs - local count=10 - while [ ${count} -gt 0 ] - do - count=$((count-1)) - sleep 1 - REAL_LUKS_KEYDEV=$(find_real_device "${LUKS_KEYDEV}") - if [ -b "${REAL_LUKS_KEYDEV}" ] && [ -n "${REAL_LUKS_KEYDEV}" ] - then - good_msg "Removable device ${REAL_LUKS_KEYDEV} detected." ${CRYPT_SILENT} - break - fi - done - if [ ! -b "${REAL_LUKS_KEYDEV}" ] - then - eval CRYPT_${TYPE}_KEY=${LUKS_KEY} - bootstrap_key ${TYPE} - eval LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"' - REAL_LUKS_KEYDEV=$(find_real_device "${LUKS_KEYDEV}") - if [ ! -b "${REAL_LUKS_KEYDEV}" ]; then - KEYDEV_ERROR=1 - bad_msg "Removable device ${LUKS_KEYDEV} not found." ${CRYPT_SILENT} - continue - fi - # continue otherwise will mount keydev which is mounted by bootstrap - continue - fi - fi - # At this point a device was recognized, now let's see if the key is there - [ ! -d "$mntkey" ] && mkdir -p ${mntkey} 2>/dev/null >/dev/null - - mount -n -o ro ${REAL_LUKS_KEYDEV} ${mntkey} >/dev/null 2>/dev/null - if [ "$?" != '0' ] - then - KEYDEV_ERROR=1 - bad_msg "Mounting of device ${REAL_LUKS_KEYDEV} failed." ${CRYPT_SILENT} - continue - else - good_msg "Removable device ${REAL_LUKS_KEYDEV} mounted." ${CRYPT_SILENT} - sleep 2 - # keyfile exists? - if [ ! -e "${mntkey}${LUKS_KEY}" ]; then - umount -n ${mntkey} 2>/dev/null >/dev/null - KEY_ERROR=1 - KEYDEV_ERROR=1 - bad_msg "Key {LUKS_KEY} on device ${REAL_LUKS_KEYDEV} not found." ${CRYPT_SILENT} - continue - fi - fi - fi - # At this point a candidate key exists (either mounted before or not) - good_msg "${LUKS_KEY} on device ${REAL_LUKS_KEYDEV} found" ${CRYPT_SILENT} - if [ "$(echo ${LUKS_KEY} | grep -o '.gpg$')" = ".gpg" ] && [ -e /usr/bin/gpg ] ; then - [ -e /dev/tty ] && mv /dev/tty /dev/tty.org - mknod /dev/tty c 5 1 - cryptsetup_options="${cryptsetup_options} -d -" - gpg_cmd="/usr/bin/gpg --logger-file /dev/null --quiet --decrypt ${mntkey}${LUKS_KEY} |" - else - cryptsetup_options="${cryptsetup_options} -d ${mntkey}${LUKS_KEY}" - fi - fi - # At this point, keyfile or not, we're ready! - crypt_exec "${gpg_cmd}/sbin/cryptsetup ${cryptsetup_options} luksOpen ${LUKS_DEVICE} ${LUKS_NAME}" - crypt_exec_ret=$? - - [ -e /dev/tty.org ] \ - && rm -f /dev/tty \ - && mv /dev/tty.org /dev/tty - - if [ ${crypt_exec_ret} -eq 0 ] - then - good_msg "LUKS device ${LUKS_DEVICE} opened" ${CRYPT_SILENT} - break - else - bad_msg "Failed to open LUKS device ${LUKS_DEVICE}" ${CRYPT_SILENT} - DEV_ERROR=1 - KEY_ERROR=1 - KEYDEV_ERROR=1 - fi - fi - fi - done - umount ${mntkey} 2>/dev/null >/dev/null - rmdir -p ${mntkey} 2>/dev/null >/dev/null + # TODO(lxnay): what has been seen, cannot be unseen. + # TODO(lxnay): there is so much wrong in this function... + + # please use 'tr' and this line, or remove it + # eval local TYPE=$(uppercase $1) + + case $1 in + root) + local TYPE=ROOT + ;; + swap) + local TYPE=SWAP + ;; + esac + + eval local LUKS_DEVICE='"${CRYPT_'${TYPE}'}"' LUKS_NAME="$1" LUKS_KEY='"${CRYPT_'${TYPE}'_KEY}"' LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"' LUKS_TRIM='"${CRYPT_'${TYPE}'_TRIM}"' + local DEV_ERROR=0 KEY_ERROR=0 KEYDEV_ERROR=0 + local mntkey="/mnt/key/" cryptsetup_options='' + + [ ! -e /sbin/cryptsetup ] && bad_msg "The ramdisk does not support LUKS" && exit 1 + while [ 1 ] + do + local gpg_cmd="" + # if crypt_silent=1 and some error occurs, enter shell quietly + if [ \( ${CRYPT_SILENT} -eq 1 \) -a \( \( \( ${DEV_ERROR} -eq 1 \) -o \( ${KEY_ERROR} -eq 1 \) \) -o \( ${KEYDEV_ERROR} -eq 1 \) \) ] + then + run_shell + elif [ ${DEV_ERROR} -eq 1 ] + then + prompt_user "LUKS_DEVICE" "${LUKS_NAME}" + DEV_ERROR=0 + elif [ ${KEY_ERROR} -eq 1 ] + then + prompt_user "LUKS_KEY" "${LUKS_NAME} key" + KEY_ERROR=0 + elif [ ${KEYDEV_ERROR} -eq 1 ] + then + prompt_user "LUKS_KEYDEV" "${LUKS_NAME} key device" + KEYDEV_ERROR=0 + else + local luks_dev=$(find_real_device "${LUKS_DEVICE}") + [ -n "${luks_dev}" ] && LUKS_DEVICE="${luks_dev}" # otherwise hope... + + setup_md_device "${LUKS_DEVICE}" + /sbin/cryptsetup isLuks "${LUKS_DEVICE}" + if [ $? -ne 0 ] + then + bad_msg "The LUKS device ${LUKS_DEVICE} does not contain a LUKS header" ${CRYPT_SILENT} + DEV_ERROR=1 + continue + else + # Handle keys + if [ "x${LUKS_TRIM}" = "xyes" ] + then + good_msg "Enabling TRIM support for ${LUKS_NAME}." ${CRYPT_SILENT} + cryptsetup_options="${cryptsetup_options} --allow-discards" + fi + + if [ -n "${LUKS_KEY}" ] + then + local REAL_LUKS_KEYDEV="${LUKS_KEYDEV}" + if [ ! -e "${mntkey}${LUKS_KEY}" ] + then + REAL_LUKS_KEYDEV=$(find_real_device "${LUKS_KEYDEV}") + if [ -b "${REAL_LUKS_KEYDEV}" ] && [ -n "${REAL_LUKS_KEYDEV}" ] + then good_msg "Using key device ${REAL_LUKS_KEYDEV}." ${CRYPT_SILENT} + else + good_msg "Please insert removable device ${LUKS_KEYDEV} for ${LUKS_NAME}" ${CRYPT_SILENT} + # abort after 10 secs + local count=10 + while [ ${count} -gt 0 ] + do + count=$((count-1)) + sleep 1 + REAL_LUKS_KEYDEV=$(find_real_device "${LUKS_KEYDEV}") + if [ -b "${REAL_LUKS_KEYDEV}" ] && [ -n "${REAL_LUKS_KEYDEV}" ] + then + good_msg "Removable device ${REAL_LUKS_KEYDEV} detected." ${CRYPT_SILENT} + break + fi + done + if [ ! -b "${REAL_LUKS_KEYDEV}" ] + then + eval CRYPT_${TYPE}_KEY=${LUKS_KEY} + bootstrap_key ${TYPE} + eval LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"' + REAL_LUKS_KEYDEV=$(find_real_device "${LUKS_KEYDEV}") + if [ ! -b "${REAL_LUKS_KEYDEV}" ]; then + KEYDEV_ERROR=1 + bad_msg "Removable device ${LUKS_KEYDEV} not found." ${CRYPT_SILENT} + continue + fi + # continue otherwise will mount keydev which is mounted by bootstrap + continue + fi + fi + # At this point a device was recognized, now let's see if the key is there + [ ! -d "$mntkey" ] && mkdir -p ${mntkey} 2>/dev/null >/dev/null + + mount -n -o ro ${REAL_LUKS_KEYDEV} ${mntkey} >/dev/null 2>/dev/null + if [ "$?" != '0' ] + then + KEYDEV_ERROR=1 + bad_msg "Mounting of device ${REAL_LUKS_KEYDEV} failed." ${CRYPT_SILENT} + continue + else + good_msg "Removable device ${REAL_LUKS_KEYDEV} mounted." ${CRYPT_SILENT} + sleep 2 + # keyfile exists? + if [ ! -e "${mntkey}${LUKS_KEY}" ]; then + umount -n ${mntkey} 2>/dev/null >/dev/null + KEY_ERROR=1 + KEYDEV_ERROR=1 + bad_msg "Key {LUKS_KEY} on device ${REAL_LUKS_KEYDEV} not found." ${CRYPT_SILENT} + continue + fi + fi + fi + # At this point a candidate key exists (either mounted before or not) + good_msg "${LUKS_KEY} on device ${REAL_LUKS_KEYDEV} found" ${CRYPT_SILENT} + if [ "$(echo ${LUKS_KEY} | grep -o '.gpg$')" = ".gpg" ] && [ -e /usr/bin/gpg ] ; then + [ -e /dev/tty ] && mv /dev/tty /dev/tty.org + mknod /dev/tty c 5 1 + cryptsetup_options="${cryptsetup_options} -d -" + gpg_cmd="/usr/bin/gpg --logger-file /dev/null --quiet --decrypt ${mntkey}${LUKS_KEY} |" + else + cryptsetup_options="${cryptsetup_options} -d ${mntkey}${LUKS_KEY}" + fi + fi + # At this point, keyfile or not, we're ready! + crypt_exec "${gpg_cmd}/sbin/cryptsetup ${cryptsetup_options} luksOpen ${LUKS_DEVICE} ${LUKS_NAME}" + crypt_exec_ret=$? + + [ -e /dev/tty.org ] \ + && rm -f /dev/tty \ + && mv /dev/tty.org /dev/tty + + if [ ${crypt_exec_ret} -eq 0 ] + then + good_msg "LUKS device ${LUKS_DEVICE} opened" ${CRYPT_SILENT} + break + else + bad_msg "Failed to open LUKS device ${LUKS_DEVICE}" ${CRYPT_SILENT} + DEV_ERROR=1 + KEY_ERROR=1 + KEYDEV_ERROR=1 + fi + fi + fi + done + umount ${mntkey} 2>/dev/null >/dev/null + rmdir -p ${mntkey} 2>/dev/null >/dev/null } start_luks() { - # if key is set but key device isn't, find it - [ -n "${CRYPT_ROOT_KEY}" ] && [ -z "${CRYPT_ROOT_KEYDEV}" ] \ - && sleep 6 && bootstrap_key "ROOT" - - if [ -n "${CRYPT_ROOT}" ]; then - open_luks "root" - if [ -n "${REAL_ROOT}" ] - then - # Rescan volumes - start_volumes - else - REAL_ROOT="/dev/mapper/root" - fi - fi - - # TODO(lxnay): this sleep 6 thing is hurting my eyes sooooo much. - # same for swap, but no need to sleep if root was unencrypted - [ -n "${CRYPT_SWAP_KEY}" ] && [ -z "${CRYPT_SWAP_KEYDEV}" ] \ - && { [ -z "${CRYPT_ROOT}" ] && sleep 6; bootstrap_key "SWAP"; } - - if [ -n "${CRYPT_SWAP}" ]; then - open_luks "swap" - if [ -z "${REAL_RESUME}" ] - then - # Resume from swap as default - REAL_RESUME="/dev/mapper/swap" - fi - fi + # if key is set but key device isn't, find it + [ -n "${CRYPT_ROOT_KEY}" ] && [ -z "${CRYPT_ROOT_KEYDEV}" ] \ + && sleep 6 && bootstrap_key "ROOT" + + if [ -n "${CRYPT_ROOT}" ]; then + open_luks "root" + if [ -n "${REAL_ROOT}" ] + then + # Rescan volumes + start_volumes + else + REAL_ROOT="/dev/mapper/root" + fi + fi + + # TODO(lxnay): this sleep 6 thing is hurting my eyes sooooo much. + # same for swap, but no need to sleep if root was unencrypted + [ -n "${CRYPT_SWAP_KEY}" ] && [ -z "${CRYPT_SWAP_KEYDEV}" ] \ + && { [ -z "${CRYPT_ROOT}" ] && sleep 6; bootstrap_key "SWAP"; } + + if [ -n "${CRYPT_SWAP}" ]; then + open_luks "swap" + if [ -z "${REAL_RESUME}" ] + then + # Resume from swap as default + REAL_RESUME="/dev/mapper/swap" + fi + fi } sdelay() { - # Sleep a specific number of seconds if SDELAY is set - if [ -n "${SDELAY}" ] - then - good_msg "Waiting ${SDELAY} seconds..." - sleep ${SDELAY} - elif is_livecd - then - good_msg 'Hint: Use scandelay[=seconds] if your live medium is slowand boot fails' - fi + # Sleep a specific number of seconds if SDELAY is set + if [ -n "${SDELAY}" ] + then + good_msg "Waiting ${SDELAY} seconds..." + sleep ${SDELAY} + elif is_livecd + then + good_msg 'Hint: Use scandelay[=seconds] if your live medium is slowand boot fails' + fi } quiet_kmsg() { - # if QUIET is set make the kernel less chatty - [ -n "$QUIET" ] && echo '0' > /proc/sys/kernel/printk + # if QUIET is set make the kernel less chatty + [ -n "$QUIET" ] && echo '0' > /proc/sys/kernel/printk } verbose_kmsg() { - # if QUIET is set make the kernel less chatty - [ -n "$QUIET" ] && echo '6' > /proc/sys/kernel/printk + # if QUIET is set make the kernel less chatty + [ -n "$QUIET" ] && echo '6' > /proc/sys/kernel/printk } cdupdate() { - if is_livecd - then - if [ -x /${CDROOT_PATH}/cdupdate.sh ] - then - good_msg "Running cdupdate.sh" - ${CDROOT_PATH}/cdupdate.sh - if [ "$?" != '0' ] - then - bad_msg "Executing cdupdate.sh failed!" - run_shell - fi - else - good_msg 'No cdupdate.sh script found, skipping...' - fi - fi + if is_livecd + then + if [ -x /${CDROOT_PATH}/cdupdate.sh ] + then + good_msg "Running cdupdate.sh" + ${CDROOT_PATH}/cdupdate.sh + if [ "$?" != '0' ] + then + bad_msg "Executing cdupdate.sh failed!" + run_shell + fi + else + good_msg 'No cdupdate.sh script found, skipping...' + fi + fi } setup_md_device() { - local device + local device - [ -z "$1" ] && device="${REAL_ROOT}" || device="$1" - [ -z "${device}" ] && return # LiveCD + [ -z "$1" ] && device="${REAL_ROOT}" || device="$1" + [ -z "${device}" ] && return # LiveCD - if [ $(echo ${device}|sed -e 's#\(luks:\)\?\(/dev/md\)[[:digit:]]\+#\2#') = "/dev/md" ] - then - good_msg 'Detected real_root as a md device. Setting up the device node...' - MD_NUMBER=$(echo ${device}|sed -e 's#\(luks:\)\?/dev/md\([[:digit:]]\+\)#\2#') - if [ ! -e /dev/md${MD_NUMBER} ] - then - mknod /dev/md${MD_NUMBER} b 9 ${MD_NUMBER} >/dev/null 2>&1 - [ $? -ne 0 ] && bad_msg "Creation of /dev/md${MD_NUMBER} failed..." - fi - mdstart ${MDPART} /dev/md${MD_NUMBER} - fi + if [ $(echo ${device}|sed -e 's#\(luks:\)\?\(/dev/md\)[[:digit:]]\+#\2#') = "/dev/md" ] + then + good_msg 'Detected real_root as a md device. Setting up the device node...' + MD_NUMBER=$(echo ${device}|sed -e 's#\(luks:\)\?/dev/md\([[:digit:]]\+\)#\2#') + if [ ! -e /dev/md${MD_NUMBER} ] + then + mknod /dev/md${MD_NUMBER} b 9 ${MD_NUMBER} >/dev/null 2>&1 + [ $? -ne 0 ] && bad_msg "Creation of /dev/md${MD_NUMBER} failed..." + fi + mdstart ${MDPART} /dev/md${MD_NUMBER} + fi } do_rundebugshell() { - splashcmd verbose - good_msg 'Type "exit" to continue with normal bootup.' - [ -x /bin/sh ] && /bin/sh || /bin/ash - splashcmd quiet + splashcmd verbose + good_msg 'Type "exit" to continue with normal bootup.' + [ -x /bin/sh ] && /bin/sh || /bin/ash + splashcmd quiet } rundebugshell() { - if [ -n "$DEBUG" ] - then - good_msg 'Starting debug shell as requested by "debug" option.' - good_msg "Stopping by: ${1}" - do_rundebugshell - fi + if [ -n "$DEBUG" ] + then + good_msg 'Starting debug shell as requested by "debug" option.' + good_msg "Stopping by: ${1}" + do_rundebugshell + fi } resume_init() { - if [ -z "${REAL_RESUME}" ]; then - return 0 - fi - if [ "${NORESUME}" = "1" ]; then - return 0 - fi + if [ -z "${REAL_RESUME}" ]; then + return 0 + fi + if [ "${NORESUME}" = "1" ]; then + return 0 + fi - local resume_dev=$(find_real_device "${REAL_RESUME}") - if [ -n "${resume_dev}" ]; then - REAL_RESUME="${resume_dev}" - good_msg "Detected real_resume=${resume_dev}" - else - bad_msg "Cannot resolve real_resume=${REAL_RESUME}" - bad_msg "Something bad may happen, crossing fingers" - fi + local resume_dev=$(find_real_device "${REAL_RESUME}") + if [ -n "${resume_dev}" ]; then + REAL_RESUME="${resume_dev}" + good_msg "Detected real_resume=${resume_dev}" + else + bad_msg "Cannot resolve real_resume=${REAL_RESUME}" + bad_msg "Something bad may happen, crossing fingers" + fi - swsusp_resume + swsusp_resume } swsusp_resume() { - # determine swap resume partition - local device=$(ls -lL "${REAL_RESUME}" | sed 's/\ */ /g' | cut -d \ -f 5-6 | sed 's/,\ */:/') - [ -f /sys/power/resume -a -n "${device}" ] && \ - echo "${device}" > /sys/power/resume + # determine swap resume partition + local device=$(ls -lL "${REAL_RESUME}" | sed 's/\ */ /g' | cut -d \ -f 5-6 | sed 's/,\ */:/') + [ -f /sys/power/resume -a -n "${device}" ] && \ + echo "${device}" > /sys/power/resume } find_loop() { - for loop in ${LOOPS} - do - if [ -e "${CDROOT_PATH}""${loop}" ] - then - LOOP="${loop}" - fi - done + for loop in ${LOOPS} + do + if [ -e "${CDROOT_PATH}""${loop}" ] + then + LOOP="${loop}" + fi + done } find_looptype() { - LOOPTYPE="${LOOP##*.}" - [ "${LOOPTYPE}" == "loop" ] && LOOPTYPE="normal" - [ "${LOOP}" == "/zisofs" ] && LOOPTYPE="${LOOP#/}" - [ -z "${LOOPTYPE}" ] && LOOPTYPE="noloop" + LOOPTYPE="${LOOP##*.}" + [ "${LOOPTYPE}" == "loop" ] && LOOPTYPE="normal" + [ "${LOOP}" == "/zisofs" ] && LOOPTYPE="${LOOP#/}" + [ -z "${LOOPTYPE}" ] && LOOPTYPE="noloop" } getdvhoff() { - echo $(( $(hexdump -n 4 -s $((316 + 12 * $2)) -e '"%i"' $1) * 512)) + echo $(( $(hexdump -n 4 -s $((316 + 12 * $2)) -e '"%i"' $1) * 512)) } setup_squashfs_aufs() { - # Setup aufs directories and vars - local overlay=/mnt/overlay - local static=/mnt/livecd + # Setup aufs directories and vars + local overlay=/mnt/overlay + local static=/mnt/livecd - for i in "${overlay}" "${static}"; do - [ ! -d "${i}" ] && mkdir -p "${i}" - done - good_msg "Loading aufs" - modprobe aufs > /dev/null 2>&1 + for i in "${overlay}" "${static}"; do + [ ! -d "${i}" ] && mkdir -p "${i}" + done + good_msg "Loading aufs" + modprobe aufs > /dev/null 2>&1 - mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${static}" - mount -t tmpfs none "${overlay}" - mount -t aufs -o br:${overlay}:${static} aufs "${NEW_ROOT}" + mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${static}" + mount -t tmpfs none "${overlay}" + mount -t aufs -o br:${overlay}:${static} aufs "${NEW_ROOT}" - [ ! -d "${NEW_ROOT}${overlay}" ] && mkdir -p "${NEW_ROOT}${overlay}" - [ ! -d "${NEW_ROOT}${static}" ] && mkdir -p "${NEW_ROOT}${static}" - echo "aufs / aufs defaults 0 0" > "${NEW_ROOT}"/etc/fstab - for i in "${overlay}" "${static}"; do mount --move "${i}" "${NEW_ROOT}${i}"; done + [ ! -d "${NEW_ROOT}${overlay}" ] && mkdir -p "${NEW_ROOT}${overlay}" + [ ! -d "${NEW_ROOT}${static}" ] && mkdir -p "${NEW_ROOT}${static}" + echo "aufs / aufs defaults 0 0" > "${NEW_ROOT}"/etc/fstab + for i in "${overlay}" "${static}"; do mount --move "${i}" "${NEW_ROOT}${i}"; done - # have handy /mnt/cdrom (CDROOT_PATH) as well - local new_cdroot="${NEW_ROOT}${CDROOT_PATH}" - [ ! -d "${new_cdroot}" ] && mkdir -p "${new_cdroot}" - mount --bind "${CDROOT_PATH}" "${new_cdroot}" + # have handy /mnt/cdrom (CDROOT_PATH) as well + local new_cdroot="${NEW_ROOT}${CDROOT_PATH}" + [ ! -d "${new_cdroot}" ] && mkdir -p "${new_cdroot}" + mount --bind "${CDROOT_PATH}" "${new_cdroot}" } livecd_init() { - good_msg "Making tmpfs for ${NEW_ROOT}" - mount -n -t tmpfs -o mode=0755 tmpfs "${NEW_ROOT}" - - local dirs= - - dirs="dev mnt proc run sys tmp mnt/livecd" - dirs="${dirs} mnt/key tmp/.initrd mnt/gentoo" - for i in ${dirs}; do - mkdir -p "${NEW_ROOT}/${i}" - chmod 755 "${NEW_ROOT}/${i}" - done - [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}" - [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3 - [ ! -e "${NEW_ROOT}/dev/console" ] && \ - mknod "${NEW_ROOT}"/dev/console c 5 1 - - # For SGI LiveCDs ... - if [ "${LOOPTYPE}" = "sgimips" ]; then - [ ! -e "${NEW_ROOT}/dev/sr0" ] && \ - mknod "${NEW_ROOT}/dev/sr0" b 11 0 - [ ! -e "${NEW_ROOT}/dev/loop0" ] && \ - mknod "${NEW_ROOT}/dev/loop0" b 7 0 - fi - - # Required for splash to work. Not an issue with the initrd as this - # device isn't created there and is not needed. - if [ -e /dev/tty1 ]; then - [ ! -e "${NEW_ROOT}/dev/tty1" ] && \ - mknod "${NEW_ROOT}/dev/tty1" c 4 1 - fi - - if ! is_nfs && [ "${LOOPTYPE}" != "sgimips" ]; then - bootstrap_cd - fi - - if [ "${REAL_ROOT}" = '' ] - then - warn_msg "No bootable medium found. Waiting for new devices..." - COUNTER=0 - while [ ${COUNTER} -lt 3 ]; do - sleep 3 - let COUNTER=${COUNTER}+1 - done - sleep 1 - bootstrap_cd - fi - - if [ "${REAL_ROOT}" = '' ] - then - # leave stale mounts around, make possible to debug - bad_msg 'Could not find CD to boot, something else needed!' - CDROOT=0 - fi + good_msg "Making tmpfs for ${NEW_ROOT}" + mount -n -t tmpfs -o mode=0755 tmpfs "${NEW_ROOT}" + + local dirs= + + dirs="dev mnt proc run sys tmp mnt/livecd" + dirs="${dirs} mnt/key tmp/.initrd mnt/gentoo" + for i in ${dirs}; do + mkdir -p "${NEW_ROOT}/${i}" + chmod 755 "${NEW_ROOT}/${i}" + done + [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}" + [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3 + [ ! -e "${NEW_ROOT}/dev/console" ] && \ + mknod "${NEW_ROOT}"/dev/console c 5 1 + + # For SGI LiveCDs ... + if [ "${LOOPTYPE}" = "sgimips" ]; then + [ ! -e "${NEW_ROOT}/dev/sr0" ] && \ + mknod "${NEW_ROOT}/dev/sr0" b 11 0 + [ ! -e "${NEW_ROOT}/dev/loop0" ] && \ + mknod "${NEW_ROOT}/dev/loop0" b 7 0 + fi + + # Required for splash to work. Not an issue with the initrd as this + # device isn't created there and is not needed. + if [ -e /dev/tty1 ]; then + [ ! -e "${NEW_ROOT}/dev/tty1" ] && \ + mknod "${NEW_ROOT}/dev/tty1" c 4 1 + fi + + if ! is_nfs && [ "${LOOPTYPE}" != "sgimips" ]; then + bootstrap_cd + fi + + if [ "${REAL_ROOT}" = '' ] + then + warn_msg "No bootable medium found. Waiting for new devices..." + COUNTER=0 + while [ ${COUNTER} -lt 3 ]; do + sleep 3 + let COUNTER=${COUNTER}+1 + done + sleep 1 + bootstrap_cd + fi + + if [ "${REAL_ROOT}" = '' ] + then + # leave stale mounts around, make possible to debug + bad_msg 'Could not find CD to boot, something else needed!' + CDROOT=0 + fi } livecd_mount() { - # Let Init scripts know that we booted from CD - export CDBOOT - CDBOOT=1 - - good_msg 'Determining looptype ...' - cd "${NEW_ROOT}" - - # Find loop and looptype - [ -z "${LOOP}" ] && find_loop - [ -z "${LOOPTYPE}" ] && find_looptype - - cache_cd_contents - - # If encrypted, find key and mount, otherwise mount as usual - if [ -n "${CRYPT_ROOT}" ] - then - CRYPT_ROOT_KEY="$(head -n 1 "${CDROOT_PATH}"/${CDROOT_MARKER})" - CRYPT_ROOT='/dev/loop0' - good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}" - - losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}" - test_success 'Preparing loop filesystem' - - start_luks - - case ${LOOPTYPE} in - normal) - MOUNTTYPE="ext2" - ;; - *) - MOUNTTYPE="${LOOPTYPE}" - ;; - esac - mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root \ - "${NEW_ROOT}/mnt/livecd" - test_success 'Mount filesystem' - FS_LOCATION='mnt/livecd' - else - # Setup the loopback mounts, if unencrypted - if [ "${LOOPTYPE}" = 'normal' ]; then - _livecd_mount_normal - FS_LOCATION='mnt/livecd' - elif [ "${LOOPTYPE}" = 'squashfs' ]; then - _livecd_mount_squashfs - FS_LOCATION='mnt/livecd' - elif [ "${LOOPTYPE}" = 'gcloop' ]; then - _livecd_mount_gcloop - FS_LOCATION='mnt/livecd' - elif [ "${LOOPTYPE}" = 'zisofs' ]; then - FS_LOCATION="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}" - elif [ "${LOOPTYPE}" = 'noloop' ]; then - FS_LOCATION="${CDROOT_PATH/\/}" - elif [ "${LOOPTYPE}" = 'sgimips' ]; then - _livecd_mount_sgimips - FS_LOCATION='mnt/livecd' - fi - fi - - is_nfs && _livecd_mount_unpack_nfs - - # Manually copy livecd content to tmpfs if aufs is disabled - is_aufs || _livecd_mount_copy_content + # Let Init scripts know that we booted from CD + export CDBOOT + CDBOOT=1 + + good_msg 'Determining looptype ...' + cd "${NEW_ROOT}" + + # Find loop and looptype + [ -z "${LOOP}" ] && find_loop + [ -z "${LOOPTYPE}" ] && find_looptype + + cache_cd_contents + + # If encrypted, find key and mount, otherwise mount as usual + if [ -n "${CRYPT_ROOT}" ] + then + CRYPT_ROOT_KEY="$(head -n 1 "${CDROOT_PATH}"/${CDROOT_MARKER})" + CRYPT_ROOT='/dev/loop0' + good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}" + + losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}" + test_success 'Preparing loop filesystem' + + start_luks + + case ${LOOPTYPE} in + normal) + MOUNTTYPE="ext2" + ;; + *) + MOUNTTYPE="${LOOPTYPE}" + ;; + esac + mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root \ + "${NEW_ROOT}/mnt/livecd" + test_success 'Mount filesystem' + FS_LOCATION='mnt/livecd' + else + # Setup the loopback mounts, if unencrypted + if [ "${LOOPTYPE}" = 'normal' ]; then + _livecd_mount_normal + FS_LOCATION='mnt/livecd' + elif [ "${LOOPTYPE}" = 'squashfs' ]; then + _livecd_mount_squashfs + FS_LOCATION='mnt/livecd' + elif [ "${LOOPTYPE}" = 'gcloop' ]; then + _livecd_mount_gcloop + FS_LOCATION='mnt/livecd' + elif [ "${LOOPTYPE}" = 'zisofs' ]; then + FS_LOCATION="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}" + elif [ "${LOOPTYPE}" = 'noloop' ]; then + FS_LOCATION="${CDROOT_PATH/\/}" + elif [ "${LOOPTYPE}" = 'sgimips' ]; then + _livecd_mount_sgimips + FS_LOCATION='mnt/livecd' + fi + fi + + is_nfs && _livecd_mount_unpack_nfs + + # Manually copy livecd content to tmpfs if aufs is disabled + is_aufs || _livecd_mount_copy_content } # Unpack additional packages from NFS mount @@ -1621,186 +1621,186 @@ livecd_mount() { # We do this now, so that additional packages can add whereever # they want. _livecd_mount_unpack_nfs() { - if [ -e "${CDROOT_PATH}/add" ]; then - for targz in $(ls ${CDROOT_PATH}/add/*.tar.gz); do - tarname=$(basename ${targz}) - good_msg "Adding additional package ${tarname}" - (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz}) - done - fi + if [ -e "${CDROOT_PATH}/add" ]; then + for targz in $(ls ${CDROOT_PATH}/add/*.tar.gz); do + tarname=$(basename ${targz}) + good_msg "Adding additional package ${tarname}" + (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz}) + done + fi } _livecd_mount_sgimips() { - # getdvhoff finds the starting offset (in bytes) of the squashfs - # partition on the cdrom and returns this offset for losetup - # - # All currently supported SGI Systems use SCSI CD-ROMs, so - # so we know that the CD-ROM is usually going to be /dev/sr0. - # - # We use the value given to losetup to set /dev/loop0 to point - # to the liveCD root partition, and then mount /dev/loop0 as - # the LiveCD rootfs - good_msg 'Locating the SGI LiveCD Root Partition' - echo ' ' | \ - losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \ - "${NEW_ROOT}${CDROOT_DEV}" \ - "${NEW_ROOT}${REAL_ROOT}" - test_success 'losetup /dev/sr0 /dev/loop0' - - good_msg 'Mounting the Root Partition' - mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" \ - "${NEW_ROOT}/mnt/livecd" - test_success 'mount /dev/loop0 /' + # getdvhoff finds the starting offset (in bytes) of the squashfs + # partition on the cdrom and returns this offset for losetup + # + # All currently supported SGI Systems use SCSI CD-ROMs, so + # so we know that the CD-ROM is usually going to be /dev/sr0. + # + # We use the value given to losetup to set /dev/loop0 to point + # to the liveCD root partition, and then mount /dev/loop0 as + # the LiveCD rootfs + good_msg 'Locating the SGI LiveCD Root Partition' + echo ' ' | \ + losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \ + "${NEW_ROOT}${CDROOT_DEV}" \ + "${NEW_ROOT}${REAL_ROOT}" + test_success 'losetup /dev/sr0 /dev/loop0' + + good_msg 'Mounting the Root Partition' + mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" \ + "${NEW_ROOT}/mnt/livecd" + test_success 'mount /dev/loop0 /' } _livecd_mount_gcloop() { - good_msg 'Mounting gcloop filesystem' - echo ' ' | losetup -E 19 -e ucl-0 -p0 \ - "${NEW_ROOT}/dev/loop0" \ - "${CDROOT_PATH}/${LOOPEXT}${LOOP}" - test_success 'losetup the loop device' + good_msg 'Mounting gcloop filesystem' + echo ' ' | losetup -E 19 -e ucl-0 -p0 \ + "${NEW_ROOT}/dev/loop0" \ + "${CDROOT_PATH}/${LOOPEXT}${LOOP}" + test_success 'losetup the loop device' - mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd" - test_success 'Mount the losetup loop device' + mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd" + test_success 'Mount the losetup loop device' } _livecd_mount_normal() { - good_msg 'Mounting loop filesystem' - mount -t ext2 -o loop,ro \ - "${CDROOT_PATH}/${LOOPEXT}${LOOP}" \ - "${NEW_ROOT}/mnt/livecd" - test_success 'Mount filesystem' + good_msg 'Mounting loop filesystem' + mount -t ext2 -o loop,ro \ + "${CDROOT_PATH}/${LOOPEXT}${LOOP}" \ + "${NEW_ROOT}/mnt/livecd" + test_success 'Mount filesystem' } _livecd_mount_squashfs() { - # if AUFS, redirect to the squashfs+aufs setup function - if is_aufs; then - good_msg 'Mounting squashfs & aufs filesystems' - setup_squashfs_aufs - test_success 'Mount filesystem' - return # preserve old behaviour - fi - - good_msg 'Mounting squashfs filesystem' - local cached_squashfs_path="${NEW_ROOT}/mnt/${LOOP}" - local squashfs_path="${CDROOT_PATH}/${LOOPEXT}${LOOP}" - - # Upgrade to cached version if possible - if [ -n "${DO_cache}" ] && [ -f "${cached_squashfs_path}" ]; then - squashfs_path="${cached_squashfs_path}" - fi - - mount -t squashfs -o loop,ro "${squashfs_path}" \ - "${NEW_ROOT}/mnt/livecd" || { - bad_msg "squashfs filesystem could not be mounted." - do_rundebugshell - } + # if AUFS, redirect to the squashfs+aufs setup function + if is_aufs; then + good_msg 'Mounting squashfs & aufs filesystems' + setup_squashfs_aufs + test_success 'Mount filesystem' + return # preserve old behaviour + fi + + good_msg 'Mounting squashfs filesystem' + local cached_squashfs_path="${NEW_ROOT}/mnt/${LOOP}" + local squashfs_path="${CDROOT_PATH}/${LOOPEXT}${LOOP}" + + # Upgrade to cached version if possible + if [ -n "${DO_cache}" ] && [ -f "${cached_squashfs_path}" ]; then + squashfs_path="${cached_squashfs_path}" + fi + + mount -t squashfs -o loop,ro "${squashfs_path}" \ + "${NEW_ROOT}/mnt/livecd" || { + bad_msg "squashfs filesystem could not be mounted." + do_rundebugshell + } } # Manually copy livecd read-only content into the final livecd root # filesystem directory, which has been mounted as tmpfs. _livecd_mount_copy_content() { - local fs_loc="${NEW_ROOT}/${FS_LOCATION}" - - good_msg "Copying read-write image contents to tmpfs" - # Copy over stuff that should be writable - ( - cd "${fs_loc}" && cp -a ${ROOT_TREES} "${NEW_ROOT}" - ) || { - bad_msg "Copy failed, dropping into a shell." - do_rundebugshell - } - - # Now we do the links. - for x in ${ROOT_LINKS}; do - - if [ -L "${fs_loc}/${x}" ]; then - ln -s "$(readlink ${fs_loc}/${x})" "${x}" 2>/dev/null - continue - fi - - # List all subdirectories of x - find "${fs_loc}/${x}" -type d 2>/dev/null | \ - while read directory; do - - # Strip the prefix of the FS_LOCATION - directory="${directory#${fs_loc}/}" - - # Skip this directory if we already linked a parent - # directory - if [ "${current_parent}" != "" ]; then - var=$(echo "${directory}" | \ - grep "^${current_parent}") - if [ "${var}" != "" ]; then - continue - fi - fi - - local root_d="${NEW_ROOT}/${directory}" - local fsloc_d="${FS_LOCATION}/${directory}" - - # Test if the directory exists already - if [ ! -e "/${root_d}" ]; then - # It does not exist, make a link to the livecd - ln -s "/${FS_LOCATION}/${directory}" \ - "${directory}" 2>/dev/null - current_parent="${directory}" - continue - fi - - # It does exist, link all the individual files - local fs_d="/${fs_loc}/${directory}" - - for file in $(ls "${fs_d}"); do - [ -d "${fs_d}/${file}" ] && continue - [ -e "${root_d}/${file}" ] && continue - - ln -s "/${fsloc_d}/${file}" \ - "${directory}/${file}" 2> /dev/null - done - - done - - done - - mkdir initramfs proc tmp sys run 2>/dev/null - chmod 1777 tmp - - # have handy /mnt/cdrom (CDROOT_PATH) as well - _new_cdroot="${NEW_ROOT}${CDROOT_PATH}" - [ ! -d "${_new_cdroot}" ] && mkdir -p "${_new_cdroot}" - mount --bind "${CDROOT_PATH}" "${_new_cdroot}" + local fs_loc="${NEW_ROOT}/${FS_LOCATION}" + + good_msg "Copying read-write image contents to tmpfs" + # Copy over stuff that should be writable + ( + cd "${fs_loc}" && cp -a ${ROOT_TREES} "${NEW_ROOT}" + ) || { + bad_msg "Copy failed, dropping into a shell." + do_rundebugshell + } + + # Now we do the links. + for x in ${ROOT_LINKS}; do + + if [ -L "${fs_loc}/${x}" ]; then + ln -s "$(readlink ${fs_loc}/${x})" "${x}" 2>/dev/null + continue + fi + + # List all subdirectories of x + find "${fs_loc}/${x}" -type d 2>/dev/null | \ + while read directory; do + + # Strip the prefix of the FS_LOCATION + directory="${directory#${fs_loc}/}" + + # Skip this directory if we already linked a parent + # directory + if [ "${current_parent}" != "" ]; then + var=$(echo "${directory}" | \ + grep "^${current_parent}") + if [ "${var}" != "" ]; then + continue + fi + fi + + local root_d="${NEW_ROOT}/${directory}" + local fsloc_d="${FS_LOCATION}/${directory}" + + # Test if the directory exists already + if [ ! -e "/${root_d}" ]; then + # It does not exist, make a link to the livecd + ln -s "/${FS_LOCATION}/${directory}" \ + "${directory}" 2>/dev/null + current_parent="${directory}" + continue + fi + + # It does exist, link all the individual files + local fs_d="/${fs_loc}/${directory}" + + for file in $(ls "${fs_d}"); do + [ -d "${fs_d}/${file}" ] && continue + [ -e "${root_d}/${file}" ] && continue + + ln -s "/${fsloc_d}/${file}" \ + "${directory}/${file}" 2> /dev/null + done + + done + + done + + mkdir initramfs proc tmp sys run 2>/dev/null + chmod 1777 tmp + + # have handy /mnt/cdrom (CDROOT_PATH) as well + _new_cdroot="${NEW_ROOT}${CDROOT_PATH}" + [ ! -d "${_new_cdroot}" ] && mkdir -p "${_new_cdroot}" + mount --bind "${CDROOT_PATH}" "${_new_cdroot}" } get_mounts_list() { - awk ' - /^[[:blank:]]*#/ { next } - { print $1 } - ' ${NEW_ROOT}/etc/initramfs.mounts + awk ' + /^[[:blank:]]*#/ { next } + { print $1 } + ' ${NEW_ROOT}/etc/initramfs.mounts } get_mount_fstype() { - [ -e "${NEW_ROOT}"/etc/fstab ] || return 1 - awk -v fs="$1" ' - /^[[:blank:]]*#/ { next } - $2 == fs { print $3 } - ' ${NEW_ROOT}/etc/fstab + [ -e "${NEW_ROOT}"/etc/fstab ] || return 1 + awk -v fs="$1" ' + /^[[:blank:]]*#/ { next } + $2 == fs { print $3 } + ' ${NEW_ROOT}/etc/fstab } get_mount_options() { - [ -e "${NEW_ROOT}"/etc/fstab ] || return 1 - awk -v fs="$1" ' - /^[[:blank:]]*#/ { next } - $2 == fs { print $4 } - ' ${NEW_ROOT}/etc/fstab + [ -e "${NEW_ROOT}"/etc/fstab ] || return 1 + awk -v fs="$1" ' + /^[[:blank:]]*#/ { next } + $2 == fs { print $4 } + ' ${NEW_ROOT}/etc/fstab } get_mount_device() { - [ -e "${NEW_ROOT}"/etc/fstab ] || return 1 - awk -v fs="$1" ' - /^[[:blank:]]*#/ { next } - $2 == fs { print $1 } - ' ${NEW_ROOT}/etc/fstab + [ -e "${NEW_ROOT}"/etc/fstab ] || return 1 + awk -v fs="$1" ' + /^[[:blank:]]*#/ { next } + $2 == fs { print $1 } + ' ${NEW_ROOT}/etc/fstab } # If the kernel is handed a mount option is does not recognize, it WILL fail to @@ -1809,255 +1809,255 @@ get_mount_device() { # To make like a little easier, busybox mount does not care about leading, # trailing or duplicate commas. strip_mount_options() { - sed -r 's/(,|^)(no)?auto(,|$)/,/g' + sed -r 's/(,|^)(no)?auto(,|$)/,/g' } # Read /etc/initramfs.mounts from ${NEW_ROOT} and mount the # listed filesystem mountpoints. For instance, /usr, which is # required by udev & systemd. ensure_initramfs_mounts() { - local fslist= - - if [ -f "${NEW_ROOT}/etc/initramfs.mounts" ]; then - fslist="$(get_mounts_list)" - else - fslist="/usr" - fi - - local dev= fstype= opts= mnt= cmd= - for fs in ${fslist}; do - - mnt="${NEW_ROOT}${fs}" - if mountpoint -q "${mnt}"; then - good_msg "${fs} already mounted, skipping..." - continue - fi - - dev=$(get_mount_device "${fs}") - [ -z "${dev}" ] && continue - # Resolve it like util-linux mount does - [ -L "${dev}" ] && dev=$(readlink "${dev}") - # In this case, it's probably part of the filesystem - # and not a mountpoint - [ -z "${dev}" ] && continue - - fstype=$(get_mount_fstype "${fs}") - if get_mount_options "${fs}" | fgrep -q bind; then - opts="bind" - dev="${NEW_ROOT}${dev}" - else - # ro must be trailing, and the options will always - # contain at least 'defaults' - opts="$(get_mount_options ${fs} | strip_mount_options)" - opts="${opts},ro" - fi - - cmd="mount -t ${fstype} -o ${opts} ${dev} ${mnt}" - good_msg "Mounting ${dev} as ${fs}: ${cmd}" - if ! ${cmd}; then - bad_msg "Unable to mount ${dev} for ${fs}" - fi - done + local fslist= + + if [ -f "${NEW_ROOT}/etc/initramfs.mounts" ]; then + fslist="$(get_mounts_list)" + else + fslist="/usr" + fi + + local dev= fstype= opts= mnt= cmd= + for fs in ${fslist}; do + + mnt="${NEW_ROOT}${fs}" + if mountpoint -q "${mnt}"; then + good_msg "${fs} already mounted, skipping..." + continue + fi + + dev=$(get_mount_device "${fs}") + [ -z "${dev}" ] && continue + # Resolve it like util-linux mount does + [ -L "${dev}" ] && dev=$(readlink "${dev}") + # In this case, it's probably part of the filesystem + # and not a mountpoint + [ -z "${dev}" ] && continue + + fstype=$(get_mount_fstype "${fs}") + if get_mount_options "${fs}" | fgrep -q bind; then + opts="bind" + dev="${NEW_ROOT}${dev}" + else + # ro must be trailing, and the options will always + # contain at least 'defaults' + opts="$(get_mount_options ${fs} | strip_mount_options)" + opts="${opts},ro" + fi + + cmd="mount -t ${fstype} -o ${opts} ${dev} ${mnt}" + good_msg "Mounting ${dev} as ${fs}: ${cmd}" + if ! ${cmd}; then + bad_msg "Unable to mount ${dev} for ${fs}" + fi + done } fstype_init() { - local fstype="${1}" - if [ "${fstype}" = "btrfs" ]; then - # start BTRFS volume detection, if available - [ -x /sbin/btrfs ] && /sbin/btrfs device scan - elif [ -z "${fstype}" ]; then - warn_msg "Unable to detect the filesystem type (empty variable)" - fi + local fstype="${1}" + if [ "${fstype}" = "btrfs" ]; then + # start BTRFS volume detection, if available + [ -x /sbin/btrfs ] && /sbin/btrfs device scan + elif [ -z "${fstype}" ]; then + warn_msg "Unable to detect the filesystem type (empty variable)" + fi } rootdev_init() { - good_msg "Initializing root device..." - - while true - do - local got_good_root= - while [ "${got_good_root}" != '1' ] - do - case "${REAL_ROOT}" in - LABEL=*|UUID=*) - - local root_dev=$(find_real_device "${REAL_ROOT}") - if [ -n "${root_dev}" ]; then - REAL_ROOT="${root_dev}" - good_msg "Detected root: ${REAL_ROOT}" - else - bad_msg "Unable to resolve root: ${REAL_ROOT}" - prompt_user "REAL_ROOT" "root block device" - got_good_root=0 - continue - fi - ;; - # move this cruft into a separate function? do we really need - # the crazy root=ZFS= thing? can't we just detect the fstype? - ZFS*) - if [ "${USE_ZFS}" = '0' ]; then - prompt_user "REAL_ROOT" "root block device" - continue - fi - ROOT_DEV="${REAL_ROOT#*=}" - if [ "${ROOT_DEV}" != 'ZFS' ] - then - if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ] - then - got_good_root=1; - REAL_ROOT=${ROOT_DEV} - ROOTFSTYPE=zfs - else - bad_msg "${ROOT_DEV} is not a filesystem" - prompt_user "REAL_ROOT" "root block device" - got_good_root=0 - continue - fi - else - BOOTFS=$(/sbin/zpool list -H -o bootfs) - if [ "${BOOTFS}" != '-' ] - then - - for i in ${BOOTFS} - do - - zfs get type ${i} > /dev/null - retval=$? - - if [ ${retval} -eq 0 ]; then - got_good_root=1 - REAL_ROOT=${i} - ROOTFSTYPE=zfs - break - fi - done - else - got_good_root=0 - fi - - fi - - if [ ${got_good_root} -ne 1 ]; then - prompt_user "REAL_ROOT" "root block device" - got_good_root=0 - fi - continue - ;; - esac - - if [ "${REAL_ROOT}" = '' ] - then - # No REAL_ROOT determined/specified. Prompt user for root block device. - prompt_user "REAL_ROOT" "root block device" - got_good_root=0 - - # Check for a block device or NFS - elif [ -b "${REAL_ROOT}" ] || is_nfs - then - got_good_root=1 - - else - bad_msg "Block device ${REAL_ROOT} is not a valid root device..." - REAL_ROOT="" - got_good_root=0 - fi - done - - - if [ "${got_good_root}" = "1" ] && is_livecd && ! is_nfs; then - # CD already mounted; no further checks necessary - break - fi - if [ "${LOOPTYPE}" = "sgimips" ]; then - # sgimips mounts the livecd root partition directly - # there is no isofs filesystem to worry about - break - fi - - local fstype=$(get_device_fstype "${REAL_ROOT}") - good_msg "Initializing ${REAL_ROOT} if needed, detected fstype: ${fstype}" - fstype_init "${fstype}" - - good_msg "Mounting ${REAL_ROOT} as root..." - - # TODO(lxnay): determine if it's possible to move this crufty thing into fstype_init - if [ "${ROOTFSTYPE}" = 'zfs' ] - then - if [ "$(zfs get -H -o value mountpoint ${REAL_ROOT})" = 'legacy' ] - then - MOUNT_STATE=rw - else - MOUNT_STATE=rw,zfsutil - fi - else - MOUNT_STATE=ro - fi - - # Try to mount the device as ${NEW_ROOT} - if is_nfs; then - findnfsmount - else - # mount ro so fsck doesn't barf later - if [ "${REAL_ROOTFLAGS}" = '' ]; then - good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE}" - mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT} - else - good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS}" - mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT} - fi - fi - - # If mount is successful break out of the loop - # else not a good root and start over. - if [ "$?" = '0' ] - then - # now that the root filesystem is mounted, before - # checking the validity of ${NEW_ROOT} and ${REAL_INIT}, - # ensure that ${NEW_ROOT}/etc/initramfs.mounts entries - # are mounted. - ensure_initramfs_mounts - - # NFS does not need further checks here. - if is_nfs; then - break - fi - - if [ ! -d "${NEW_ROOT}/dev" ]; then - _msg="The filesystem ${REAL_ROOT}," - _msg="${_msg} mounted at ${NEW_ROOT}" - _msg="${_msg} does not contain /dev" - _msg="${_msg}, init will likely fail..." - bad_msg "${_msg}" - fi - if [ ! -x "${NEW_ROOT}${REAL_INIT}" ]; then - _msg="The filesystem ${REAL_ROOT}," - _msg="${_msg} mounted at ${NEW_ROOT}" - _msg="${_msg} does not contain a valid" - _msg="${_msg} init=${REAL_INIT}" - bad_msg "${_msg}" - fi - break - else - bad_msg "Could not mount specified ROOT, try again" - got_good_root=0 - REAL_ROOT='' - fi - done + good_msg "Initializing root device..." + + while true + do + local got_good_root= + while [ "${got_good_root}" != '1' ] + do + case "${REAL_ROOT}" in + LABEL=*|UUID=*) + + local root_dev=$(find_real_device "${REAL_ROOT}") + if [ -n "${root_dev}" ]; then + REAL_ROOT="${root_dev}" + good_msg "Detected root: ${REAL_ROOT}" + else + bad_msg "Unable to resolve root: ${REAL_ROOT}" + prompt_user "REAL_ROOT" "root block device" + got_good_root=0 + continue + fi + ;; + # move this cruft into a separate function? do we really need + # the crazy root=ZFS= thing? can't we just detect the fstype? + ZFS*) + if [ "${USE_ZFS}" = '0' ]; then + prompt_user "REAL_ROOT" "root block device" + continue + fi + ROOT_DEV="${REAL_ROOT#*=}" + if [ "${ROOT_DEV}" != 'ZFS' ] + then + if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ] + then + got_good_root=1; + REAL_ROOT=${ROOT_DEV} + ROOTFSTYPE=zfs + else + bad_msg "${ROOT_DEV} is not a filesystem" + prompt_user "REAL_ROOT" "root block device" + got_good_root=0 + continue + fi + else + BOOTFS=$(/sbin/zpool list -H -o bootfs) + if [ "${BOOTFS}" != '-' ] + then + + for i in ${BOOTFS} + do + + zfs get type ${i} > /dev/null + retval=$? + + if [ ${retval} -eq 0 ]; then + got_good_root=1 + REAL_ROOT=${i} + ROOTFSTYPE=zfs + break + fi + done + else + got_good_root=0 + fi + + fi + + if [ ${got_good_root} -ne 1 ]; then + prompt_user "REAL_ROOT" "root block device" + got_good_root=0 + fi + continue + ;; + esac + + if [ "${REAL_ROOT}" = '' ] + then + # No REAL_ROOT determined/specified. Prompt user for root block device. + prompt_user "REAL_ROOT" "root block device" + got_good_root=0 + + # Check for a block device or NFS + elif [ -b "${REAL_ROOT}" ] || is_nfs + then + got_good_root=1 + + else + bad_msg "Block device ${REAL_ROOT} is not a valid root device..." + REAL_ROOT="" + got_good_root=0 + fi + done + + + if [ "${got_good_root}" = "1" ] && is_livecd && ! is_nfs; then + # CD already mounted; no further checks necessary + break + fi + if [ "${LOOPTYPE}" = "sgimips" ]; then + # sgimips mounts the livecd root partition directly + # there is no isofs filesystem to worry about + break + fi + + local fstype=$(get_device_fstype "${REAL_ROOT}") + good_msg "Initializing ${REAL_ROOT} if needed, detected fstype: ${fstype}" + fstype_init "${fstype}" + + good_msg "Mounting ${REAL_ROOT} as root..." + + # TODO(lxnay): determine if it's possible to move this crufty thing into fstype_init + if [ "${ROOTFSTYPE}" = 'zfs' ] + then + if [ "$(zfs get -H -o value mountpoint ${REAL_ROOT})" = 'legacy' ] + then + MOUNT_STATE=rw + else + MOUNT_STATE=rw,zfsutil + fi + else + MOUNT_STATE=ro + fi + + # Try to mount the device as ${NEW_ROOT} + if is_nfs; then + findnfsmount + else + # mount ro so fsck doesn't barf later + if [ "${REAL_ROOTFLAGS}" = '' ]; then + good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE}" + mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT} + else + good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS}" + mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT} + fi + fi + + # If mount is successful break out of the loop + # else not a good root and start over. + if [ "$?" = '0' ] + then + # now that the root filesystem is mounted, before + # checking the validity of ${NEW_ROOT} and ${REAL_INIT}, + # ensure that ${NEW_ROOT}/etc/initramfs.mounts entries + # are mounted. + ensure_initramfs_mounts + + # NFS does not need further checks here. + if is_nfs; then + break + fi + + if [ ! -d "${NEW_ROOT}/dev" ]; then + _msg="The filesystem ${REAL_ROOT}," + _msg="${_msg} mounted at ${NEW_ROOT}" + _msg="${_msg} does not contain /dev" + _msg="${_msg}, init will likely fail..." + bad_msg "${_msg}" + fi + if [ ! -x "${NEW_ROOT}${REAL_INIT}" ]; then + _msg="The filesystem ${REAL_ROOT}," + _msg="${_msg} mounted at ${NEW_ROOT}" + _msg="${_msg} does not contain a valid" + _msg="${_msg} init=${REAL_INIT}" + bad_msg "${_msg}" + fi + break + else + bad_msg "Could not mount specified ROOT, try again" + got_good_root=0 + REAL_ROOT='' + fi + done } # If devtmpfs is mounted, try move it to the new root # If that fails, try to unmount all possible mounts of devtmpfs as # stuff breaks otherwise move_mounts_to_chroot() { - for fs in /run /dev /sys /proc; do - if grep -qs "$fs" /proc/mounts; then - local chroot_dir="${CHROOT}${fs}" - mkdir -p "${chroot_dir}" - if ! mount --move $fs "${chroot_dir}" - then - umount $fs || \ - bad_msg "Failed to move and umount $fs!" - fi - fi - done + for fs in /run /dev /sys /proc; do + if grep -qs "$fs" /proc/mounts; then + local chroot_dir="${CHROOT}${fs}" + mkdir -p "${chroot_dir}" + if ! mount --move $fs "${chroot_dir}" + then + umount $fs || \ + bad_msg "Failed to move and umount $fs!" + fi + fi + done } diff --git a/defaults/linuxrc b/defaults/linuxrc old mode 100644 new mode 100755 index 862f4ec..34585b0 --- a/defaults/linuxrc +++ b/defaults/linuxrc @@ -7,10 +7,10 @@ exec >${CONSOLE} <${CONSOLE} 2>&1 if [ "$$" != "1" ]; then - echo "/linuxrc has to be run as the init process as the one" - echo "with a PID of 1. Try adding init=/linuxrc to the" - echo "kernel command line or running "exec /linuxrc"." - exit 1 + echo "/linuxrc has to be run as the init process as the one" + echo "with a PID of 1. Try adding init=/linuxrc to the" + echo "kernel command line or running "exec /linuxrc"." + exit 1 fi mount -t proc -o noexec,nosuid,nodev proc /proc >/dev/null 2>&1 @@ -21,7 +21,7 @@ mount -t tmpfs none /dev/shm 2>&1 /bin/busybox --install -s if [ "$0" = "/init" ]; then - rm -f /linuxrc + rm -f /linuxrc fi CMDLINE=$(cat /proc/cmdline) @@ -36,207 +36,207 @@ QUIET="" mkdir -p /etc/cmdline /etc/modprobe.d for x in ${CMDLINE}; do - case "${x}" in - real_root=*) - REAL_ROOT=${x#*=} - ;; - root=*) - FAKE_ROOT=${x#*=} - ;; - subdir=*) - SUBDIR=${x#*=} - ;; - real_init=*) - REAL_INIT=${x#*=} - ;; - init=*) - FAKE_INIT=${x#*=} - ;; - init_opts=*) - INIT_OPTS=${x#*=} - ;; - cdroot) - CDROOT=1 - ;; - cdroot=*) - CDROOT=1 - CDROOT_DEV=${x#*=} - ;; - cdroot_type=*) - CDROOT_TYPE=${x#*=} - ;; - cdroot_marker=*) - CDROOT_MARKER=${x#*=} - ;; - loop=*) - LOOP=${x#*=} - ;; - looptype=*) - LOOPTYPE=${x#*=} - ;; - isoboot=*) - ISOBOOT=${x#*=} - ;; - domdev) - USE_MDEV=1 - ;; - dolvm) - USE_LVM_NORMAL=1 - ;; - domdadm) - USE_MDADM=1 - ;; - dodmraid) - USE_DMRAID_NORMAL=1 - ;; - dodmraid=*) - DMRAID_OPTS=${x#*=} - USE_DMRAID_NORMAL=1 - ;; - domultipath) - good_msg "Booting with multipath activated." - USE_MULTIPATH_NORMAL=1 - ;; - dozfs*) - USE_ZFS=1 - - if [ "${x#*=}" = "force" ]; then - ZPOOL_FORCE=-f - fi - ;; - quiet) - QUIET=1 - ;; - debug) - DEBUG="yes" - ;; - scandelay=*) - SDELAY=${x#*=} - ;; - scandelay) - SDELAY=3 - ;; - doload=*) - MDOLIST=${x#*=} - MDOLIST=$(echo ${MDOLIST} | sed -e "s/,/ /g") - ;; - nodetect) - NODETECT=1 - ;; - noload=*) - MLIST=${x#*=} - MLIST="$(echo ${MLIST} | sed -e "s/,/ /g")" - export MLIST - ;; - CONSOLE=*|console=*) - CONSOLE=${x#*=} - CONSOLE=$(basename ${CONSOLE}) - ;; - splash) - PLYMOUTH=1 - ;; - splash=*) - FBSPLASH=1 - ;; - lvmraid=*) - RAID_DEVICES="${x#*=}" - RAID_DEVICES="$(echo ${RAID_DEVICES} | sed -e "s/,/ /g")" - USE_LVM_NORMAL=1 - ;; - part=*) - MDPART=${x#*=} - ;; - part|partitionable) - MDPART=1 - ;; - ip=*) - IP=${x#*=} - ;; - nfsroot=*) - NFSROOT=${x#*=} - ;; - - iscsi_initiatorname=*) - ISCSI_INITIATORNAME=${x#*=} - ;; - iscsi_target=*) - ISCSI_TARGET=${x#*=} - ;; - iscsi_tgpt=*) - ISCSI_TGPT=${x#*=} - ;; - iscsi_address=*) - ISCSI_ADDRESS=${x#*=} - ;; - iscsi_port=*) - ISCSI_PORT=${x#*=} - ;; - iscsi_username=*) - ISCSI_USERNAME=${x#*=} - ;; - iscsi_password=*) - ISCSI_PASSWORD=${x#*=} - ;; - iscsi_username_in=*) - ISCSI_USERNAME_IN=${x#*=} - ;; - iscsi_password_in=*) - ISCSI_PASSWORD_IN=${x#*=} - ;; - iscsi_debug=*) - ISCSI_DEBUG=${x#*=} - ;; - iscsi_noibft) - ISCSI_NOIBFT=1 - ;; - - crypt_root=*) - CRYPT_ROOT=${x#*=} - ;; - crypt_swap=*) - CRYPT_SWAP=${x#*=} - ;; - root_key=*) - CRYPT_ROOT_KEY=${x#*=} - ;; - root_keydev=*) - CRYPT_ROOT_KEYDEV=${x#*=} - ;; - root_trim=*) - CRYPT_ROOT_TRIM=${x#*=} - ;; - - swap_key=*) - CRYPT_SWAP_KEY=${x#*=} - ;; - swap_keydev=*) - CRYPT_SWAP_KEYDEV=${x#*=} - ;; - real_resume=*|resume=*) - REAL_RESUME=${x#*=} - ;; - noresume) - NORESUME=1 - ;; - crypt_silent) - CRYPT_SILENT=1 - ;; - real_rootflags=*) - REAL_ROOTFLAGS=${x#*=} - ;; - rootflags=*) - FAKE_ROOTFLAGS=${x#*=} - ;; - rootfstype=*) - ROOTFSTYPE=${x#*=} - ;; - keymap=*) - keymap=${x#*=} - ;; - aufs) - USE_AUFS=1 - ;; - esac + case "${x}" in + real_root=*) + REAL_ROOT=${x#*=} + ;; + root=*) + FAKE_ROOT=${x#*=} + ;; + subdir=*) + SUBDIR=${x#*=} + ;; + real_init=*) + REAL_INIT=${x#*=} + ;; + init=*) + FAKE_INIT=${x#*=} + ;; + init_opts=*) + INIT_OPTS=${x#*=} + ;; + cdroot) + CDROOT=1 + ;; + cdroot=*) + CDROOT=1 + CDROOT_DEV=${x#*=} + ;; + cdroot_type=*) + CDROOT_TYPE=${x#*=} + ;; + cdroot_marker=*) + CDROOT_MARKER=${x#*=} + ;; + loop=*) + LOOP=${x#*=} + ;; + looptype=*) + LOOPTYPE=${x#*=} + ;; + isoboot=*) + ISOBOOT=${x#*=} + ;; + domdev) + USE_MDEV=1 + ;; + dolvm) + USE_LVM_NORMAL=1 + ;; + domdadm) + USE_MDADM=1 + ;; + dodmraid) + USE_DMRAID_NORMAL=1 + ;; + dodmraid=*) + DMRAID_OPTS=${x#*=} + USE_DMRAID_NORMAL=1 + ;; + domultipath) + good_msg "Booting with multipath activated." + USE_MULTIPATH_NORMAL=1 + ;; + dozfs*) + USE_ZFS=1 + + if [ "${x#*=}" = "force" ]; then + ZPOOL_FORCE=-f + fi + ;; + quiet) + QUIET=1 + ;; + debug) + DEBUG="yes" + ;; + scandelay=*) + SDELAY=${x#*=} + ;; + scandelay) + SDELAY=3 + ;; + doload=*) + MDOLIST=${x#*=} + MDOLIST=$(echo ${MDOLIST} | sed -e "s/,/ /g") + ;; + nodetect) + NODETECT=1 + ;; + noload=*) + MLIST=${x#*=} + MLIST="$(echo ${MLIST} | sed -e "s/,/ /g")" + export MLIST + ;; + CONSOLE=*|console=*) + CONSOLE=${x#*=} + CONSOLE=$(basename ${CONSOLE}) + ;; + splash) + PLYMOUTH=1 + ;; + splash=*) + FBSPLASH=1 + ;; + lvmraid=*) + RAID_DEVICES="${x#*=}" + RAID_DEVICES="$(echo ${RAID_DEVICES} | sed -e "s/,/ /g")" + USE_LVM_NORMAL=1 + ;; + part=*) + MDPART=${x#*=} + ;; + part|partitionable) + MDPART=1 + ;; + ip=*) + IP=${x#*=} + ;; + nfsroot=*) + NFSROOT=${x#*=} + ;; + + iscsi_initiatorname=*) + ISCSI_INITIATORNAME=${x#*=} + ;; + iscsi_target=*) + ISCSI_TARGET=${x#*=} + ;; + iscsi_tgpt=*) + ISCSI_TGPT=${x#*=} + ;; + iscsi_address=*) + ISCSI_ADDRESS=${x#*=} + ;; + iscsi_port=*) + ISCSI_PORT=${x#*=} + ;; + iscsi_username=*) + ISCSI_USERNAME=${x#*=} + ;; + iscsi_password=*) + ISCSI_PASSWORD=${x#*=} + ;; + iscsi_username_in=*) + ISCSI_USERNAME_IN=${x#*=} + ;; + iscsi_password_in=*) + ISCSI_PASSWORD_IN=${x#*=} + ;; + iscsi_debug=*) + ISCSI_DEBUG=${x#*=} + ;; + iscsi_noibft) + ISCSI_NOIBFT=1 + ;; + + crypt_root=*) + CRYPT_ROOT=${x#*=} + ;; + crypt_swap=*) + CRYPT_SWAP=${x#*=} + ;; + root_key=*) + CRYPT_ROOT_KEY=${x#*=} + ;; + root_keydev=*) + CRYPT_ROOT_KEYDEV=${x#*=} + ;; + root_trim=*) + CRYPT_ROOT_TRIM=${x#*=} + ;; + + swap_key=*) + CRYPT_SWAP_KEY=${x#*=} + ;; + swap_keydev=*) + CRYPT_SWAP_KEYDEV=${x#*=} + ;; + real_resume=*|resume=*) + REAL_RESUME=${x#*=} + ;; + noresume) + NORESUME=1 + ;; + crypt_silent) + CRYPT_SILENT=1 + ;; + real_rootflags=*) + REAL_ROOTFLAGS=${x#*=} + ;; + rootflags=*) + FAKE_ROOTFLAGS=${x#*=} + ;; + rootfstype=*) + ROOTFSTYPE=${x#*=} + ;; + keymap=*) + keymap=${x#*=} + ;; + aufs) + USE_AUFS=1 + ;; + esac done quiet_kmsg @@ -305,8 +305,8 @@ splashcmd hasroot "${NEW_ROOT}" cdupdate if [ "${SUBDIR}" != "" ] && [ -e "${CHROOT}/${SUBDIR}" ]; then - good_msg "Entering ${SUBDIR} to boot" - CHROOT="${CHROOT}/${SUBDIR}" + good_msg "Entering ${SUBDIR} to boot" + CHROOT="${CHROOT}/${SUBDIR}" fi verbose_kmsg @@ -323,7 +323,7 @@ move_mounts_to_chroot rundebugshell "before entering switch_root" exec /sbin/switch_root -c "/dev/console" "${CHROOT}" \ - "${REAL_INIT}" "${INIT_OPTS}" + "${REAL_INIT}" "${INIT_OPTS}" # If we get here, something bad has happened splashcmd verbose diff --git a/defaults/udhcpc.scripts b/defaults/udhcpc.scripts index 53aa2cc..023291f 100755 --- a/defaults/udhcpc.scripts +++ b/defaults/udhcpc.scripts @@ -3,35 +3,35 @@ [ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1 case ${1} in - renew|bound) - [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" - [ -n "$subnet" ] && NETMASK="netmask $subnet" - [ -n "$rootpath" ] && echo "$rootpath" > /rootpath - [ -n "$hostname" ] && hostname ${hostname} + renew|bound) + [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" + [ -n "$subnet" ] && NETMASK="netmask $subnet" + [ -n "$rootpath" ] && echo "$rootpath" > /rootpath + [ -n "$hostname" ] && hostname ${hostname} - busybox ifconfig $interface $ip $BROADCAST $NETMASK - if [ -n "${router}" ] - then - while route del default gw 0.0.0.0 dev $interface; do - : - done + busybox ifconfig $interface $ip $BROADCAST $NETMASK + if [ -n "${router}" ] + then + while route del default gw 0.0.0.0 dev $interface; do + : + done - for i in ${router} - do - busybox route add default gw ${i} - done - fi - [ -n "$domain" ] && echo "domain ${domain}" >> /etc/resolv.conf - if [ -n "${dns}" ] - then - for i in ${dns} - do - echo "nameserver ${i}" >> /etc/resolv.conf - done - fi - ;; - deconfig) - busybox ifconfig $interface 0.0.0.0 - ;; + for i in ${router} + do + busybox route add default gw ${i} + done + fi + [ -n "$domain" ] && echo "domain ${domain}" >> /etc/resolv.conf + if [ -n "${dns}" ] + then + for i in ${dns} + do + echo "nameserver ${i}" >> /etc/resolv.conf + done + fi + ;; + deconfig) + busybox ifconfig $interface 0.0.0.0 + ;; esac diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt index 78bba08..5fbfff0 100644 --- a/doc/genkernel.8.txt +++ b/doc/genkernel.8.txt @@ -154,8 +154,8 @@ KERNEL COMPILATION kernel and modules have been compiled. *--*[*no-*]*static*:: - Builds, or does not build a monolithic kernel without any modules on any - initial ramdisks. + Builds, or does not build a monolithic kernel without any modules on any + initial ramdisks. KERNEL LOCATIONS @@ -256,8 +256,8 @@ INITIALIZATION the system. *--*[*no-*]*lvm*:: - Adds or skips in LVM support from static binaries if they exist on the - system, or compile static LVM binaries if static ones do not exist. + Adds or skips in LVM support from static binaries if they exist on the + system, or compile static LVM binaries if static ones do not exist. *--*[*no-*]*mdadm*:: Includes or excludes mdadm/mdmon support. @@ -296,15 +296,15 @@ INITIALIZATION Specifies a user created busybox config. *--genzimage*:: - Make and install kernelz image from 'arch/powerpc/boot/zImage.initrd'. + Make and install kernelz image from 'arch/powerpc/boot/zImage.initrd'. *--*[*no-*]*luks*:: - Includes or excludes Luks support from static binaries if they exist on - the system. + Includes or excludes Luks support from static binaries if they exist on + the system. *--*[*no-*]*gpg*:: - Includes or excludes support for GnuPG 1.x, the portable standalone branch - of GnuPG. A key can be made from + Includes or excludes support for GnuPG 1.x, the portable standalone branch + of GnuPG. A key can be made from `gpg --symmetric -o /path/to/LUKS-key.gpg /path/to/LUKS-key` . After that, re-point the *root_key* argument to the new .gpg file. @@ -331,7 +331,7 @@ INTERNALS Sets genkernel's temporary working directory to . *--*[*no-*]*postclear*:: - Clears or skips clearing all tmp files and caches after genkernel has run. + Clears or skips clearing all tmp files and caches after genkernel has run. OUTPUT SETTINGS @@ -372,16 +372,16 @@ OUTPUT SETTINGS For multiple files, separate the filenames with a comma. *--*[*no-*]*integrated-initramfs*:: - Builds or does not build the generated initramfs into the kernel instead - of keeping it as a separate file. + Builds or does not build the generated initramfs into the kernel instead + of keeping it as a separate file. *--*[*no-*]*compress-initramfs*, *--*[*no-*]*compress-initrd*:: - Compresses or does not compress the generated initramfs. + Compresses or does not compress the generated initramfs. *--compress-initramfs-type*=:: - Compression type for initramfs (best, xz, lzma, bzip2, gzip, lzop). - "Best" causes selection of the best available algorithm that is selected - in your kernel configuration. + Compression type for initramfs (best, xz, lzma, bzip2, gzip, lzop). + "Best" causes selection of the best available algorithm that is selected + in your kernel configuration. RAMDISK OPTIONS @@ -526,8 +526,8 @@ which the ramdisk scripts would recognize. *part*[=<0,1>]:: *partitionable*:: - Enable/Disable partitionable RAIDs (metadata 0.x) during auto-run. - Standalone *part* and *partitionable* keywords for kernel compatability. + Enable/Disable partitionable RAIDs (metadata 0.x) during auto-run. + Standalone *part* and *partitionable* keywords for kernel compatability. *iscsi_initiatorname*=<...>:: *iscsi_target*=<...>:: diff --git a/gen_arch.sh b/gen_arch.sh index 866a40f..74290fb 100755 --- a/gen_arch.sh +++ b/gen_arch.sh @@ -2,93 +2,93 @@ # $Id$ get_official_arch() { - if [ "${CMD_ARCHOVERRIDE}" != '' ] - then - ARCH=${CMD_ARCHOVERRIDE} - else - if [ "${ARCH_OVERRIDE}" != '' ] - then - ARCH=${ARCH_OVERRIDE} - else - ARCH=`uname -m` - case "${ARCH}" in - i?86) - ARCH="x86" - ;; - mips|mips64) - ARCH="mips" - ;; - arm*) - ARCH=arm - ;; - *) - ;; - esac - fi - fi + if [ "${CMD_ARCHOVERRIDE}" != '' ] + then + ARCH=${CMD_ARCHOVERRIDE} + else + if [ "${ARCH_OVERRIDE}" != '' ] + then + ARCH=${ARCH_OVERRIDE} + else + ARCH=`uname -m` + case "${ARCH}" in + i?86) + ARCH="x86" + ;; + mips|mips64) + ARCH="mips" + ;; + arm*) + ARCH=arm + ;; + *) + ;; + esac + fi + fi - if [ "${CMD_UTILS_ARCH}" != '' ] - then - UTILS_ARCH=${CMD_UTILS_ARCH} - else - if [ "${UTILS_ARCH}" != '' ] - then - UTILS_ARCH=${UTILS_ARCH} - fi - fi + if [ "${CMD_UTILS_ARCH}" != '' ] + then + UTILS_ARCH=${CMD_UTILS_ARCH} + else + if [ "${UTILS_ARCH}" != '' ] + then + UTILS_ARCH=${UTILS_ARCH} + fi + fi - # sparc64 klibc is b0rked, so we force to 32 - if [ "${ARCH}" = 'sparc64' ] - then - UTILS_ARCH='sparc' - fi + # sparc64 klibc is b0rked, so we force to 32 + if [ "${ARCH}" = 'sparc64' ] + then + UTILS_ARCH='sparc' + fi - ARCH_CONFIG="${GK_SHARE}/arch/${ARCH}/config.sh" - [ -f "${ARCH_CONFIG}" ] || gen_die "${ARCH} not yet supported by genkernel. Please add the arch-specific config file, ${ARCH_CONFIG}" + ARCH_CONFIG="${GK_SHARE}/arch/${ARCH}/config.sh" + [ -f "${ARCH_CONFIG}" ] || gen_die "${ARCH} not yet supported by genkernel. Please add the arch-specific config file, ${ARCH_CONFIG}" } set_kernel_arch() { - KERNEL_ARCH=${ARCH} - case ${ARCH} in - ppc|ppc64) - if [ "${VER}" -ge "3" ] - then - KERNEL_ARCH=powerpc - elif [ "${VER}" -eq "2" -a "${PAT}" -ge "6" ] - then - if [ "${PAT}" -eq "6" -a "${SUB}" -ge "16" ] || [ "${PAT}" -gt "6" ] - then - KERNEL_ARCH=powerpc - fi - fi - ;; - x86) - if [ "${VER}" -ge "3" ] - then - KERNEL_ARCH=x86 - elif [ "${VER}" -eq "2" -a "${PAT}" -ge "6" ] || [ "${VER}" -gt "2" ] - then - if [ "${PAT}" -eq "6" -a "${SUB}" -ge "24" ] || [ "${PAT}" -gt "6" ] - then - KERNEL_ARCH=x86 - else - KERNEL_ARCH=i386 - fi - fi - ;; - x86_64) - if [ "${VER}" -ge "3" ] - then - KERNEL_ARCH=x86 - elif [ "${VER}" -eq "2" -a "${PAT}" -ge "6" ] || [ "${VER}" -gt "2" ] - then - if [ "${PAT}" -eq "6" -a "${SUB}" -ge "24" ] || [ "${PAT}" -gt "6" ] - then - KERNEL_ARCH=x86 - fi - fi - ;; - esac - export KERNEL_ARCH - print_info 2 "KERNEL_ARCH=${KERNEL_ARCH}" + KERNEL_ARCH=${ARCH} + case ${ARCH} in + ppc|ppc64) + if [ "${VER}" -ge "3" ] + then + KERNEL_ARCH=powerpc + elif [ "${VER}" -eq "2" -a "${PAT}" -ge "6" ] + then + if [ "${PAT}" -eq "6" -a "${SUB}" -ge "16" ] || [ "${PAT}" -gt "6" ] + then + KERNEL_ARCH=powerpc + fi + fi + ;; + x86) + if [ "${VER}" -ge "3" ] + then + KERNEL_ARCH=x86 + elif [ "${VER}" -eq "2" -a "${PAT}" -ge "6" ] || [ "${VER}" -gt "2" ] + then + if [ "${PAT}" -eq "6" -a "${SUB}" -ge "24" ] || [ "${PAT}" -gt "6" ] + then + KERNEL_ARCH=x86 + else + KERNEL_ARCH=i386 + fi + fi + ;; + x86_64) + if [ "${VER}" -ge "3" ] + then + KERNEL_ARCH=x86 + elif [ "${VER}" -eq "2" -a "${PAT}" -ge "6" ] || [ "${VER}" -gt "2" ] + then + if [ "${PAT}" -eq "6" -a "${SUB}" -ge "24" ] || [ "${PAT}" -gt "6" ] + then + KERNEL_ARCH=x86 + fi + fi + ;; + esac + export KERNEL_ARCH + print_info 2 "KERNEL_ARCH=${KERNEL_ARCH}" } diff --git a/gen_bootloader.sh b/gen_bootloader.sh index 5848bd2..699abc9 100755 --- a/gen_bootloader.sh +++ b/gen_bootloader.sh @@ -1,177 +1,177 @@ # $Id$ set_bootloader() { - case "${BOOTLOADER}" in - grub) - set_bootloader_grub - ;; - grub2) - set_bootloader_grub2 - ;; - *) - print_warning "Bootloader ${BOOTLOADER} is not currently supported" - ;; - esac + case "${BOOTLOADER}" in + grub) + set_bootloader_grub + ;; + grub2) + set_bootloader_grub2 + ;; + *) + print_warning "Bootloader ${BOOTLOADER} is not currently supported" + ;; + esac } set_bootloader_read_fstab() { - local ROOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "/" ) { print $1; exit }' /etc/fstab) - local BOOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "'${BOOTDIR}'") { print $1; exit }' /etc/fstab) + local ROOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "/" ) { print $1; exit }' /etc/fstab) + local 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 / - [ -z "${BOOTFS}" ] && BOOTFS=${ROOTFS} + # If ${BOOTDIR} is not defined in /etc/fstab, it must be the same as / + [ -z "${BOOTFS}" ] && BOOTFS=${ROOTFS} - echo "${ROOTFS} ${BOOTFS}" + echo "${ROOTFS} ${BOOTFS}" } set_bootloader_grub_read_device_map() { - # Read GRUB device map - [ ! -d ${TEMP} ] && mkdir ${TEMP} - echo "quit" | grub --batch --device-map=${TEMP}/grub.map &>/dev/null - echo "${TEMP}/grub.map" + # Read GRUB device map + [ ! -d ${TEMP} ] && mkdir ${TEMP} + echo "quit" | grub --batch --device-map=${TEMP}/grub.map &>/dev/null + echo "${TEMP}/grub.map" } set_bootloader_grub2() { - local GRUB_CONF - for candidate in \ - "${BOOTDIR}/grub2/grub.cfg" \ - "${BOOTDIR}/grub/grub.cfg" \ - ; do - if [[ -e "${candidate}" ]]; then - GRUB_CONF=${candidate} - break - fi - done - - if [[ -z "${GRUB_CONF}" ]]; then - print_error 1 "Error! Grub2 configuration file does not exist, please ensure grub2 is correctly setup first." - return 0 - fi - - print_info 1 "You can customize Grub2 parameters in /etc/default/grub." - print_info 1 "Running grub2-mkconfig to create ${GRUB_CONF}..." - grub2-mkconfig -o "${GRUB_CONF}" - [ "${BUILD_RAMDISK}" -ne 0 ] && sed -i 's/ro single/ro debug/' "${GRUB_CONF}" + local GRUB_CONF + for candidate in \ + "${BOOTDIR}/grub2/grub.cfg" \ + "${BOOTDIR}/grub/grub.cfg" \ + ; do + if [[ -e "${candidate}" ]]; then + GRUB_CONF=${candidate} + break + fi + done + + if [[ -z "${GRUB_CONF}" ]]; then + print_error 1 "Error! Grub2 configuration file does not exist, please ensure grub2 is correctly setup first." + return 0 + fi + + print_info 1 "You can customize Grub2 parameters in /etc/default/grub." + print_info 1 "Running grub2-mkconfig to create ${GRUB_CONF}..." + grub2-mkconfig -o "${GRUB_CONF}" + [ "${BUILD_RAMDISK}" -ne 0 ] && sed -i 's/ro single/ro debug/' "${GRUB_CONF}" } set_bootloader_grub() { - local GRUB_CONF="${BOOTDIR}/grub/grub.conf" - - print_info 1 "Adding kernel to ${GRUB_CONF}..." - - if [ ! -e ${GRUB_CONF} ] - then - local GRUB_BOOTFS - if [ -n "${BOOTFS}" ] - then - GRUB_BOOTFS=$BOOTFS - else - GRUB_BOOTFS=$(set_bootloader_read_fstab | cut -d' ' -f2) - fi - - # 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#') - 1)) - - if [ -n "${GRUB_BOOT_DISK}" -a -n "${GRUB_BOOT_PARTITION}" ] - then - - # Create grub configuration directory and file if it doesn't exist. - [ ! -d `dirname ${GRUB_CONF}` ] && mkdir -p `dirname ${GRUB_CONF}` - - touch ${GRUB_CONF} - echo 'default 0' >> ${GRUB_CONF} - echo 'timeout 5' >> ${GRUB_CONF} - echo "root (${GRUB_BOOT_DISK},${GRUB_BOOT_PARTITION})" >> ${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 "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=${GRUB_ROOTFS}" >> ${GRUB_CONF} - if [ "${BUILD_INITRD}" = '1' ] - then - if [ "${PAT}" -gt '4' ] - then - echo -e "\tinitrd /initramfs-${KNAME}-${ARCH}-${KV}" >> ${GRUB_CONF} - fi - 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 - # The grub.conf already exists, so let's try to duplicate the default entry - if set_bootloader_grub_check_for_existing_entry "${GRUB_CONF}"; then - print_warning 1 "An entry was already found for a kernel/initramfs with this name...skipping update" - return 0 - fi - - set_bootloader_grub_duplicate_default "${GRUB_CONF}" - fi + local GRUB_CONF="${BOOTDIR}/grub/grub.conf" + + print_info 1 "Adding kernel to ${GRUB_CONF}..." + + if [ ! -e ${GRUB_CONF} ] + then + local GRUB_BOOTFS + if [ -n "${BOOTFS}" ] + then + GRUB_BOOTFS=$BOOTFS + else + GRUB_BOOTFS=$(set_bootloader_read_fstab | cut -d' ' -f2) + fi + + # 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#') - 1)) + + if [ -n "${GRUB_BOOT_DISK}" -a -n "${GRUB_BOOT_PARTITION}" ] + then + + # Create grub configuration directory and file if it doesn't exist. + [ ! -d `dirname ${GRUB_CONF}` ] && mkdir -p `dirname ${GRUB_CONF}` + + touch ${GRUB_CONF} + echo 'default 0' >> ${GRUB_CONF} + echo 'timeout 5' >> ${GRUB_CONF} + echo "root (${GRUB_BOOT_DISK},${GRUB_BOOT_PARTITION})" >> ${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 "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=${GRUB_ROOTFS}" >> ${GRUB_CONF} + if [ "${BUILD_INITRD}" = '1' ] + then + if [ "${PAT}" -gt '4' ] + then + echo -e "\tinitrd /initramfs-${KNAME}-${ARCH}-${KV}" >> ${GRUB_CONF} + fi + 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 + # The grub.conf already exists, so let's try to duplicate the default entry + if set_bootloader_grub_check_for_existing_entry "${GRUB_CONF}"; then + print_warning 1 "An entry was already found for a kernel/initramfs with this name...skipping update" + return 0 + fi + + set_bootloader_grub_duplicate_default "${GRUB_CONF}" + fi } set_bootloader_grub_duplicate_default_replace_kernel_initrd() { - sed -r -e "/^[[:space:]]*kernel/s/kernel-[[:alnum:][:punct:]]+/kernel-${KNAME}-${ARCH}-${KV}/" - | - sed -r -e "/^[[:space:]]*initrd/s/init(rd|ramfs)-[[:alnum:][:punct:]]+/init\1-${KNAME}-${ARCH}-${KV}/" + sed -r -e "/^[[:space:]]*kernel/s/kernel-[[:alnum:][:punct:]]+/kernel-${KNAME}-${ARCH}-${KV}/" - | + sed -r -e "/^[[:space:]]*initrd/s/init(rd|ramfs)-[[:alnum:][:punct:]]+/init\1-${KNAME}-${ARCH}-${KV}/" } set_bootloader_grub_check_for_existing_entry() { - local GRUB_CONF=$1 - if grep -q "^[[:space:]]*kernel[[:space:]=]*.*/kernel-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}" && - grep -q "^[[:space:]]*initrd[[:space:]=]*.*/initramfs-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}" - then - return 0 - fi - return 1 + local GRUB_CONF=$1 + if grep -q "^[[:space:]]*kernel[[:space:]=]*.*/kernel-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}" && + grep -q "^[[:space:]]*initrd[[:space:]=]*.*/initramfs-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}" + then + return 0 + fi + return 1 } set_bootloader_grub_duplicate_default() { - local GRUB_CONF=$1 - local GRUB_CONF_TMP="${GRUB_CONF}.tmp" - - line_count=$(wc -l < "${GRUB_CONF}") - line_nums="$(grep -n "^title" "${GRUB_CONF}" | cut -d: -f1)" - if [ -z "${line_nums}" ]; then - print_error 1 "No current 'title' entries found in your grub.conf...skipping update" - return 0 - fi - line_nums="${line_nums} $((${line_count}+1))" - - # Find default entry - default=$(sed -rn '/^[[:space:]]*default[[:space:]=]/s/^.*default[[:space:]=]+([[:alnum:]]+).*$/\1/p' "${GRUB_CONF}") + local GRUB_CONF=$1 + local GRUB_CONF_TMP="${GRUB_CONF}.tmp" + + line_count=$(wc -l < "${GRUB_CONF}") + line_nums="$(grep -n "^title" "${GRUB_CONF}" | cut -d: -f1)" + if [ -z "${line_nums}" ]; then + print_error 1 "No current 'title' entries found in your grub.conf...skipping update" + return 0 + fi + line_nums="${line_nums} $((${line_count}+1))" + + # Find default entry + default=$(sed -rn '/^[[:space:]]*default[[:space:]=]/s/^.*default[[:space:]=]+([[:alnum:]]+).*$/\1/p' "${GRUB_CONF}") if [ -z "${default}" ]; then - print_warning 1 "No default entry found...assuming 0" - default=0 - fi - if ! echo ${default} | grep -q '^[0-9]\+$'; then - print_error 1 "We don't support non-numeric (such as 'saved') default values...skipping update" - return 0 - fi - - # Grub defaults are 0 based, cut is 1 based - # Figure out where the default entry lives - startstop=$(echo ${line_nums} | cut -d" " -f$((${default}+1))-$((${default}+2))) - startline=$(echo ${startstop} | cut -d" " -f1) - stopline=$(echo ${startstop} | cut -d" " -f2) - - # Write out the bits before the default entry - sed -n 1,$((${startline}-1))p "${GRUB_CONF}" > "${GRUB_CONF_TMP}" - - # Put in our title - echo "title=Gentoo Linux (${KV})" >> "${GRUB_CONF_TMP}" - - # Pass the default entry (minus the title) through to the replacement function and pipe the output to GRUB_CONF_TMP - sed -n $((${startline}+1)),$((${stopline}-1))p "${GRUB_CONF}" | set_bootloader_grub_duplicate_default_replace_kernel_initrd >> "${GRUB_CONF_TMP}" - - # Finish off with everything including the previous default entry - sed -n ${startline},${line_count}p "${GRUB_CONF}" >> "${GRUB_CONF_TMP}" - - cp "${GRUB_CONF}" "${GRUB_CONF}.bak" - cp "${GRUB_CONF_TMP}" "${GRUB_CONF}" - rm "${GRUB_CONF_TMP}" + print_warning 1 "No default entry found...assuming 0" + default=0 + fi + if ! echo ${default} | grep -q '^[0-9]\+$'; then + print_error 1 "We don't support non-numeric (such as 'saved') default values...skipping update" + return 0 + fi + + # Grub defaults are 0 based, cut is 1 based + # Figure out where the default entry lives + startstop=$(echo ${line_nums} | cut -d" " -f$((${default}+1))-$((${default}+2))) + startline=$(echo ${startstop} | cut -d" " -f1) + stopline=$(echo ${startstop} | cut -d" " -f2) + + # Write out the bits before the default entry + sed -n 1,$((${startline}-1))p "${GRUB_CONF}" > "${GRUB_CONF_TMP}" + + # Put in our title + echo "title=Gentoo Linux (${KV})" >> "${GRUB_CONF_TMP}" + + # Pass the default entry (minus the title) through to the replacement function and pipe the output to GRUB_CONF_TMP + sed -n $((${startline}+1)),$((${stopline}-1))p "${GRUB_CONF}" | set_bootloader_grub_duplicate_default_replace_kernel_initrd >> "${GRUB_CONF_TMP}" + + # Finish off with everything including the previous default entry + sed -n ${startline},${line_count}p "${GRUB_CONF}" >> "${GRUB_CONF_TMP}" + + cp "${GRUB_CONF}" "${GRUB_CONF}.bak" + cp "${GRUB_CONF_TMP}" "${GRUB_CONF}" + rm "${GRUB_CONF_TMP}" } diff --git a/gen_cmdline.sh b/gen_cmdline.sh index 1a951df..c0c0d25 100755 --- a/gen_cmdline.sh +++ b/gen_cmdline.sh @@ -8,615 +8,615 @@ longusage() { echo " genkernel [options] action" echo echo "Available Actions: " - echo " all Build all steps" - echo " bzImage Build only the kernel" - echo " initramfs Build only the ramdisk/initramfs" - echo " kernel Build only the kernel and modules" - echo " ramdisk Build only the ramdisk/initramfs" + echo " all Build all steps" + echo " bzImage Build only the kernel" + echo " initramfs Build only the ramdisk/initramfs" + echo " kernel Build only the kernel and modules" + echo " ramdisk Build only the ramdisk/initramfs" echo echo "Available Options: " echo " Configuration settings" - echo " --config= genkernel configuration file to use" + echo " --config= genkernel configuration file to use" echo " Debug settings" - echo " --loglevel=<0-5> Debug Verbosity Level" - echo " --logfile= Output file for debug info" - echo " --color Output debug in color" - echo " --no-color Do not output debug in color" + echo " --loglevel=<0-5> Debug Verbosity Level" + echo " --logfile= Output file for debug info" + echo " --color Output debug in color" + echo " --no-color Do not output debug in color" echo " Kernel Configuration settings" - echo " --menuconfig Run menuconfig after oldconfig" - echo " --no-menuconfig Do not run menuconfig after oldconfig" - echo " --nconfig Run nconfig after oldconfig" - echo " --no-nconfig Do not run nconfig after oldconfig" - echo " --gconfig Run gconfig after oldconfig" - echo " --no-gconfig Don't run gconfig after oldconfig" - echo " --xconfig Run xconfig after oldconfig" - echo " --no-xconfig Don't run xconfig after oldconfig" - echo " --save-config Save the configuration to /etc/kernels" - echo " --no-save-config Don't save the configuration to /etc/kernels" - echo " --virtio Include VirtIO kernel code" + echo " --menuconfig Run menuconfig after oldconfig" + echo " --no-menuconfig Do not run menuconfig after oldconfig" + echo " --nconfig Run nconfig after oldconfig" + echo " --no-nconfig Do not run nconfig after oldconfig" + echo " --gconfig Run gconfig after oldconfig" + echo " --no-gconfig Don't run gconfig after oldconfig" + echo " --xconfig Run xconfig after oldconfig" + echo " --no-xconfig Don't run xconfig after oldconfig" + echo " --save-config Save the configuration to /etc/kernels" + echo " --no-save-config Don't save the configuration to /etc/kernels" + echo " --virtio Include VirtIO kernel code" echo " Kernel Compile settings" - echo " --oldconfig Implies --no-clean and runs a 'make oldconfig'" - echo " --clean Run make clean before compilation" - echo " --no-clean Do not run make clean before compilation" - echo " --mrproper Run make mrproper before compilation" - echo " --no-mrproper Do not run make mrproper before compilation" - echo " --splash Install framebuffer splash support into initramfs" - echo " --no-splash Do not install framebuffer splash" - echo " --plymouth Enable plymouth support (forces --udev)" - echo " --no-plymouth Do not enable plymouth support" - echo " --install Install the kernel after building" - echo " --no-install Do not install the kernel after building" - echo " --symlink Manage symlinks in /boot for installed images" - echo " --no-symlink Do not manage symlinks" - echo " --ramdisk-modules Copy required modules to the ramdisk" - echo " --no-ramdisk-modules Don't copy any modules to the ramdisk" - echo " --all-ramdisk-modules Copy all kernel modules to the ramdisk" - echo " --callback=<...> Run the specified arguments after the" - echo " kernel and modules have been compiled" - echo " --static Build a static (monolithic kernel)." - echo " --no-static Do not build a static (monolithic kernel)." + echo " --oldconfig Implies --no-clean and runs a 'make oldconfig'" + echo " --clean Run make clean before compilation" + echo " --no-clean Do not run make clean before compilation" + echo " --mrproper Run make mrproper before compilation" + echo " --no-mrproper Do not run make mrproper before compilation" + echo " --splash Install framebuffer splash support into initramfs" + echo " --no-splash Do not install framebuffer splash" + echo " --plymouth Enable plymouth support (forces --udev)" + echo " --no-plymouth Do not enable plymouth support" + echo " --install Install the kernel after building" + echo " --no-install Do not install the kernel after building" + echo " --symlink Manage symlinks in /boot for installed images" + echo " --no-symlink Do not manage symlinks" + echo " --ramdisk-modules Copy required modules to the ramdisk" + echo " --no-ramdisk-modules Don't copy any modules to the ramdisk" + echo " --all-ramdisk-modules Copy all kernel modules to the ramdisk" + echo " --callback=<...> Run the specified arguments after the" + echo " kernel and modules have been compiled" + echo " --static Build a static (monolithic kernel)." + echo " --no-static Do not build a static (monolithic kernel)." echo " Kernel settings" - echo " --kerneldir= Location of the kernel sources" - echo " --kernel-config= Kernel configuration file to use for compilation" - echo " --module-prefix= Prefix to kernel module destination, modules" - echo " will be installed in /lib/modules" + echo " --kerneldir= Location of the kernel sources" + echo " --kernel-config= Kernel configuration file to use for compilation" + echo " --module-prefix= Prefix to kernel module destination, modules" + echo " will be installed in /lib/modules" echo " Low-Level Compile settings" - echo " --kernel-cc= Compiler to use for kernel (e.g. distcc)" - echo " --kernel-as= Assembler to use for kernel" - echo " --kernel-ld= Linker to use for kernel" - echo " --kernel-make= GNU Make to use for kernel" - echo " --kernel-target= Override default make target (bzImage)" - echo " --kernel-binary= Override default kernel binary path (arch/foo/boot/bar)" - echo " --kernel-outputdir= Save output files outside the source tree." + echo " --kernel-cc= Compiler to use for kernel (e.g. distcc)" + echo " --kernel-as= Assembler to use for kernel" + echo " --kernel-ld= Linker to use for kernel" + echo " --kernel-make= GNU Make to use for kernel" + echo " --kernel-target= Override default make target (bzImage)" + echo " --kernel-binary= Override default kernel binary path (arch/foo/boot/bar)" + echo " --kernel-outputdir= Save output files outside the source tree." - echo " --utils-cc= Compiler to use for utilities" - echo " --utils-as= Assembler to use for utils" - echo " --utils-ld= Linker to use for utils" - echo " --utils-make= GNU Make to use for utils" - echo " --utils-arch= Force to arch for utils only instead of" - echo " autodetect." - echo " --makeopts= Make options such as -j2, etc..." - echo " --mountboot Mount BOOTDIR automatically if mountable" - echo " --no-mountboot Don't mount BOOTDIR automatically" - echo " --bootdir= Set the location of the boot-directory, default is /boot" - echo " --modprobedir= Set the location of the modprobe.d-directory, default is /etc/modprobe.d" + echo " --utils-cc= Compiler to use for utilities" + echo " --utils-as= Assembler to use for utils" + echo " --utils-ld= Linker to use for utils" + echo " --utils-make= GNU Make to use for utils" + echo " --utils-arch= Force to arch for utils only instead of" + echo " autodetect." + echo " --makeopts= Make options such as -j2, etc..." + echo " --mountboot Mount BOOTDIR automatically if mountable" + echo " --no-mountboot Don't mount BOOTDIR automatically" + echo " --bootdir= Set the location of the boot-directory, default is /boot" + echo " --modprobedir= Set the location of the modprobe.d-directory, default is /etc/modprobe.d" echo " Initialization" - echo " --splash= Enable framebuffer splash using " - echo " --splash-res= Select splash theme resolutions to install" - echo " --splash= Enable framebuffer splash using " - echo " --splash-res= Select splash theme resolutions to install" - echo " --plymouth-theme= Embed the given plymouth theme" - echo " --do-keymap-auto Forces keymap selection at boot" - echo " --keymap Enables keymap selection support" - echo " --no-keymap Disables keymap selection support" - echo " --udev Include udev and use it instead of mdev" - echo " --no-udev Exclude udev and use it instead of mdev" - echo " --lvm Include LVM support" - echo " --no-lvm Exclude LVM support" - echo " --mdadm Include MDADM/MDMON support" - echo " --no-mdadm Exclude MDADM/MDMON support" - echo " --mdadm-config= Use file as mdadm.conf in initramfs" - echo " --dmraid Include DMRAID support" - echo " --no-dmraid Exclude DMRAID support" - echo " --e2fsprogs Include e2fsprogs" - echo " --no-e2fsprogs Exclude e2fsprogs" - echo " --zfs Include ZFS support" - echo " --no-zfs Exclude ZFS support" - echo " --btrfs Include BTRFS support" - echo " --no-btrfs Exclude BTRFS support" - echo " --multipath Include Multipath support" - echo " --no-multipath Exclude Multipath support" - echo " --iscsi Include iSCSI support" - echo " --no-iscsi Exclude iSCSI support" - echo " --bootloader=grub Add new kernel to GRUB configuration" - echo " --linuxrc= Specifies a user created linuxrc" - echo " --busybox-config= Specifies a user created busybox config" - echo " --genzimage Make and install kernelz image (PowerPC)" - echo " --luks Include LUKS support" - echo " --> 'emerge cryptsetup-luks' with USE=-dynamic" - echo " --no-luks Exclude LUKS support" - echo " --gpg Include GPG-armored LUKS key support" - echo " --no-gpg Exclude GPG-armored LUKS key support" - echo " --busybox Include busybox" - echo " --no-busybox Exclude busybox" - echo " --netboot Create a self-contained env in the initramfs" - echo " --no-netboot Exclude --netboot env" - echo " --real-root= Specify a default for real_root=" + echo " --splash= Enable framebuffer splash using " + echo " --splash-res= Select splash theme resolutions to install" + echo " --splash= Enable framebuffer splash using " + echo " --splash-res= Select splash theme resolutions to install" + echo " --plymouth-theme= Embed the given plymouth theme" + echo " --do-keymap-auto Forces keymap selection at boot" + echo " --keymap Enables keymap selection support" + echo " --no-keymap Disables keymap selection support" + echo " --udev Include udev and use it instead of mdev" + echo " --no-udev Exclude udev and use it instead of mdev" + echo " --lvm Include LVM support" + echo " --no-lvm Exclude LVM support" + echo " --mdadm Include MDADM/MDMON support" + echo " --no-mdadm Exclude MDADM/MDMON support" + echo " --mdadm-config= Use file as mdadm.conf in initramfs" + echo " --dmraid Include DMRAID support" + echo " --no-dmraid Exclude DMRAID support" + echo " --e2fsprogs Include e2fsprogs" + echo " --no-e2fsprogs Exclude e2fsprogs" + echo " --zfs Include ZFS support" + echo " --no-zfs Exclude ZFS support" + echo " --btrfs Include BTRFS support" + echo " --no-btrfs Exclude BTRFS support" + echo " --multipath Include Multipath support" + echo " --no-multipath Exclude Multipath support" + echo " --iscsi Include iSCSI support" + echo " --no-iscsi Exclude iSCSI support" + echo " --bootloader=grub Add new kernel to GRUB configuration" + echo " --linuxrc= Specifies a user created linuxrc" + echo " --busybox-config= Specifies a user created busybox config" + echo " --genzimage Make and install kernelz image (PowerPC)" + echo " --luks Include LUKS support" + echo " --> 'emerge cryptsetup-luks' with USE=-dynamic" + echo " --no-luks Exclude LUKS support" + echo " --gpg Include GPG-armored LUKS key support" + echo " --no-gpg Exclude GPG-armored LUKS key support" + echo " --busybox Include busybox" + echo " --no-busybox Exclude busybox" + echo " --netboot Create a self-contained env in the initramfs" + echo " --no-netboot Exclude --netboot env" + echo " --real-root= Specify a default for real_root=" echo " Internals" - echo " --arch-override= Force to arch instead of autodetect" - echo " --cachedir= Override the default cache location" - echo " --tempdir= Location of Genkernel's temporary directory" - echo " --postclear Clear all tmp files and caches after genkernel has run" - echo " --no-postclear Do not clean up after genkernel has run" + echo " --arch-override= Force to arch instead of autodetect" + echo " --cachedir= Override the default cache location" + echo " --tempdir= Location of Genkernel's temporary directory" + echo " --postclear Clear all tmp files and caches after genkernel has run" + echo " --no-postclear Do not clean up after genkernel has run" echo " Output Settings" - echo " --kernname=<...> Tag the kernel and ramdisk with a name:" - echo " If not defined the option defaults to" - echo " 'genkernel'" - echo " --minkernpackage= File to output a .tar.bz2'd kernel and ramdisk:" - echo " No modules outside of the ramdisk will be" - echo " included..." - echo " --modulespackage= File to output a .tar.bz2'd modules after the" - echo " callbacks have run" - echo " --kerncache= File to output a .tar.bz2'd kernel contents" - echo " of /lib/modules/ and the kernel config" - echo " NOTE: This is created before the callbacks" - echo " are run!" - echo " --no-kernel-sources This option is only valid if kerncache is" - echo " defined. If there is a valid kerncache no checks" - echo " will be made against a kernel source tree" - echo " --initramfs-overlay=" - echo " Directory structure to include in the initramfs," - echo " only available on 2.6 kernels" - echo " --firmware" - echo " Enable copying of firmware into initramfs" - echo " --firmware-dir=" - echo " Specify directory to copy firmware from (defaults" - echo " to /lib/firmware)" - echo " --firmware-files=" - echo " Specifies specific firmware files to copy. This" - echo " overrides --firmware-dir. For multiple files," - echo " separate the filenames with a comma" - echo " --integrated-initramfs, --no-integrated-initramfs" - echo " Include/exclude the generated initramfs in the kernel" - echo " instead of keeping it as a separate file" - echo " --compress-initramfs, --no-compress-initramfs," - echo " --compress-initrd, --no-compress-initrd" - echo " Compress or do not compress the generated initramfs" - echo " --compress-initramfs-type=" - echo " Compression type for initramfs (best, xz, lzma, bzip2, gzip, lzop)" + echo " --kernname=<...> Tag the kernel and ramdisk with a name:" + echo " If not defined the option defaults to" + echo " 'genkernel'" + echo " --minkernpackage= File to output a .tar.bz2'd kernel and ramdisk:" + echo " No modules outside of the ramdisk will be" + echo " included..." + echo " --modulespackage= File to output a .tar.bz2'd modules after the" + echo " callbacks have run" + echo " --kerncache= File to output a .tar.bz2'd kernel contents" + echo " of /lib/modules/ and the kernel config" + echo " NOTE: This is created before the callbacks" + echo " are run!" + echo " --no-kernel-sources This option is only valid if kerncache is" + echo " defined. If there is a valid kerncache no checks" + echo " will be made against a kernel source tree" + echo " --initramfs-overlay=" + echo " Directory structure to include in the initramfs," + echo " only available on 2.6 kernels" + echo " --firmware" + echo " Enable copying of firmware into initramfs" + echo " --firmware-dir=" + echo " Specify directory to copy firmware from (defaults" + echo " to /lib/firmware)" + echo " --firmware-files=" + echo " Specifies specific firmware files to copy. This" + echo " overrides --firmware-dir. For multiple files," + echo " separate the filenames with a comma" + echo " --integrated-initramfs, --no-integrated-initramfs" + echo " Include/exclude the generated initramfs in the kernel" + echo " instead of keeping it as a separate file" + echo " --compress-initramfs, --no-compress-initramfs," + echo " --compress-initrd, --no-compress-initrd" + echo " Compress or do not compress the generated initramfs" + echo " --compress-initramfs-type=" + echo " Compression type for initramfs (best, xz, lzma, bzip2, gzip, lzop)" } usage() { echo "Gentoo Linux Genkernel ${GK_V}" echo echo "Usage: " - echo " genkernel [options] all" + echo " genkernel [options] all" echo echo 'Some useful options:' - echo ' --menuconfig Run menuconfig after oldconfig' - echo ' --nconfig Run nconfig after oldconfig (requires ncurses)' - echo ' --no-clean Do not run make clean before compilation' - echo ' --no-mrproper Do not run make mrproper before compilation,' - echo ' this is implied by --no-clean.' + echo ' --menuconfig Run menuconfig after oldconfig' + echo ' --nconfig Run nconfig after oldconfig (requires ncurses)' + echo ' --no-clean Do not run make clean before compilation' + echo ' --no-mrproper Do not run make mrproper before compilation,' + echo ' this is implied by --no-clean.' echo echo 'For a detailed list of supported options and flags; issue:' - echo ' genkernel --help' + echo ' genkernel --help' } parse_optbool() { - local opt=${1/--no-*/0} # false - opt=${opt/--*/1} # true - echo $opt + local opt=${1/--no-*/0} # false + opt=${opt/--*/1} # true + echo $opt } parse_cmdline() { - case "$*" in - --kernel-cc=*) - CMD_KERNEL_CC=`parse_opt "$*"` - print_info 2 "CMD_KERNEL_CC: ${CMD_KERNEL_CC}" - ;; - --kernel-ld=*) - CMD_KERNEL_LD=`parse_opt "$*"` - print_info 2 "CMD_KERNEL_LD: ${CMD_KERNEL_LD}" - ;; - --kernel-as=*) - CMD_KERNEL_AS=`parse_opt "$*"` - print_info 2 "CMD_KERNEL_AS: ${CMD_KERNEL_AS}" - ;; - --kernel-make=*) - CMD_KERNEL_MAKE=`parse_opt "$*"` - print_info 2 "CMD_KERNEL_MAKE: ${CMD_KERNEL_MAKE}" - ;; - --kernel-target=*) - KERNEL_MAKE_DIRECTIVE_OVERRIDE=`parse_opt "$*"` - print_info 2 "KERNEL_MAKE_DIRECTIVE_OVERRIDE: ${KERNEL_MAKE_DIRECTIVE_OVERRIDE}" - ;; - --kernel-binary=*) - KERNEL_BINARY_OVERRIDE=`parse_opt "$*"` - print_info 2 "KERNEL_BINARY_OVERRIDE: ${KERNEL_BINARY_OVERRIDE}" - ;; - --kernel-outputdir=*) - CMD_KERNEL_OUTPUTDIR=`parse_opt "$*"` - print_info 2 "CMD_KERNEL_OUTPUTDIR: ${CMD_KERNEL_OUTPUTDIR}" - ;; - --utils-cc=*) - CMD_UTILS_CC=`parse_opt "$*"` - print_info 2 "CMD_UTILS_CC: ${CMD_UTILS_CC}" - ;; - --utils-ld=*) - CMD_UTILS_LD=`parse_opt "$*"` - print_info 2 "CMD_UTILS_LD: ${CMD_UTILS_LD}" - ;; - --utils-as=*) - CMD_UTILS_AS=`parse_opt "$*"` - print_info 2 "CMD_UTILS_AS: ${CMD_UTILS_AS}" - ;; - --utils-make=*) - CMD_UTILS_MAKE=`parse_opt "$*"` - print_info 2 "CMD_UTILS_MAKE: ${CMD_UTILS_MAKE}" - ;; - --utils-arch=*) - CMD_UTILS_ARCH=`parse_opt "$*"` - print_info 2 "CMD_UTILS_ARCH: ${CMD_ARCHOVERRIDE}" - ;; - --makeopts=*) - CMD_MAKEOPTS=`parse_opt "$*"` - print_info 2 "CMD_MAKEOPTS: ${CMD_MAKEOPTS}" - ;; - --mountboot|--no-mountboot) - CMD_MOUNTBOOT=`parse_optbool "$*"` - print_info 2 "CMD_MOUNTBOOT: ${CMD_MOUNTBOOT}" - ;; - --bootdir=*) - CMD_BOOTDIR=`parse_opt "$*"` - print_info 2 "CMD_BOOTDIR: ${CMD_BOOTDIR}" - ;; - --modprobedir=*) - CMD_MODPROBEDIR=`parse_opt "$*"` - print_info 2 "CMD_MODPROBEDIR: ${CMD_MODPROBEDIR}" - ;; - --do-keymap-auto) - CMD_DOKEYMAPAUTO=1 - CMD_KEYMAP=1 - print_info 2 "CMD_DOKEYMAPAUTO: ${CMD_DOKEYMAPAUTO}" - ;; - --keymap|--no-keymap) - CMD_KEYMAP=`parse_optbool "$*"` - print_info 2 "CMD_KEYMAP: ${CMD_KEYMAP}" - ;; - --udev|--no-udev) - CMD_UDEV=`parse_optbool "$*"` - print_info 2 "CMD_UDEV: ${CMD_UDEV}" - ;; - --lvm|--no-lvm) - CMD_LVM=`parse_optbool "$*"` - print_info 2 "CMD_LVM: ${CMD_LVM}" - ;; - --lvm2|--no-lvm2) - CMD_LVM=`parse_optbool "$*"` - print_info 2 "CMD_LVM: ${CMD_LVM}" - echo - print_warning 1 "Please use --lvm, as --lvm2 is deprecated." - ;; - --mdadm|--no-mdadm) - CMD_MDADM=`parse_optbool "$*"` - print_info 2 "CMD_MDADM: $CMD_MDADM" - ;; - --mdadm-config=*) - CMD_MDADM_CONFIG=`parse_opt "$*"` - print_info 2 "CMD_MDADM_CONFIG: $CMD_MDADM_CONFIG" - ;; - --busybox|--no-busybox) - CMD_BUSYBOX=`parse_optbool "$*"` - print_info 2 "CMD_BUSYBOX: ${CMD_BUSYBOX}" - ;; - --netboot|--no-netboot) - CMD_NETBOOT=`parse_optbool "$*"` - print_info 2 "CMD_NETBOOT: ${CMD_NETBOOT}" - ;; - --real-root=*) - CMD_REAL_ROOT=`parse_opt "$*"` - print_info 2 "CMD_REAL_ROOT: ${CMD_REAL_ROOT}" - ;; - --dmraid|--no-dmraid) - CMD_DMRAID=`parse_optbool "$*"` - if [ "$CMD_DMRAID" = "1" -a ! -e /usr/include/libdevmapper.h ] - then - echo 'Error: --dmraid requires LVM2 to be installed' - echo ' on the host system; try "emerge lvm2".' - exit 1 - fi - print_info 2 "CMD_DMRAID: ${CMD_DMRAID}" - ;; - --e2fsprogs|--no-e2fsprogs) - CMD_E2FSPROGS=`parse_optbool "$*"` - print_info 2 "CMD_E2FSPROGS: ${CMD_E2FSPROGS}" - ;; - --zfs|--no-zfs) - CMD_ZFS=`parse_optbool "$*"` - print_info 2 "CMD_ZFS: ${CMD_ZFS}" - ;; - --btrfs|--no-btrfs) - CMD_BTRFS=`parse_optbool "$*"` - print_info 2 "CMD_BTRFS: ${CMD_BTRFS}" - ;; - --virtio) - CMD_VIRTIO=`parse_optbool "$*"` - print_info 2 "CMD_VIRTIO: ${CMD_VIRTIO}" - ;; - --multipath|--no-multipath) - CMD_MULTIPATH=`parse_optbool "$*"` - if [ "$CMD_MULTIPATH" = "1" -a ! -e /usr/include/libdevmapper.h ] - then - echo 'Error: --multipath requires LVM2 to be installed' - echo ' on the host;system; try "emerge lvm2".' - exit 1 - fi - print_info 2 "CMD_MULTIPATH: ${CMD_MULTIPATH}" - ;; - --bootloader=*) - CMD_BOOTLOADER=`parse_opt "$*"` - print_info 2 "CMD_BOOTLOADER: ${CMD_BOOTLOADER}" - ;; - --iscsi|--no-iscsi) - CMD_ISCSI=`parse_optbool "$*"` - print_info 2 "CMD_ISCSI: ${CMD_ISCSI}" - ;; - --loglevel=*) - CMD_LOGLEVEL=`parse_opt "$*"` - LOGLEVEL="${CMD_LOGLEVEL}" - print_info 2 "CMD_LOGLEVEL: ${CMD_LOGLEVEL}" - ;; - --menuconfig) - TERM_LINES=`stty -a | head -n 1 | cut -d\ -f5 | cut -d\; -f1` - TERM_COLUMNS=`stty -a | head -n 1 | cut -d\ -f7 | cut -d\; -f1` - if [[ TERM_LINES -lt 19 || TERM_COLUMNS -lt 80 ]] - then - echo "Error: You need a terminal with at least 80 columns" - echo " and 19 lines for --menuconfig; try --no-menuconfig..." - exit 1 - fi - CMD_MENUCONFIG=1 - print_info 2 "CMD_MENUCONFIG: ${CMD_MENUCONFIG}" - ;; - --no-menuconfig) - CMD_MENUCONFIG=0 - print_info 2 "CMD_MENUCONFIG: ${CMD_MENUCONFIG}" - ;; - --nconfig) - CMD_NCONFIG=1 - print_info 2 "CMD_NCONFIG: ${CMD_NCONFIG}" - ;; - --no-nconfig) - CMD_NCONFIG=0 - print_info 2 "CMD_NCONFIG: ${CMD_NCONFIG}" - ;; - --gconfig|--no-gconfig) - CMD_GCONFIG=`parse_optbool "$*"` - print_info 2 "CMD_GCONFIG: ${CMD_GCONFIG}" - ;; - --xconfig|--no-xconfig) - CMD_XCONFIG=`parse_optbool "$*"` - print_info 2 "CMD_XCONFIG: ${CMD_XCONFIG}" - ;; - --save-config|--no-save-config) - CMD_SAVE_CONFIG=`parse_optbool "$*"` - print_info 2 "CMD_SAVE_CONFIG: ${CMD_SAVE_CONFIG}" - ;; - --mrproper|--no-mrproper) - CMD_MRPROPER=`parse_optbool "$*"` - print_info 2 "CMD_MRPROPER: ${CMD_MRPROPER}" - ;; - --clean|--no-clean) - CMD_CLEAN=`parse_optbool "$*"` - print_info 2 "CMD_CLEAN: ${CMD_CLEAN}" - ;; - --oldconfig|--no-oldconfig) - CMD_OLDCONFIG=`parse_optbool "$*"` - [ "$CMD_OLDCONFIG" = "1" ] && CMD_CLEAN=0 - print_info 2 "CMD_CLEAN: ${CMD_CLEAN}" - print_info 2 "CMD_OLDCONFIG: ${CMD_OLDCONFIG}" - ;; - --gensplash=*) - CMD_SPLASH=1 - SPLASH_THEME=`parse_opt "$*"` - print_info 2 "CMD_SPLASH: ${CMD_SPLASH}" - print_info 2 "SPLASH_THEME: ${SPLASH_THEME}" - echo - print_warning 1 "Please use --splash, as --gensplash is deprecated." - ;; - --gensplash|--no-gensplash) - CMD_SPLASH=`parse_optbool "$*"` - SPLASH_THEME='default' - print_info 2 "CMD_SPLASH: ${CMD_SPLASH}" - echo - print_warning 1 "Please use --splash, as --gensplash is deprecated." - ;; - --splash=*) - CMD_SPLASH=1 - SPLASH_THEME=`parse_opt "$*"` - print_info 2 "CMD_SPLASH: ${CMD_SPLASH}" - print_info 2 "SPLASH_THEME: ${SPLASH_THEME}" - ;; - --splash|--no-splash) - CMD_SPLASH=`parse_optbool "$*"` - SPLASH_THEME='default' - print_info 2 "CMD_SPLASH: ${CMD_SPLASH}" - ;; - --gensplash-res=*) - SPLASH_RES=`parse_opt "$*"` - print_info 2 "SPLASH_RES: ${SPLASH_RES}" - echo - print_warning 1 "Please use --splash-res, as --gensplash-res is deprecated." - ;; - --splash-res=*) - SPLASH_RES=`parse_opt "$*"` - print_info 2 "SPLASH_RES: ${SPLASH_RES}" - ;; - --plymouth) - CMD_PLYMOUTH=1 - CMD_UDEV=1 # mdev is not really supported - PLYMOUTH_THEME='text' - print_info 2 "CMD_PLYMOUTH: ${CMD_PLYMOUTH}" - ;; - --plymouth-theme=*) - CMD_PLYMOUTH=1 - PLYMOUTH_THEME=`parse_opt "$*"` - print_info 2 "CMD_PLYMOUTH: ${CMD_PLYMOUTH}" - print_info 2 "PLYMOUTH_THEME: ${PLYMOUTH_THEME}" - ;; - --install|--no-install) - CMD_INSTALL=`parse_optbool "$*"` - print_info 2 "CMD_INSTALL: ${CMD_INSTALL}" - ;; - --ramdisk-modules|--no-ramdisk-modules) - CMD_RAMDISKMODULES=`parse_optbool "$*"` - print_info 2 "CMD_RAMDISKMODULES: ${CMD_RAMDISKMODULES}" - ;; - --all-ramdisk-modules|--no-all-ramdisk-modules) - CMD_ALLRAMDISKMODULES=`parse_optbool "$*"` - print_info 2 "CMD_ALLRAMDISKMODULES: ${CMD_ALLRAMDISKMODULES}" - ;; - --callback=*) - CMD_CALLBACK=`parse_opt "$*"` - print_info 2 "CMD_CALLBACK: ${CMD_CALLBACK}/$*" - ;; - --static|--no-static) - CMD_STATIC=`parse_optbool "$*"` - print_info 2 "CMD_STATIC: ${CMD_STATIC}" - ;; - --tempdir=*) - TMPDIR=`parse_opt "$*"` - TEMP=${TMPDIR}/$RANDOM.$RANDOM.$RANDOM.$$ - print_info 2 "TMPDIR: ${TMPDIR}" - print_info 2 "TEMP: ${TEMP}" - ;; - --postclear|--no-postclear) - CMD_POSTCLEAR=`parse_optbool "$*"` - print_info 2 "CMD_POSTCLEAR: ${CMD_POSTCLEAR}" - ;; - --arch-override=*) - CMD_ARCHOVERRIDE=`parse_opt "$*"` - print_info 2 "CMD_ARCHOVERRIDE: ${CMD_ARCHOVERRIDE}" - ;; - --color|--no-color) - USECOLOR=`parse_optbool "$*"` - print_info 2 "USECOLOR: ${USECOLOR}" - setColorVars - ;; - --logfile=*) - CMD_LOGFILE=`parse_opt "$*"` - LOGFILE=`parse_opt "$*"` - print_info 2 "CMD_LOGFILE: ${CMD_LOGFILE}" - print_info 2 "LOGFILE: ${CMD_LOGFILE}" - ;; - --kerneldir=*) - CMD_KERNEL_DIR=`parse_opt "$*"` - print_info 2 "CMD_KERNEL_DIR: ${CMD_KERNEL_DIR}" - ;; - --kernel-config=*) - CMD_KERNEL_CONFIG=`parse_opt "$*"` - print_info 2 "CMD_KERNEL_CONFIG: ${CMD_KERNEL_CONFIG}" - ;; - --module-prefix=*) - CMD_INSTALL_MOD_PATH=`parse_opt "$*"` - print_info 2 "CMD_INSTALL_MOD_PATH: ${CMD_INSTALL_MOD_PATH}" - ;; - --cachedir=*) - CACHE_DIR=`parse_opt "$*"` - print_info 2 "CACHE_DIR: ${CACHE_DIR}" - ;; - --minkernpackage=*) - CMD_MINKERNPACKAGE=`parse_opt "$*"` - print_info 2 "MINKERNPACKAGE: ${CMD_MINKERNPACKAGE}" - ;; - --modulespackage=*) - CMD_MODULESPACKAGE=`parse_opt "$*"` - print_info 2 "MODULESPACKAGE: ${CMD_MODULESPACKAGE}" - ;; - --kerncache=*) - CMD_KERNCACHE=`parse_opt "$*"` - print_info 2 "KERNCACHE: ${CMD_KERNCACHE}" - ;; - --kernname=*) - CMD_KERNNAME=`parse_opt "$*"` - print_info 2 "KERNNAME: ${CMD_KERNNAME}" - ;; - --symlink|--no-symlink) - CMD_SYMLINK=`parse_optbool "$*"` - print_info 2 "CMD_SYMLINK: ${CMD_SYMLINK}" - ;; - --kernel-sources|--no-kernel-sources) - CMD_KERNEL_SOURCES=`parse_optbool "$*"` - print_info 2 "CMD_KERNEL_SOURCES: ${CMD_KERNEL_SOURCES}" - ;; - --initramfs-overlay=*) - CMD_INITRAMFS_OVERLAY=`parse_opt "$*"` - print_info 2 "CMD_INITRAMFS_OVERLAY: ${CMD_INITRAMFS_OVERLAY}" - ;; - --linuxrc=*) - CMD_LINUXRC=`parse_opt "$*"` - print_info 2 "CMD_LINUXRC: ${CMD_LINUXRC}" - ;; - --busybox-config=*) - CMD_BUSYBOX_CONFIG=`parse_opt "$*"` - print_info 2 "CMD_BUSYBOX_CONFIG: ${CMD_BUSYBOX_CONFIG}" - ;; - --genzimage) - KERNEL_MAKE_DIRECTIVE_2='zImage.initrd' - KERNEL_BINARY_2='arch/powerpc/boot/zImage.initrd' - CMD_GENZIMAGE="yes" -# ENABLE_PEGASOS_HACKS="yes" -# print_info 2 "ENABLE_PEGASOS_HACKS: ${ENABLE_PEGASOS_HACKS}" - ;; - --luks|--no-luks) - CMD_LUKS=`parse_optbool "$*"` - print_info 2 "CMD_LUKS: ${CMD_LUKS}" - ;; - --gpg|--no-gpg) - CMD_GPG=`parse_optbool "$*"` - print_info 2 "CMD_GPG: ${CMD_GPG}" - ;; - --firmware|--no-firmware) - CMD_FIRMWARE=`parse_optbool "$*"` - print_info 2 "CMD_FIRMWARE: ${CMD_FIRMWARE}" - ;; - --firmware-dir=*) - CMD_FIRMWARE_DIR=`parse_opt "$*"` - CMD_FIRMWARE=1 - print_info 2 "CMD_FIRMWARE_DIR: ${CMD_FIRMWARE_DIR}" - ;; - --firmware-files=*) - CMD_FIRMWARE_FILES=`parse_opt "$*"` - CMD_FIRMWARE=1 - print_info 2 "CMD_FIRMWARE_FILES: ${CMD_FIRMWARE_FILES}" - ;; - --integrated-initramfs|--no-integrated-initramfs) - CMD_INTEGRATED_INITRAMFS=`parse_optbool "$*"` - print_info 2 "CMD_INTEGRATED_INITRAMFS=${CMD_INTEGRATED_INITRAMFS}" - ;; - --compress-initramfs|--no-compress-initramfs|--compress-initrd|--no-compress-initrd) - CMD_COMPRESS_INITRD=`parse_optbool "$*"` - print_info 2 "CMD_COMPRESS_INITRD=${CMD_COMPRESS_INITRD}" - ;; - --compress-initramfs-type=*|--compress-initrd-type=*) - COMPRESS_INITRD_TYPE=`parse_opt "$*"` - print_info 2 "CMD_COMPRESS_INITRD_TYPE: ${CMD_LINUXRC}" - ;; - --config=*) - print_info 2 "CMD_GK_CONFIG: `parse_opt "$*"`" - ;; - all) - BUILD_KERNEL=1 - BUILD_MODULES=1 - BUILD_RAMDISK=1 - ;; - ramdisk|initramfs) - BUILD_RAMDISK=1 - ;; - kernel) - BUILD_KERNEL=1 - BUILD_MODULES=1 - BUILD_RAMDISK=0 - ;; - bzImage) - BUILD_KERNEL=1 - BUILD_MODULES=0 - BUILD_RAMDISK=1 - CMD_RAMDISKMODULES=0 - print_info 2 "CMD_RAMDISKMODULES: ${CMD_RAMDISKMODULES}" - ;; - --help) - longusage - exit 1 - ;; - --version) - echo "${GK_V}" - exit 0 - ;; - *) - echo "Error: Unknown option '$*'!" - exit 1 - ;; - esac + case "$*" in + --kernel-cc=*) + CMD_KERNEL_CC=`parse_opt "$*"` + print_info 2 "CMD_KERNEL_CC: ${CMD_KERNEL_CC}" + ;; + --kernel-ld=*) + CMD_KERNEL_LD=`parse_opt "$*"` + print_info 2 "CMD_KERNEL_LD: ${CMD_KERNEL_LD}" + ;; + --kernel-as=*) + CMD_KERNEL_AS=`parse_opt "$*"` + print_info 2 "CMD_KERNEL_AS: ${CMD_KERNEL_AS}" + ;; + --kernel-make=*) + CMD_KERNEL_MAKE=`parse_opt "$*"` + print_info 2 "CMD_KERNEL_MAKE: ${CMD_KERNEL_MAKE}" + ;; + --kernel-target=*) + KERNEL_MAKE_DIRECTIVE_OVERRIDE=`parse_opt "$*"` + print_info 2 "KERNEL_MAKE_DIRECTIVE_OVERRIDE: ${KERNEL_MAKE_DIRECTIVE_OVERRIDE}" + ;; + --kernel-binary=*) + KERNEL_BINARY_OVERRIDE=`parse_opt "$*"` + print_info 2 "KERNEL_BINARY_OVERRIDE: ${KERNEL_BINARY_OVERRIDE}" + ;; + --kernel-outputdir=*) + CMD_KERNEL_OUTPUTDIR=`parse_opt "$*"` + print_info 2 "CMD_KERNEL_OUTPUTDIR: ${CMD_KERNEL_OUTPUTDIR}" + ;; + --utils-cc=*) + CMD_UTILS_CC=`parse_opt "$*"` + print_info 2 "CMD_UTILS_CC: ${CMD_UTILS_CC}" + ;; + --utils-ld=*) + CMD_UTILS_LD=`parse_opt "$*"` + print_info 2 "CMD_UTILS_LD: ${CMD_UTILS_LD}" + ;; + --utils-as=*) + CMD_UTILS_AS=`parse_opt "$*"` + print_info 2 "CMD_UTILS_AS: ${CMD_UTILS_AS}" + ;; + --utils-make=*) + CMD_UTILS_MAKE=`parse_opt "$*"` + print_info 2 "CMD_UTILS_MAKE: ${CMD_UTILS_MAKE}" + ;; + --utils-arch=*) + CMD_UTILS_ARCH=`parse_opt "$*"` + print_info 2 "CMD_UTILS_ARCH: ${CMD_ARCHOVERRIDE}" + ;; + --makeopts=*) + CMD_MAKEOPTS=`parse_opt "$*"` + print_info 2 "CMD_MAKEOPTS: ${CMD_MAKEOPTS}" + ;; + --mountboot|--no-mountboot) + CMD_MOUNTBOOT=`parse_optbool "$*"` + print_info 2 "CMD_MOUNTBOOT: ${CMD_MOUNTBOOT}" + ;; + --bootdir=*) + CMD_BOOTDIR=`parse_opt "$*"` + print_info 2 "CMD_BOOTDIR: ${CMD_BOOTDIR}" + ;; + --modprobedir=*) + CMD_MODPROBEDIR=`parse_opt "$*"` + print_info 2 "CMD_MODPROBEDIR: ${CMD_MODPROBEDIR}" + ;; + --do-keymap-auto) + CMD_DOKEYMAPAUTO=1 + CMD_KEYMAP=1 + print_info 2 "CMD_DOKEYMAPAUTO: ${CMD_DOKEYMAPAUTO}" + ;; + --keymap|--no-keymap) + CMD_KEYMAP=`parse_optbool "$*"` + print_info 2 "CMD_KEYMAP: ${CMD_KEYMAP}" + ;; + --udev|--no-udev) + CMD_UDEV=`parse_optbool "$*"` + print_info 2 "CMD_UDEV: ${CMD_UDEV}" + ;; + --lvm|--no-lvm) + CMD_LVM=`parse_optbool "$*"` + print_info 2 "CMD_LVM: ${CMD_LVM}" + ;; + --lvm2|--no-lvm2) + CMD_LVM=`parse_optbool "$*"` + print_info 2 "CMD_LVM: ${CMD_LVM}" + echo + print_warning 1 "Please use --lvm, as --lvm2 is deprecated." + ;; + --mdadm|--no-mdadm) + CMD_MDADM=`parse_optbool "$*"` + print_info 2 "CMD_MDADM: $CMD_MDADM" + ;; + --mdadm-config=*) + CMD_MDADM_CONFIG=`parse_opt "$*"` + print_info 2 "CMD_MDADM_CONFIG: $CMD_MDADM_CONFIG" + ;; + --busybox|--no-busybox) + CMD_BUSYBOX=`parse_optbool "$*"` + print_info 2 "CMD_BUSYBOX: ${CMD_BUSYBOX}" + ;; + --netboot|--no-netboot) + CMD_NETBOOT=`parse_optbool "$*"` + print_info 2 "CMD_NETBOOT: ${CMD_NETBOOT}" + ;; + --real-root=*) + CMD_REAL_ROOT=`parse_opt "$*"` + print_info 2 "CMD_REAL_ROOT: ${CMD_REAL_ROOT}" + ;; + --dmraid|--no-dmraid) + CMD_DMRAID=`parse_optbool "$*"` + if [ "$CMD_DMRAID" = "1" -a ! -e /usr/include/libdevmapper.h ] + then + echo 'Error: --dmraid requires LVM2 to be installed' + echo ' on the host system; try "emerge lvm2".' + exit 1 + fi + print_info 2 "CMD_DMRAID: ${CMD_DMRAID}" + ;; + --e2fsprogs|--no-e2fsprogs) + CMD_E2FSPROGS=`parse_optbool "$*"` + print_info 2 "CMD_E2FSPROGS: ${CMD_E2FSPROGS}" + ;; + --zfs|--no-zfs) + CMD_ZFS=`parse_optbool "$*"` + print_info 2 "CMD_ZFS: ${CMD_ZFS}" + ;; + --btrfs|--no-btrfs) + CMD_BTRFS=`parse_optbool "$*"` + print_info 2 "CMD_BTRFS: ${CMD_BTRFS}" + ;; + --virtio) + CMD_VIRTIO=`parse_optbool "$*"` + print_info 2 "CMD_VIRTIO: ${CMD_VIRTIO}" + ;; + --multipath|--no-multipath) + CMD_MULTIPATH=`parse_optbool "$*"` + if [ "$CMD_MULTIPATH" = "1" -a ! -e /usr/include/libdevmapper.h ] + then + echo 'Error: --multipath requires LVM2 to be installed' + echo ' on the host;system; try "emerge lvm2".' + exit 1 + fi + print_info 2 "CMD_MULTIPATH: ${CMD_MULTIPATH}" + ;; + --bootloader=*) + CMD_BOOTLOADER=`parse_opt "$*"` + print_info 2 "CMD_BOOTLOADER: ${CMD_BOOTLOADER}" + ;; + --iscsi|--no-iscsi) + CMD_ISCSI=`parse_optbool "$*"` + print_info 2 "CMD_ISCSI: ${CMD_ISCSI}" + ;; + --loglevel=*) + CMD_LOGLEVEL=`parse_opt "$*"` + LOGLEVEL="${CMD_LOGLEVEL}" + print_info 2 "CMD_LOGLEVEL: ${CMD_LOGLEVEL}" + ;; + --menuconfig) + TERM_LINES=`stty -a | head -n 1 | cut -d\ -f5 | cut -d\; -f1` + TERM_COLUMNS=`stty -a | head -n 1 | cut -d\ -f7 | cut -d\; -f1` + if [[ TERM_LINES -lt 19 || TERM_COLUMNS -lt 80 ]] + then + echo "Error: You need a terminal with at least 80 columns" + echo " and 19 lines for --menuconfig; try --no-menuconfig..." + exit 1 + fi + CMD_MENUCONFIG=1 + print_info 2 "CMD_MENUCONFIG: ${CMD_MENUCONFIG}" + ;; + --no-menuconfig) + CMD_MENUCONFIG=0 + print_info 2 "CMD_MENUCONFIG: ${CMD_MENUCONFIG}" + ;; + --nconfig) + CMD_NCONFIG=1 + print_info 2 "CMD_NCONFIG: ${CMD_NCONFIG}" + ;; + --no-nconfig) + CMD_NCONFIG=0 + print_info 2 "CMD_NCONFIG: ${CMD_NCONFIG}" + ;; + --gconfig|--no-gconfig) + CMD_GCONFIG=`parse_optbool "$*"` + print_info 2 "CMD_GCONFIG: ${CMD_GCONFIG}" + ;; + --xconfig|--no-xconfig) + CMD_XCONFIG=`parse_optbool "$*"` + print_info 2 "CMD_XCONFIG: ${CMD_XCONFIG}" + ;; + --save-config|--no-save-config) + CMD_SAVE_CONFIG=`parse_optbool "$*"` + print_info 2 "CMD_SAVE_CONFIG: ${CMD_SAVE_CONFIG}" + ;; + --mrproper|--no-mrproper) + CMD_MRPROPER=`parse_optbool "$*"` + print_info 2 "CMD_MRPROPER: ${CMD_MRPROPER}" + ;; + --clean|--no-clean) + CMD_CLEAN=`parse_optbool "$*"` + print_info 2 "CMD_CLEAN: ${CMD_CLEAN}" + ;; + --oldconfig|--no-oldconfig) + CMD_OLDCONFIG=`parse_optbool "$*"` + [ "$CMD_OLDCONFIG" = "1" ] && CMD_CLEAN=0 + print_info 2 "CMD_CLEAN: ${CMD_CLEAN}" + print_info 2 "CMD_OLDCONFIG: ${CMD_OLDCONFIG}" + ;; + --gensplash=*) + CMD_SPLASH=1 + SPLASH_THEME=`parse_opt "$*"` + print_info 2 "CMD_SPLASH: ${CMD_SPLASH}" + print_info 2 "SPLASH_THEME: ${SPLASH_THEME}" + echo + print_warning 1 "Please use --splash, as --gensplash is deprecated." + ;; + --gensplash|--no-gensplash) + CMD_SPLASH=`parse_optbool "$*"` + SPLASH_THEME='default' + print_info 2 "CMD_SPLASH: ${CMD_SPLASH}" + echo + print_warning 1 "Please use --splash, as --gensplash is deprecated." + ;; + --splash=*) + CMD_SPLASH=1 + SPLASH_THEME=`parse_opt "$*"` + print_info 2 "CMD_SPLASH: ${CMD_SPLASH}" + print_info 2 "SPLASH_THEME: ${SPLASH_THEME}" + ;; + --splash|--no-splash) + CMD_SPLASH=`parse_optbool "$*"` + SPLASH_THEME='default' + print_info 2 "CMD_SPLASH: ${CMD_SPLASH}" + ;; + --gensplash-res=*) + SPLASH_RES=`parse_opt "$*"` + print_info 2 "SPLASH_RES: ${SPLASH_RES}" + echo + print_warning 1 "Please use --splash-res, as --gensplash-res is deprecated." + ;; + --splash-res=*) + SPLASH_RES=`parse_opt "$*"` + print_info 2 "SPLASH_RES: ${SPLASH_RES}" + ;; + --plymouth) + CMD_PLYMOUTH=1 + CMD_UDEV=1 # mdev is not really supported + PLYMOUTH_THEME='text' + print_info 2 "CMD_PLYMOUTH: ${CMD_PLYMOUTH}" + ;; + --plymouth-theme=*) + CMD_PLYMOUTH=1 + PLYMOUTH_THEME=`parse_opt "$*"` + print_info 2 "CMD_PLYMOUTH: ${CMD_PLYMOUTH}" + print_info 2 "PLYMOUTH_THEME: ${PLYMOUTH_THEME}" + ;; + --install|--no-install) + CMD_INSTALL=`parse_optbool "$*"` + print_info 2 "CMD_INSTALL: ${CMD_INSTALL}" + ;; + --ramdisk-modules|--no-ramdisk-modules) + CMD_RAMDISKMODULES=`parse_optbool "$*"` + print_info 2 "CMD_RAMDISKMODULES: ${CMD_RAMDISKMODULES}" + ;; + --all-ramdisk-modules|--no-all-ramdisk-modules) + CMD_ALLRAMDISKMODULES=`parse_optbool "$*"` + print_info 2 "CMD_ALLRAMDISKMODULES: ${CMD_ALLRAMDISKMODULES}" + ;; + --callback=*) + CMD_CALLBACK=`parse_opt "$*"` + print_info 2 "CMD_CALLBACK: ${CMD_CALLBACK}/$*" + ;; + --static|--no-static) + CMD_STATIC=`parse_optbool "$*"` + print_info 2 "CMD_STATIC: ${CMD_STATIC}" + ;; + --tempdir=*) + TMPDIR=`parse_opt "$*"` + TEMP=${TMPDIR}/$RANDOM.$RANDOM.$RANDOM.$$ + print_info 2 "TMPDIR: ${TMPDIR}" + print_info 2 "TEMP: ${TEMP}" + ;; + --postclear|--no-postclear) + CMD_POSTCLEAR=`parse_optbool "$*"` + print_info 2 "CMD_POSTCLEAR: ${CMD_POSTCLEAR}" + ;; + --arch-override=*) + CMD_ARCHOVERRIDE=`parse_opt "$*"` + print_info 2 "CMD_ARCHOVERRIDE: ${CMD_ARCHOVERRIDE}" + ;; + --color|--no-color) + USECOLOR=`parse_optbool "$*"` + print_info 2 "USECOLOR: ${USECOLOR}" + setColorVars + ;; + --logfile=*) + CMD_LOGFILE=`parse_opt "$*"` + LOGFILE=`parse_opt "$*"` + print_info 2 "CMD_LOGFILE: ${CMD_LOGFILE}" + print_info 2 "LOGFILE: ${CMD_LOGFILE}" + ;; + --kerneldir=*) + CMD_KERNEL_DIR=`parse_opt "$*"` + print_info 2 "CMD_KERNEL_DIR: ${CMD_KERNEL_DIR}" + ;; + --kernel-config=*) + CMD_KERNEL_CONFIG=`parse_opt "$*"` + print_info 2 "CMD_KERNEL_CONFIG: ${CMD_KERNEL_CONFIG}" + ;; + --module-prefix=*) + CMD_INSTALL_MOD_PATH=`parse_opt "$*"` + print_info 2 "CMD_INSTALL_MOD_PATH: ${CMD_INSTALL_MOD_PATH}" + ;; + --cachedir=*) + CACHE_DIR=`parse_opt "$*"` + print_info 2 "CACHE_DIR: ${CACHE_DIR}" + ;; + --minkernpackage=*) + CMD_MINKERNPACKAGE=`parse_opt "$*"` + print_info 2 "MINKERNPACKAGE: ${CMD_MINKERNPACKAGE}" + ;; + --modulespackage=*) + CMD_MODULESPACKAGE=`parse_opt "$*"` + print_info 2 "MODULESPACKAGE: ${CMD_MODULESPACKAGE}" + ;; + --kerncache=*) + CMD_KERNCACHE=`parse_opt "$*"` + print_info 2 "KERNCACHE: ${CMD_KERNCACHE}" + ;; + --kernname=*) + CMD_KERNNAME=`parse_opt "$*"` + print_info 2 "KERNNAME: ${CMD_KERNNAME}" + ;; + --symlink|--no-symlink) + CMD_SYMLINK=`parse_optbool "$*"` + print_info 2 "CMD_SYMLINK: ${CMD_SYMLINK}" + ;; + --kernel-sources|--no-kernel-sources) + CMD_KERNEL_SOURCES=`parse_optbool "$*"` + print_info 2 "CMD_KERNEL_SOURCES: ${CMD_KERNEL_SOURCES}" + ;; + --initramfs-overlay=*) + CMD_INITRAMFS_OVERLAY=`parse_opt "$*"` + print_info 2 "CMD_INITRAMFS_OVERLAY: ${CMD_INITRAMFS_OVERLAY}" + ;; + --linuxrc=*) + CMD_LINUXRC=`parse_opt "$*"` + print_info 2 "CMD_LINUXRC: ${CMD_LINUXRC}" + ;; + --busybox-config=*) + CMD_BUSYBOX_CONFIG=`parse_opt "$*"` + print_info 2 "CMD_BUSYBOX_CONFIG: ${CMD_BUSYBOX_CONFIG}" + ;; + --genzimage) + KERNEL_MAKE_DIRECTIVE_2='zImage.initrd' + KERNEL_BINARY_2='arch/powerpc/boot/zImage.initrd' + CMD_GENZIMAGE="yes" +# ENABLE_PEGASOS_HACKS="yes" +# print_info 2 "ENABLE_PEGASOS_HACKS: ${ENABLE_PEGASOS_HACKS}" + ;; + --luks|--no-luks) + CMD_LUKS=`parse_optbool "$*"` + print_info 2 "CMD_LUKS: ${CMD_LUKS}" + ;; + --gpg|--no-gpg) + CMD_GPG=`parse_optbool "$*"` + print_info 2 "CMD_GPG: ${CMD_GPG}" + ;; + --firmware|--no-firmware) + CMD_FIRMWARE=`parse_optbool "$*"` + print_info 2 "CMD_FIRMWARE: ${CMD_FIRMWARE}" + ;; + --firmware-dir=*) + CMD_FIRMWARE_DIR=`parse_opt "$*"` + CMD_FIRMWARE=1 + print_info 2 "CMD_FIRMWARE_DIR: ${CMD_FIRMWARE_DIR}" + ;; + --firmware-files=*) + CMD_FIRMWARE_FILES=`parse_opt "$*"` + CMD_FIRMWARE=1 + print_info 2 "CMD_FIRMWARE_FILES: ${CMD_FIRMWARE_FILES}" + ;; + --integrated-initramfs|--no-integrated-initramfs) + CMD_INTEGRATED_INITRAMFS=`parse_optbool "$*"` + print_info 2 "CMD_INTEGRATED_INITRAMFS=${CMD_INTEGRATED_INITRAMFS}" + ;; + --compress-initramfs|--no-compress-initramfs|--compress-initrd|--no-compress-initrd) + CMD_COMPRESS_INITRD=`parse_optbool "$*"` + print_info 2 "CMD_COMPRESS_INITRD=${CMD_COMPRESS_INITRD}" + ;; + --compress-initramfs-type=*|--compress-initrd-type=*) + COMPRESS_INITRD_TYPE=`parse_opt "$*"` + print_info 2 "CMD_COMPRESS_INITRD_TYPE: ${CMD_LINUXRC}" + ;; + --config=*) + print_info 2 "CMD_GK_CONFIG: `parse_opt "$*"`" + ;; + all) + BUILD_KERNEL=1 + BUILD_MODULES=1 + BUILD_RAMDISK=1 + ;; + ramdisk|initramfs) + BUILD_RAMDISK=1 + ;; + kernel) + BUILD_KERNEL=1 + BUILD_MODULES=1 + BUILD_RAMDISK=0 + ;; + bzImage) + BUILD_KERNEL=1 + BUILD_MODULES=0 + BUILD_RAMDISK=1 + CMD_RAMDISKMODULES=0 + print_info 2 "CMD_RAMDISKMODULES: ${CMD_RAMDISKMODULES}" + ;; + --help) + longusage + exit 1 + ;; + --version) + echo "${GK_V}" + exit 0 + ;; + *) + echo "Error: Unknown option '$*'!" + exit 1 + ;; + esac } diff --git a/gen_compile.sh b/gen_compile.sh index f3e62e7..81f9f48 100755 --- a/gen_compile.sh +++ b/gen_compile.sh @@ -2,403 +2,403 @@ # $Id$ compile_kernel_args() { - local ARGS + local ARGS - ARGS='' - if [ "${KERNEL_CC}" != '' ] - then - ARGS="CC=\"${KERNEL_CC}\"" - fi - if [ "${KERNEL_LD}" != '' ] - then - ARGS="${ARGS} LD=\"${KERNEL_LD}\"" - fi - if [ "${KERNEL_AS}" != '' ] - then - ARGS="${ARGS} AS=\"${KERNEL_AS}\"" - fi - if [ -n "${KERNEL_ARCH}" ] - then - ARGS="${ARGS} ARCH=\"${KERNEL_ARCH}\"" - fi - if [ -n "${KERNEL_OUTPUTDIR}" -a "${KERNEL_OUTPUTDIR}" != "${KERNEL_DIR}" ] - then - ARGS="${ARGS} O=\"${KERNEL_OUTPUTDIR}\"" - fi - echo -n "${ARGS}" + ARGS='' + if [ "${KERNEL_CC}" != '' ] + then + ARGS="CC=\"${KERNEL_CC}\"" + fi + if [ "${KERNEL_LD}" != '' ] + then + ARGS="${ARGS} LD=\"${KERNEL_LD}\"" + fi + if [ "${KERNEL_AS}" != '' ] + then + ARGS="${ARGS} AS=\"${KERNEL_AS}\"" + fi + if [ -n "${KERNEL_ARCH}" ] + then + ARGS="${ARGS} ARCH=\"${KERNEL_ARCH}\"" + fi + if [ -n "${KERNEL_OUTPUTDIR}" -a "${KERNEL_OUTPUTDIR}" != "${KERNEL_DIR}" ] + then + ARGS="${ARGS} O=\"${KERNEL_OUTPUTDIR}\"" + fi + echo -n "${ARGS}" } compile_utils_args() { - local ARGS - ARGS='' + local ARGS + ARGS='' - if [ "${UTILS_ARCH}" != '' ] - then - ARGS="ARCH=\"${UTILS_ARCH}\"" - fi - if [ "${UTILS_CC}" != '' ] - then - ARGS="CC=\"${UTILS_CC}\"" - fi - if [ "${UTILS_LD}" != '' ] - then - ARGS="${ARGS} LD=\"${UTILS_LD}\"" - fi - if [ "${UTILS_AS}" != '' ] - then - ARGS="${ARGS} AS=\"${UTILS_AS}\"" - fi + if [ "${UTILS_ARCH}" != '' ] + then + ARGS="ARCH=\"${UTILS_ARCH}\"" + fi + if [ "${UTILS_CC}" != '' ] + then + ARGS="CC=\"${UTILS_CC}\"" + fi + if [ "${UTILS_LD}" != '' ] + then + ARGS="${ARGS} LD=\"${UTILS_LD}\"" + fi + if [ "${UTILS_AS}" != '' ] + then + ARGS="${ARGS} AS=\"${UTILS_AS}\"" + fi - echo -n "${ARGS}" + echo -n "${ARGS}" } export_utils_args() { - save_args - if [ "${UTILS_ARCH}" != '' ] - then - export ARCH="${UTILS_ARCH}" - fi - if [ "${UTILS_CC}" != '' ] - then - export CC="${UTILS_CC}" - fi - if [ "${UTILS_LD}" != '' ] - then - export LD="${UTILS_LD}" - fi - if [ "${UTILS_AS}" != '' ] - then - export AS="${UTILS_AS}" - fi + save_args + if [ "${UTILS_ARCH}" != '' ] + then + export ARCH="${UTILS_ARCH}" + fi + if [ "${UTILS_CC}" != '' ] + then + export CC="${UTILS_CC}" + fi + if [ "${UTILS_LD}" != '' ] + then + export LD="${UTILS_LD}" + fi + if [ "${UTILS_AS}" != '' ] + then + export AS="${UTILS_AS}" + fi } unset_utils_args() { - if [ "${UTILS_ARCH}" != '' ] - then - unset ARCH - fi - if [ "${UTILS_CC}" != '' ] - then - unset CC - fi - if [ "${UTILS_LD}" != '' ] - then - unset LD - fi - if [ "${UTILS_AS}" != '' ] - then - unset AS - fi - reset_args + if [ "${UTILS_ARCH}" != '' ] + then + unset ARCH + fi + if [ "${UTILS_CC}" != '' ] + then + unset CC + fi + if [ "${UTILS_LD}" != '' ] + then + unset LD + fi + if [ "${UTILS_AS}" != '' ] + then + unset AS + fi + reset_args } export_kernel_args() { - if [ "${KERNEL_CC}" != '' ] - then - export CC="${KERNEL_CC}" - fi - if [ "${KERNEL_LD}" != '' ] - then - export LD="${KERNEL_LD}" - fi - if [ "${KERNEL_AS}" != '' ] - then - export AS="${KERNEL_AS}" - fi + if [ "${KERNEL_CC}" != '' ] + then + export CC="${KERNEL_CC}" + fi + if [ "${KERNEL_LD}" != '' ] + then + export LD="${KERNEL_LD}" + fi + if [ "${KERNEL_AS}" != '' ] + then + export AS="${KERNEL_AS}" + fi } unset_kernel_args() { - if [ "${KERNEL_CC}" != '' ] - then - unset CC - fi - if [ "${KERNEL_LD}" != '' ] - then - unset LD - fi - if [ "${KERNEL_AS}" != '' ] - then - unset AS - fi + if [ "${KERNEL_CC}" != '' ] + then + unset CC + fi + if [ "${KERNEL_LD}" != '' ] + then + unset LD + fi + if [ "${KERNEL_AS}" != '' ] + then + unset AS + fi } save_args() { - if [ "${ARCH}" != '' ] - then - export ORIG_ARCH="${ARCH}" - fi - if [ "${CC}" != '' ] - then - export ORIG_CC="${CC}" - fi - if [ "${LD}" != '' ] - then - export ORIG_LD="${LD}" - fi - if [ "${AS}" != '' ] - then - export ORIG_AS="${AS}" - fi + if [ "${ARCH}" != '' ] + then + export ORIG_ARCH="${ARCH}" + fi + if [ "${CC}" != '' ] + then + export ORIG_CC="${CC}" + fi + if [ "${LD}" != '' ] + then + export ORIG_LD="${LD}" + fi + if [ "${AS}" != '' ] + then + export ORIG_AS="${AS}" + fi } reset_args() { - if [ "${ORIG_ARCH}" != '' ] - then - export ARCH="${ORIG_ARCH}" - unset ORIG_ARCH - fi - if [ "${ORIG_CC}" != '' ] - then - export CC="${ORIG_CC}" - unset ORIG_CC - fi - if [ "${ORIG_LD}" != '' ] - then - export LD="${ORIG_LD}" - unset ORIG_LD - fi - if [ "${ORIG_AS}" != '' ] - then - export AS="${ORIG_AS}" - unset ORIG_AS - fi + if [ "${ORIG_ARCH}" != '' ] + then + export ARCH="${ORIG_ARCH}" + unset ORIG_ARCH + fi + if [ "${ORIG_CC}" != '' ] + then + export CC="${ORIG_CC}" + unset ORIG_CC + fi + if [ "${ORIG_LD}" != '' ] + then + export LD="${ORIG_LD}" + unset ORIG_LD + fi + if [ "${ORIG_AS}" != '' ] + then + export AS="${ORIG_AS}" + unset ORIG_AS + fi } apply_patches() { - util=$1 - version=$2 + util=$1 + version=$2 - if [ -d "${GK_SHARE}/patches/${util}/${version}" ] - then - print_info 1 "${util}: >> Applying patches..." - for i in ${GK_SHARE}/patches/${util}/${version}/*{diff,patch} - do - [ -f "${i}" ] || continue - patch_success=0 - for j in `seq 0 5` - do - patch -p${j} --backup-if-mismatch -f < "${i}" >/dev/null - if [ $? = 0 ] - then - patch_success=1 - break - fi - done - if [ ${patch_success} -eq 1 ] - then - print_info 1 " - `basename ${i}`" - else - gen_die "could not apply patch ${i} for ${util}-${version}" - fi - done - fi + if [ -d "${GK_SHARE}/patches/${util}/${version}" ] + then + print_info 1 "${util}: >> Applying patches..." + for i in ${GK_SHARE}/patches/${util}/${version}/*{diff,patch} + do + [ -f "${i}" ] || continue + patch_success=0 + for j in `seq 0 5` + do + patch -p${j} --backup-if-mismatch -f < "${i}" >/dev/null + if [ $? = 0 ] + then + patch_success=1 + break + fi + done + if [ ${patch_success} -eq 1 ] + then + print_info 1 " - `basename ${i}`" + else + gen_die "could not apply patch ${i} for ${util}-${version}" + fi + done + fi } compile_generic() { - local RET - [ "$#" -lt '2' ] && - gen_die 'compile_generic(): improper usage!' - local target=${1} - local argstype=${2} + local RET + [ "$#" -lt '2' ] && + gen_die 'compile_generic(): improper usage!' + local target=${1} + local argstype=${2} - case "${argstype}" in - kernel|kernelruntask) - export_kernel_args - MAKE=${KERNEL_MAKE} - ;; - utils) - export_utils_args - MAKE=${UTILS_MAKE} - ;; - esac + case "${argstype}" in + kernel|kernelruntask) + export_kernel_args + MAKE=${KERNEL_MAKE} + ;; + utils) + export_utils_args + MAKE=${UTILS_MAKE} + ;; + esac - case "${argstype}" in - kernel|kernelruntask) ARGS="`compile_kernel_args`" ;; - utils) ARGS="`compile_utils_args`" ;; - *) ARGS="" ;; - esac - shift 2 + case "${argstype}" in + kernel|kernelruntask) ARGS="`compile_kernel_args`" ;; + utils) ARGS="`compile_utils_args`" ;; + *) ARGS="" ;; + esac + shift 2 - # the eval usage is needed in the next set of code - # as ARGS can contain spaces and quotes, eg: - # ARGS='CC="ccache gcc"' - if [ "${argstype}" == 'kernelruntask' ] - then - # Silent operation, forced -j1 - print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} -j1 ${ARGS} ${target} $*" 1 0 1 - eval ${MAKE} -s ${MAKEOPTS} -j1 "${ARGS}" ${target} $* - RET=$? - elif [ "${LOGLEVEL}" -gt "1" ] - then - # Output to stdout and logfile - print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $*" 1 0 1 - eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* 2>&1 | tee -a ${LOGFILE} - RET=${PIPESTATUS[0]} - else - # Output to logfile only - print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1} $*" 1 0 1 - eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* >> ${LOGFILE} 2>&1 - RET=$? - fi - [ ${RET} -ne 0 ] && - gen_die "Failed to compile the \"${target}\" target..." + # the eval usage is needed in the next set of code + # as ARGS can contain spaces and quotes, eg: + # ARGS='CC="ccache gcc"' + if [ "${argstype}" == 'kernelruntask' ] + then + # Silent operation, forced -j1 + print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} -j1 ${ARGS} ${target} $*" 1 0 1 + eval ${MAKE} -s ${MAKEOPTS} -j1 "${ARGS}" ${target} $* + RET=$? + elif [ "${LOGLEVEL}" -gt "1" ] + then + # Output to stdout and logfile + print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $*" 1 0 1 + eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* 2>&1 | tee -a ${LOGFILE} + RET=${PIPESTATUS[0]} + else + # Output to logfile only + print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1} $*" 1 0 1 + eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* >> ${LOGFILE} 2>&1 + RET=$? + fi + [ ${RET} -ne 0 ] && + gen_die "Failed to compile the \"${target}\" target..." - unset MAKE - unset ARGS + unset MAKE + unset ARGS - case "${argstype}" in - kernel) unset_kernel_args ;; - utils) unset_utils_args ;; - esac + case "${argstype}" in + kernel) unset_kernel_args ;; + utils) unset_utils_args ;; + esac } compile_modules() { - print_info 1 " >> Compiling ${KV} modules..." - cd ${KERNEL_DIR} - compile_generic modules kernel - export UNAME_MACHINE="${ARCH}" - [ "${INSTALL_MOD_PATH}" != '' ] && export INSTALL_MOD_PATH - MAKEOPTS="${MAKEOPTS} -j1" compile_generic "modules_install" kernel - print_info 1 " >> Generating module dependency data..." - if [ "${INSTALL_MOD_PATH}" != '' ] - then - depmod -a -e -F "${KERNEL_OUTPUTDIR}"/System.map -b "${INSTALL_MOD_PATH}" ${KV} - else - depmod -a -e -F "${KERNEL_OUTPUTDIR}"/System.map ${KV} - fi - unset UNAME_MACHINE + print_info 1 " >> Compiling ${KV} modules..." + cd ${KERNEL_DIR} + compile_generic modules kernel + export UNAME_MACHINE="${ARCH}" + [ "${INSTALL_MOD_PATH}" != '' ] && export INSTALL_MOD_PATH + MAKEOPTS="${MAKEOPTS} -j1" compile_generic "modules_install" kernel + print_info 1 " >> Generating module dependency data..." + if [ "${INSTALL_MOD_PATH}" != '' ] + then + depmod -a -e -F "${KERNEL_OUTPUTDIR}"/System.map -b "${INSTALL_MOD_PATH}" ${KV} + else + depmod -a -e -F "${KERNEL_OUTPUTDIR}"/System.map ${KV} + fi + unset UNAME_MACHINE } compile_kernel() { - [ "${KERNEL_MAKE}" = '' ] && - gen_die "KERNEL_MAKE undefined - I don't know how to compile a kernel for this arch!" - cd ${KERNEL_DIR} - local kernel_make_directive="${KERNEL_MAKE_DIRECTIVE}" - if [ "${KERNEL_MAKE_DIRECTIVE_OVERRIDE}" != "${DEFAULT_KERNEL_MAKE_DIRECTIVE_OVERRIDE}" ]; then - kernel_make_directive="${KERNEL_MAKE_DIRECTIVE_OVERRIDE}" - fi - print_info 1 " >> Compiling ${KV} ${kernel_make_directive/_install/ [ install ]/}..." - compile_generic "${kernel_make_directive}" kernel - if [ "${KERNEL_MAKE_DIRECTIVE_2}" != '' ] - then - print_info 1 " >> Starting supplimental compile of ${KV}: ${KERNEL_MAKE_DIRECTIVE_2}..." - compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel - fi + [ "${KERNEL_MAKE}" = '' ] && + gen_die "KERNEL_MAKE undefined - I don't know how to compile a kernel for this arch!" + cd ${KERNEL_DIR} + local kernel_make_directive="${KERNEL_MAKE_DIRECTIVE}" + if [ "${KERNEL_MAKE_DIRECTIVE_OVERRIDE}" != "${DEFAULT_KERNEL_MAKE_DIRECTIVE_OVERRIDE}" ]; then + kernel_make_directive="${KERNEL_MAKE_DIRECTIVE_OVERRIDE}" + fi + print_info 1 " >> Compiling ${KV} ${kernel_make_directive/_install/ [ install ]/}..." + compile_generic "${kernel_make_directive}" kernel + if [ "${KERNEL_MAKE_DIRECTIVE_2}" != '' ] + then + print_info 1 " >> Starting supplimental compile of ${KV}: ${KERNEL_MAKE_DIRECTIVE_2}..." + compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel + fi - local firmware_in_kernel_line=`fgrep CONFIG_FIRMWARE_IN_KERNEL "${KERNEL_OUTPUTDIR}"/.config` - if [ -n "${firmware_in_kernel_line}" -a "${firmware_in_kernel_line}" != CONFIG_FIRMWARE_IN_KERNEL=y ] - then - print_info 1 " >> Installing firmware ('make firmware_install') due to CONFIG_FIRMWARE_IN_KERNEL != y..." - MAKEOPTS="${MAKEOPTS} -j1" compile_generic "firmware_install" kernel - else - print_info 1 " >> Not installing firmware as it's included in the kernel already (CONFIG_FIRMWARE_IN_KERNEL=y)..." - fi + local firmware_in_kernel_line=`fgrep CONFIG_FIRMWARE_IN_KERNEL "${KERNEL_OUTPUTDIR}"/.config` + if [ -n "${firmware_in_kernel_line}" -a "${firmware_in_kernel_line}" != CONFIG_FIRMWARE_IN_KERNEL=y ] + then + print_info 1 " >> Installing firmware ('make firmware_install') due to CONFIG_FIRMWARE_IN_KERNEL != y..." + MAKEOPTS="${MAKEOPTS} -j1" compile_generic "firmware_install" kernel + else + print_info 1 " >> Not installing firmware as it's included in the kernel already (CONFIG_FIRMWARE_IN_KERNEL=y)..." + fi - local tmp_kernel_binary=$(find_kernel_binary ${KERNEL_BINARY_OVERRIDE:-${KERNEL_BINARY}}) - local tmp_kernel_binary2=$(find_kernel_binary ${KERNEL_BINARY_2}) - if [ -z "${tmp_kernel_binary}" ] - then - gen_die "Cannot locate kernel binary" - fi + local tmp_kernel_binary=$(find_kernel_binary ${KERNEL_BINARY_OVERRIDE:-${KERNEL_BINARY}}) + local tmp_kernel_binary2=$(find_kernel_binary ${KERNEL_BINARY_2}) + if [ -z "${tmp_kernel_binary}" ] + then + gen_die "Cannot locate kernel binary" + fi - if isTrue "${CMD_INSTALL}" - then - copy_image_with_preserve "kernel" \ - "${tmp_kernel_binary}" \ - "kernel-${KNAME}-${ARCH}-${KV}" + if isTrue "${CMD_INSTALL}" + then + copy_image_with_preserve "kernel" \ + "${tmp_kernel_binary}" \ + "kernel-${KNAME}-${ARCH}-${KV}" - copy_image_with_preserve "System.map" \ - "System.map" \ - "System.map-${KNAME}-${ARCH}-${KV}" + copy_image_with_preserve "System.map" \ + "System.map" \ + "System.map-${KNAME}-${ARCH}-${KV}" - if isTrue "${GENZIMAGE}" - then - copy_image_with_preserve "kernelz" \ - "${tmp_kernel_binary2}" \ - "kernelz-${KV}" - fi - else - cp "${tmp_kernel_binary}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" || - gen_die "Could not copy the kernel binary to ${TMPDIR}!" - cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" || - gen_die "Could not copy System.map to ${TMPDIR}!" - if isTrue "${GENZIMAGE}" - then - cp "${tmp_kernel_binary2}" "${TMPDIR}/kernelz-${KV}" || - gen_die "Could not copy the kernelz binary to ${TMPDIR}!" - fi - fi + if isTrue "${GENZIMAGE}" + then + copy_image_with_preserve "kernelz" \ + "${tmp_kernel_binary2}" \ + "kernelz-${KV}" + fi + else + cp "${tmp_kernel_binary}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" || + gen_die "Could not copy the kernel binary to ${TMPDIR}!" + cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" || + gen_die "Could not copy System.map to ${TMPDIR}!" + if isTrue "${GENZIMAGE}" + then + cp "${tmp_kernel_binary2}" "${TMPDIR}/kernelz-${KV}" || + gen_die "Could not copy the kernelz binary to ${TMPDIR}!" + fi + fi } compile_busybox() { - [ -f "${BUSYBOX_SRCTAR}" ] || - gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!" + [ -f "${BUSYBOX_SRCTAR}" ] || + gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!" - if [ -n "${BUSYBOX_CONFIG}" ] - then - [ -f "${BUSYBOX_CONFIG}" ] || - gen_die "Could not find busybox config file: ${BUSYBOX_CONFIG}" - elif isTrue "${NETBOOT}" && [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")" ] - then - BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")" - elif isTrue "${NETBOOT}" && [ -f "${GK_SHARE}/netboot/busy-config" ] - then - BUSYBOX_CONFIG="${GK_SHARE}/netboot/busy-config" - elif [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")" ] - then - BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")" - elif [ -f "${GK_SHARE}/defaults/busy-config" ] - then - BUSYBOX_CONFIG="${GK_SHARE}/defaults/busy-config" - else - gen_die "Could not find a busybox config file" - fi + if [ -n "${BUSYBOX_CONFIG}" ] + then + [ -f "${BUSYBOX_CONFIG}" ] || + gen_die "Could not find busybox config file: ${BUSYBOX_CONFIG}" + elif isTrue "${NETBOOT}" && [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")" ] + then + BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")" + elif isTrue "${NETBOOT}" && [ -f "${GK_SHARE}/netboot/busy-config" ] + then + BUSYBOX_CONFIG="${GK_SHARE}/netboot/busy-config" + elif [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")" ] + then + BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")" + elif [ -f "${GK_SHARE}/defaults/busy-config" ] + then + BUSYBOX_CONFIG="${GK_SHARE}/defaults/busy-config" + else + gen_die "Could not find a busybox config file" + fi - # Delete cache if stored config's MD5 does not match one to be used - if [ -f "${BUSYBOX_BINCACHE}" ] - then - oldconfig_md5=$(tar -xjf "${BUSYBOX_BINCACHE}" -O .config.gk_orig 2>/dev/null | md5sum) - newconfig_md5=$(md5sum < "${BUSYBOX_CONFIG}") - if [ "${oldconfig_md5}" != "${newconfig_md5}" ] - then - print_info 1 "busybox: >> Removing stale cache..." - rm -rf "${BUSYBOX_BINCACHE}" - else - print_info 1 "busybox: >> Using cache" - fi - fi + # Delete cache if stored config's MD5 does not match one to be used + if [ -f "${BUSYBOX_BINCACHE}" ] + then + oldconfig_md5=$(tar -xjf "${BUSYBOX_BINCACHE}" -O .config.gk_orig 2>/dev/null | md5sum) + newconfig_md5=$(md5sum < "${BUSYBOX_CONFIG}") + if [ "${oldconfig_md5}" != "${newconfig_md5}" ] + then + print_info 1 "busybox: >> Removing stale cache..." + rm -rf "${BUSYBOX_BINCACHE}" + else + print_info 1 "busybox: >> Using cache" + fi + fi - if [ ! -f "${BUSYBOX_BINCACHE}" ] - then - cd "${TEMP}" - rm -rf "${BUSYBOX_DIR}" > /dev/null - /bin/tar -jxpf ${BUSYBOX_SRCTAR} || - gen_die 'Could not extract busybox source tarball!' - [ -d "${BUSYBOX_DIR}" ] || - gen_die "Busybox directory ${BUSYBOX_DIR} is invalid!" - cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config" - cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config.gk_orig" - cd "${BUSYBOX_DIR}" - apply_patches busybox ${BUSYBOX_VER} - print_info 1 'busybox: >> Configuring...' - yes '' 2>/dev/null | compile_generic oldconfig utils + if [ ! -f "${BUSYBOX_BINCACHE}" ] + then + cd "${TEMP}" + rm -rf "${BUSYBOX_DIR}" > /dev/null + /bin/tar -jxpf ${BUSYBOX_SRCTAR} || + gen_die 'Could not extract busybox source tarball!' + [ -d "${BUSYBOX_DIR}" ] || + gen_die "Busybox directory ${BUSYBOX_DIR} is invalid!" + cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config" + cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config.gk_orig" + cd "${BUSYBOX_DIR}" + apply_patches busybox ${BUSYBOX_VER} + print_info 1 'busybox: >> Configuring...' + yes '' 2>/dev/null | compile_generic oldconfig utils - print_info 1 'busybox: >> Compiling...' - compile_generic all utils - print_info 1 'busybox: >> Copying to cache...' - [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] || - gen_die 'Busybox executable does not exist!' - strip "${TEMP}/${BUSYBOX_DIR}/busybox" || - gen_die 'Could not strip busybox binary!' - tar -cj -C "${TEMP}/${BUSYBOX_DIR}" -f "${BUSYBOX_BINCACHE}" busybox .config .config.gk_orig || - gen_die 'Could not create the busybox bincache!' + print_info 1 'busybox: >> Compiling...' + compile_generic all utils + print_info 1 'busybox: >> Copying to cache...' + [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] || + gen_die 'Busybox executable does not exist!' + strip "${TEMP}/${BUSYBOX_DIR}/busybox" || + gen_die 'Could not strip busybox binary!' + tar -cj -C "${TEMP}/${BUSYBOX_DIR}" -f "${BUSYBOX_BINCACHE}" busybox .config .config.gk_orig || + gen_die 'Could not create the busybox bincache!' - cd "${TEMP}" - rm -rf "${BUSYBOX_DIR}" > /dev/null - fi + cd "${TEMP}" + rm -rf "${BUSYBOX_DIR}" > /dev/null + fi } diff --git a/gen_configkernel.sh b/gen_configkernel.sh index 3b5a0ef..27ff7f3 100755 --- a/gen_configkernel.sh +++ b/gen_configkernel.sh @@ -3,106 +3,106 @@ # Fills variable KERNEL_CONFIG determine_config_file() { - if [ "${CMD_KERNEL_CONFIG}" != "" ] - then - KERNEL_CONFIG="${CMD_KERNEL_CONFIG}" - elif [ -f "/etc/kernels/kernel-config-${ARCH}-${KV}" ] - then - KERNEL_CONFIG="/etc/kernels/kernel-config-${ARCH}-${KV}" - elif [ -f "${GK_SHARE}/arch/${ARCH}/kernel-config-${KV}" ] - then - KERNEL_CONFIG="${GK_SHARE}/arch/${ARCH}/kernel-config-${KV}" - elif [ "${DEFAULT_KERNEL_CONFIG}" != "" -a -f "${DEFAULT_KERNEL_CONFIG}" ] - then - KERNEL_CONFIG="${DEFAULT_KERNEL_CONFIG}" - elif [ -f "${GK_SHARE}/arch/${ARCH}/kernel-config-${VER}.${PAT}" ] - then - KERNEL_CONFIG="${GK_SHARE}/arch/${ARCH}/kernel-config-${VER}.${PAT}" - elif [ -f "${GK_SHARE}/arch/${ARCH}/kernel-config" ] - then - KERNEL_CONFIG="${GK_SHARE}/arch/${ARCH}/kernel-config" - else - gen_die 'Error: No kernel .config specified, or file not found!' - fi + if [ "${CMD_KERNEL_CONFIG}" != "" ] + then + KERNEL_CONFIG="${CMD_KERNEL_CONFIG}" + elif [ -f "/etc/kernels/kernel-config-${ARCH}-${KV}" ] + then + KERNEL_CONFIG="/etc/kernels/kernel-config-${ARCH}-${KV}" + elif [ -f "${GK_SHARE}/arch/${ARCH}/kernel-config-${KV}" ] + then + KERNEL_CONFIG="${GK_SHARE}/arch/${ARCH}/kernel-config-${KV}" + elif [ "${DEFAULT_KERNEL_CONFIG}" != "" -a -f "${DEFAULT_KERNEL_CONFIG}" ] + then + KERNEL_CONFIG="${DEFAULT_KERNEL_CONFIG}" + elif [ -f "${GK_SHARE}/arch/${ARCH}/kernel-config-${VER}.${PAT}" ] + then + KERNEL_CONFIG="${GK_SHARE}/arch/${ARCH}/kernel-config-${VER}.${PAT}" + elif [ -f "${GK_SHARE}/arch/${ARCH}/kernel-config" ] + then + KERNEL_CONFIG="${GK_SHARE}/arch/${ARCH}/kernel-config" + else + gen_die 'Error: No kernel .config specified, or file not found!' + fi KERNEL_CONFIG="$(readlink -f "${KERNEL_CONFIG}")" } config_kernel() { - determine_config_file - cd "${KERNEL_DIR}" || gen_die 'Could not switch to the kernel directory!' + determine_config_file + cd "${KERNEL_DIR}" || gen_die 'Could not switch to the kernel directory!' - # Backup current kernel .config - if isTrue "${MRPROPER}" || [ ! -f "${KERNEL_OUTPUTDIR}/.config" ] - then - print_info 1 "kernel: Using config from ${KERNEL_CONFIG}" - if [ -f "${KERNEL_OUTPUTDIR}/.config" ] - then - NOW=`date +--%Y-%m-%d--%H-%M-%S` - cp "${KERNEL_OUTPUTDIR}/.config" "${KERNEL_OUTPUTDIR}/.config${NOW}.bak" \ - || gen_die "Could not backup kernel config (${KERNEL_OUTPUTDIR}/.config)" - print_info 1 " Previous config backed up to .config${NOW}.bak" - fi - fi + # Backup current kernel .config + if isTrue "${MRPROPER}" || [ ! -f "${KERNEL_OUTPUTDIR}/.config" ] + then + print_info 1 "kernel: Using config from ${KERNEL_CONFIG}" + if [ -f "${KERNEL_OUTPUTDIR}/.config" ] + then + NOW=`date +--%Y-%m-%d--%H-%M-%S` + cp "${KERNEL_OUTPUTDIR}/.config" "${KERNEL_OUTPUTDIR}/.config${NOW}.bak" \ + || gen_die "Could not backup kernel config (${KERNEL_OUTPUTDIR}/.config)" + print_info 1 " Previous config backed up to .config${NOW}.bak" + fi + fi - if isTrue ${MRPROPER} - then - print_info 1 'kernel: >> Running mrproper...' - compile_generic mrproper kernel - else - print_info 1 "kernel: --mrproper is disabled; not running 'make mrproper'." - fi + if isTrue ${MRPROPER} + then + print_info 1 'kernel: >> Running mrproper...' + compile_generic mrproper kernel + else + print_info 1 "kernel: --mrproper is disabled; not running 'make mrproper'." + fi - # If we're not cleaning a la mrproper, then we don't want to try to overwrite the configs - # or we might remove configurations someone is trying to test. - if isTrue "${MRPROPER}" || [ ! -f "${KERNEL_OUTPUTDIR}/.config" ] - then - local message='Could not copy configuration file!' - if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then - # Support --kernel-config=/proc/config.gz, mainly - zcat "${KERNEL_CONFIG}" > "${KERNEL_OUTPUTDIR}/.config" || gen_die "${message}" - else - cp "${KERNEL_CONFIG}" "${KERNEL_OUTPUTDIR}/.config" || gen_die "${message}" - fi - fi + # If we're not cleaning a la mrproper, then we don't want to try to overwrite the configs + # or we might remove configurations someone is trying to test. + if isTrue "${MRPROPER}" || [ ! -f "${KERNEL_OUTPUTDIR}/.config" ] + then + local message='Could not copy configuration file!' + if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then + # Support --kernel-config=/proc/config.gz, mainly + zcat "${KERNEL_CONFIG}" > "${KERNEL_OUTPUTDIR}/.config" || gen_die "${message}" + else + cp "${KERNEL_CONFIG}" "${KERNEL_OUTPUTDIR}/.config" || gen_die "${message}" + fi + fi - if isTrue "${OLDCONFIG}" - then - print_info 1 ' >> Running oldconfig...' - yes '' 2>/dev/null | compile_generic oldconfig kernel 2>/dev/null - else - print_info 1 "kernel: --oldconfig is disabled; not running 'make oldconfig'." - fi - if isTrue "${CLEAN}" - then - print_info 1 'kernel: >> Cleaning...' - compile_generic clean kernel - else - print_info 1 "kernel: --clean is disabled; not running 'make clean'." - fi + if isTrue "${OLDCONFIG}" + then + print_info 1 ' >> Running oldconfig...' + yes '' 2>/dev/null | compile_generic oldconfig kernel 2>/dev/null + else + print_info 1 "kernel: --oldconfig is disabled; not running 'make oldconfig'." + fi + if isTrue "${CLEAN}" + then + print_info 1 'kernel: >> Cleaning...' + compile_generic clean kernel + else + print_info 1 "kernel: --clean is disabled; not running 'make clean'." + fi - if isTrue ${MENUCONFIG} - then - print_info 1 'kernel: >> Invoking menuconfig...' - compile_generic menuconfig kernelruntask - [ "$?" ] || gen_die 'Error: menuconfig failed!' - elif isTrue ${NCONFIG} - then - print_info 1 'kernel: >> Invoking nconfig...' - compile_generic nconfig kernelruntask - [ "$?" ] || gen_die 'Error: nconfig failed!' - elif isTrue ${CMD_GCONFIG} - then - print_info 1 'kernel: >> Invoking gconfig...' - compile_generic gconfig kernel - [ "$?" ] || gen_die 'Error: gconfig failed!' + if isTrue ${MENUCONFIG} + then + print_info 1 'kernel: >> Invoking menuconfig...' + compile_generic menuconfig kernelruntask + [ "$?" ] || gen_die 'Error: menuconfig failed!' + elif isTrue ${NCONFIG} + then + print_info 1 'kernel: >> Invoking nconfig...' + compile_generic nconfig kernelruntask + [ "$?" ] || gen_die 'Error: nconfig failed!' + elif isTrue ${CMD_GCONFIG} + then + print_info 1 'kernel: >> Invoking gconfig...' + compile_generic gconfig kernel + [ "$?" ] || gen_die 'Error: gconfig failed!' - CMD_XCONFIG=0 - fi + CMD_XCONFIG=0 + fi - if isTrue ${CMD_XCONFIG} - then - print_info 1 'kernel: >> Invoking xconfig...' - compile_generic xconfig kernel - [ "$?" ] || gen_die 'Error: xconfig failed!' - fi + if isTrue ${CMD_XCONFIG} + then + print_info 1 'kernel: >> Invoking xconfig...' + compile_generic xconfig kernel + [ "$?" ] || gen_die 'Error: xconfig failed!' + fi } diff --git a/gen_determineargs.sh b/gen_determineargs.sh index 36c9388..387c6a8 100755 --- a/gen_determineargs.sh +++ b/gen_determineargs.sh @@ -2,216 +2,216 @@ # $Id$ get_KV() { - if [ "${KERNEL_SOURCES}" = '0' -a -e "${KERNCACHE}" ] - then - /bin/tar -xj -C ${TEMP} -f ${KERNCACHE} kerncache.config - if [ -e ${TEMP}/kerncache.config ] - then - VER=`grep ^VERSION\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'` - PAT=`grep ^PATCHLEVEL\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'` - SUB=`grep ^SUBLEVEL\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'` - EXV=`grep ^EXTRAVERSION\ \= ${TEMP}/kerncache.config | sed -e "s/EXTRAVERSION =//" -e "s/ //g"` - LOV=`grep ^CONFIG_LOCALVERSION\= ${TEMP}/kerncache.config | sed -e "s/CONFIG_LOCALVERSION=\"\(.*\)\"/\1/"` - KV=${VER}.${PAT}.${SUB}${EXV}${LOV} - else - gen_die "Could not find kerncache.config in the kernel cache! Exiting." - fi - else - # Configure the kernel - # If BUILD_KERNEL=0 then assume --no-clean, menuconfig is cleared - - if [ ! -f "${KERNEL_DIR}"/Makefile ] - then - gen_die "Kernel Makefile (${KERNEL_DIR}/Makefile) missing. Maybe re-install the kernel sources." - fi - - VER=`grep ^VERSION\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'` - PAT=`grep ^PATCHLEVEL\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'` - SUB=`grep ^SUBLEVEL\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'` - EXV=`grep ^EXTRAVERSION\ \= ${KERNEL_DIR}/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g" -e 's/\$([a-z]*)//gi'` - - if [ -z "${SUB}" ] - then - # Handle O= build directories - KERNEL_SOURCE_DIR=`grep ^MAKEARGS\ \:\= ${KERNEL_DIR}/Makefile | awk '{ print $4 };'` - [ -z "${KERNEL_SOURCE_DIR}" ] && gen_die "Deriving \${KERNEL_SOURCE_DIR} failed" - SUB=`grep ^SUBLEVEL\ \= ${KERNEL_SOURCE_DIR}/Makefile | awk '{ print $3 };'` - EXV=`grep ^EXTRAVERSION\ \= ${KERNEL_SOURCE_DIR}/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g" -e 's/\$([a-z]*)//gi'` - fi - - cd ${KERNEL_DIR} - #compile_generic prepare kernel > /dev/null 2>&1 - cd - > /dev/null 2>&1 - [ -f "${KERNEL_DIR}/include/linux/version.h" ] && \ - VERSION_SOURCE="${KERNEL_DIR}/include/linux/version.h" - [ -f "${KERNEL_DIR}/include/linux/utsrelease.h" ] && \ - VERSION_SOURCE="${KERNEL_DIR}/include/linux/utsrelease.h" - # Handle new-style releases where version.h doesn't have UTS_RELEASE - if [ -f ${KERNEL_DIR}/include/config/kernel.release ] - then - UTS_RELEASE=`cat ${KERNEL_DIR}/include/config/kernel.release` - LOV=`echo ${UTS_RELEASE}|sed -e "s/${VER}.${PAT}.${SUB}${EXV}//"` - KV=${VER}.${PAT}.${SUB}${EXV}${LOV} - elif [ -n "${VERSION_SOURCE}" ] - then - UTS_RELEASE=`grep UTS_RELEASE ${VERSION_SOURCE} | sed -e 's/#define UTS_RELEASE "\(.*\)"/\1/'` - LOV=`echo ${UTS_RELEASE}|sed -e "s/${VER}.${PAT}.${SUB}${EXV}//"` - KV=${VER}.${PAT}.${SUB}${EXV}${LOV} - else - determine_config_file - LCV=`grep ^CONFIG_LOCALVERSION= "${KERNEL_CONFIG}" | sed -r -e "s/.*=\"(.*)\"/\1/"` - KV=${VER}.${PAT}.${SUB}${EXV}${LCV} - fi - fi + if [ "${KERNEL_SOURCES}" = '0' -a -e "${KERNCACHE}" ] + then + /bin/tar -xj -C ${TEMP} -f ${KERNCACHE} kerncache.config + if [ -e ${TEMP}/kerncache.config ] + then + VER=`grep ^VERSION\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'` + PAT=`grep ^PATCHLEVEL\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'` + SUB=`grep ^SUBLEVEL\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'` + EXV=`grep ^EXTRAVERSION\ \= ${TEMP}/kerncache.config | sed -e "s/EXTRAVERSION =//" -e "s/ //g"` + LOV=`grep ^CONFIG_LOCALVERSION\= ${TEMP}/kerncache.config | sed -e "s/CONFIG_LOCALVERSION=\"\(.*\)\"/\1/"` + KV=${VER}.${PAT}.${SUB}${EXV}${LOV} + else + gen_die "Could not find kerncache.config in the kernel cache! Exiting." + fi + else + # Configure the kernel + # If BUILD_KERNEL=0 then assume --no-clean, menuconfig is cleared + + if [ ! -f "${KERNEL_DIR}"/Makefile ] + then + gen_die "Kernel Makefile (${KERNEL_DIR}/Makefile) missing. Maybe re-install the kernel sources." + fi + + VER=`grep ^VERSION\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'` + PAT=`grep ^PATCHLEVEL\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'` + SUB=`grep ^SUBLEVEL\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'` + EXV=`grep ^EXTRAVERSION\ \= ${KERNEL_DIR}/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g" -e 's/\$([a-z]*)//gi'` + + if [ -z "${SUB}" ] + then + # Handle O= build directories + KERNEL_SOURCE_DIR=`grep ^MAKEARGS\ \:\= ${KERNEL_DIR}/Makefile | awk '{ print $4 };'` + [ -z "${KERNEL_SOURCE_DIR}" ] && gen_die "Deriving \${KERNEL_SOURCE_DIR} failed" + SUB=`grep ^SUBLEVEL\ \= ${KERNEL_SOURCE_DIR}/Makefile | awk '{ print $3 };'` + EXV=`grep ^EXTRAVERSION\ \= ${KERNEL_SOURCE_DIR}/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g" -e 's/\$([a-z]*)//gi'` + fi + + cd ${KERNEL_DIR} + #compile_generic prepare kernel > /dev/null 2>&1 + cd - > /dev/null 2>&1 + [ -f "${KERNEL_DIR}/include/linux/version.h" ] && \ + VERSION_SOURCE="${KERNEL_DIR}/include/linux/version.h" + [ -f "${KERNEL_DIR}/include/linux/utsrelease.h" ] && \ + VERSION_SOURCE="${KERNEL_DIR}/include/linux/utsrelease.h" + # Handle new-style releases where version.h doesn't have UTS_RELEASE + if [ -f ${KERNEL_DIR}/include/config/kernel.release ] + then + UTS_RELEASE=`cat ${KERNEL_DIR}/include/config/kernel.release` + LOV=`echo ${UTS_RELEASE}|sed -e "s/${VER}.${PAT}.${SUB}${EXV}//"` + KV=${VER}.${PAT}.${SUB}${EXV}${LOV} + elif [ -n "${VERSION_SOURCE}" ] + then + UTS_RELEASE=`grep UTS_RELEASE ${VERSION_SOURCE} | sed -e 's/#define UTS_RELEASE "\(.*\)"/\1/'` + LOV=`echo ${UTS_RELEASE}|sed -e "s/${VER}.${PAT}.${SUB}${EXV}//"` + KV=${VER}.${PAT}.${SUB}${EXV}${LOV} + else + determine_config_file + LCV=`grep ^CONFIG_LOCALVERSION= "${KERNEL_CONFIG}" | sed -r -e "s/.*=\"(.*)\"/\1/"` + KV=${VER}.${PAT}.${SUB}${EXV}${LCV} + fi + fi } determine_real_args() { - print_info 4 "Resolving config file, command line, and arch default settings." - - # Dest / Config File Command Line Arch Default - # ------------------ ------------ ------------ - set_config_with_override STRING LOGFILE CMD_LOGFILE - set_config_with_override STRING KERNEL_DIR CMD_KERNEL_DIR "${DEFAULT_KERNEL_SOURCE}" - set_config_with_override BOOL KERNEL_SOURCES CMD_KERNEL_SOURCES "yes" - set_config_with_override STRING KNAME CMD_KERNNAME "genkernel" - - set_config_with_override STRING COMPRESS_INITRD CMD_COMPRESS_INITRD "$DEFAULT_COMPRESS_INITRD" - set_config_with_override STRING COMPRESS_INITRD_TYPE CMD_COMPRESS_INITRD_TYPE "$DEFAULT_COMPRESS_INITRD_TYPE" - set_config_with_override STRING MAKEOPTS CMD_MAKEOPTS "$DEFAULT_MAKEOPTS" - set_config_with_override STRING KERNEL_MAKE CMD_KERNEL_MAKE "$DEFAULT_KERNEL_MAKE" - set_config_with_override STRING UTILS_MAKE CMD_UTILS_MAKE "$DEFAULT_UTILS_MAKE" - set_config_with_override STRING KERNEL_CC CMD_KERNEL_CC "$DEFAULT_KERNEL_CC" - set_config_with_override STRING KERNEL_LD CMD_KERNEL_LD "$DEFAULT_KERNEL_LD" - set_config_with_override STRING KERNEL_AS CMD_KERNEL_AS "$DEFAULT_KERNEL_AS" - set_config_with_override STRING UTILS_CC CMD_UTILS_CC "$DEFAULT_UTILS_CC" - set_config_with_override STRING UTILS_LD CMD_UTILS_LD "$DEFAULT_UTILS_LD" - set_config_with_override STRING UTILS_AS CMD_UTILS_AS "$DEFAULT_UTILS_AS" - - set_config_with_override STRING BOOTDIR CMD_BOOTDIR "/boot" - set_config_with_override STRING KERNEL_OUTPUTDIR CMD_KERNEL_OUTPUTDIR "${KERNEL_DIR}" - set_config_with_override STRING MODPROBEDIR CMD_MODPROBEDIR "/etc/modprobe.d" - - set_config_with_override BOOL SPLASH CMD_SPLASH - set_config_with_override BOOL PLYMOUTH CMD_PLYMOUTH - set_config_with_override BOOL POSTCLEAR CMD_POSTCLEAR - set_config_with_override BOOL MRPROPER CMD_MRPROPER - set_config_with_override BOOL MENUCONFIG CMD_MENUCONFIG - set_config_with_override BOOL NCONFIG CMD_NCONFIG - set_config_with_override BOOL CLEAN CMD_CLEAN - - set_config_with_override STRING MINKERNPACKAGE CMD_MINKERNPACKAGE - set_config_with_override STRING MODULESPACKAGE CMD_MODULESPACKAGE - set_config_with_override STRING KERNCACHE CMD_KERNCACHE - set_config_with_override BOOL RAMDISKMODULES CMD_RAMDISKMODULES "yes" - set_config_with_override BOOL ALLRAMDISKMODULES CMD_ALLRAMDISKMODULES - set_config_with_override STRING INITRAMFS_OVERLAY CMD_INITRAMFS_OVERLAY - set_config_with_override BOOL MOUNTBOOT CMD_MOUNTBOOT - set_config_with_override BOOL BUILD_STATIC CMD_STATIC - set_config_with_override BOOL SAVE_CONFIG CMD_SAVE_CONFIG - set_config_with_override BOOL SYMLINK CMD_SYMLINK - set_config_with_override STRING INSTALL_MOD_PATH CMD_INSTALL_MOD_PATH - set_config_with_override BOOL OLDCONFIG CMD_OLDCONFIG - set_config_with_override BOOL UDEV CMD_UDEV - set_config_with_override BOOL LVM CMD_LVM - set_config_with_override BOOL DMRAID CMD_DMRAID - set_config_with_override BOOL ISCSI CMD_ISCSI - set_config_with_override BOOL BUSYBOX CMD_BUSYBOX "yes" - set_config_with_override BOOL NETBOOT CMD_NETBOOT - set_config_with_override STRING REAL_ROOT CMD_REAL_ROOT - set_config_with_override BOOL LUKS CMD_LUKS - set_config_with_override BOOL GPG CMD_GPG - set_config_with_override BOOL MDADM CMD_MDADM - set_config_with_override STRING MDADM_CONFIG CMD_MDADM_CONFIG - set_config_with_override BOOL E2FSPROGS CMD_E2FSPROGS "no" - set_config_with_override BOOL ZFS CMD_ZFS - set_config_with_override BOOL BTRFS CMD_BTRFS - set_config_with_override BOOL VIRTIO CMD_VIRTIO "no" - set_config_with_override BOOL MULTIPATH CMD_MULTIPATH - set_config_with_override BOOL FIRMWARE CMD_FIRMWARE - set_config_with_override STRING FIRMWARE_DIR CMD_FIRMWARE_DIR "/lib/firmware" - set_config_with_override STRING FIRMWARE_FILES CMD_FIRMWARE_FILES - set_config_with_override BOOL INTEGRATED_INITRAMFS CMD_INTEGRATED_INITRAMFS - set_config_with_override BOOL GENZIMAGE CMD_GENZIMAGE - set_config_with_override BOOL KEYMAP CMD_KEYMAP "yes" - set_config_with_override BOOL DOKEYMAPAUTO CMD_DOKEYMAPAUTO - set_config_with_override STRING BUSYBOX_CONFIG CMD_BUSYBOX_CONFIG - set_config_with_override BOOL INSTALL CMD_INSTALL "yes" - - BOOTDIR=`arch_replace "${BOOTDIR}"` - BOOTDIR=${BOOTDIR%/} # Remove any trailing slash - MODPROBEDIR=${MODPROBEDIR%/} # Remove any trailing slash - - CACHE_DIR=`arch_replace "${CACHE_DIR}"` - BUSYBOX_BINCACHE=`cache_replace "${BUSYBOX_BINCACHE}"` - - DEFAULT_KERNEL_CONFIG=`arch_replace "${DEFAULT_KERNEL_CONFIG}"` - BUSYBOX_CONFIG=`arch_replace "${BUSYBOX_CONFIG}"` - BUSYBOX_BINCACHE=`arch_replace "${BUSYBOX_BINCACHE}"` - - if [ -n "${CMD_BOOTLOADER}" ] - then - BOOTLOADER="${CMD_BOOTLOADER}" - if [ "${CMD_BOOTLOADER}" != "${CMD_BOOTLOADER/:/}" ] - then - BOOTFS=`echo "${CMD_BOOTLOADER}" | cut -f2- -d:` - BOOTLOADER=`echo "${CMD_BOOTLOADER}" | cut -f1 -d:` - fi - fi - - if [ "${KERNEL_SOURCES}" != "0" ] - then - if [ ! -d ${KERNEL_DIR} ] - then - gen_die "kernel source directory \"${KERNEL_DIR}\" was not found!" - fi - fi - - if [ -z "${KERNCACHE}" ] - then - if [ "${KERNEL_DIR}" = '' -a "${KERNEL_SOURCES}" != "0" ] - then - gen_die 'No kernel source directory!' - fi - if [ ! -e "${KERNEL_DIR}" -a "${KERNEL_SOURCES}" != "0" ] - then - gen_die 'No kernel source directory!' - fi - else - if [ "${KERNEL_DIR}" = '' ] - then - gen_die 'Kernel Cache specified but no kernel tree to verify against!' - fi - fi - - # Special case: If --no-clean is specified on the command line, - # imply --no-mrproper. - if [ "${CMD_CLEAN}" != '' ] - then - if ! isTrue ${CLEAN} - then - MRPROPER=0 - fi - fi - - if [ -n "${MINKERNPACKAGE}" ] - then - mkdir -p `dirname ${MINKERNPACKAGE}` - fi - - if [ -n "${MODULESPACKAGE}" ] - then - mkdir -p `dirname ${MODULESPACKAGE}` - fi - - if [ -n "${KERNCACHE}" ] - then - mkdir -p `dirname ${KERNCACHE}` - fi - - if ! isTrue "${BUILD_RAMDISK}" - then - INTEGRATED_INITRAMFS=0 - fi - - get_KV + print_info 4 "Resolving config file, command line, and arch default settings." + + # Dest / Config File Command Line Arch Default + # ------------------ ------------ ------------ + set_config_with_override STRING LOGFILE CMD_LOGFILE + set_config_with_override STRING KERNEL_DIR CMD_KERNEL_DIR "${DEFAULT_KERNEL_SOURCE}" + set_config_with_override BOOL KERNEL_SOURCES CMD_KERNEL_SOURCES "yes" + set_config_with_override STRING KNAME CMD_KERNNAME "genkernel" + + set_config_with_override STRING COMPRESS_INITRD CMD_COMPRESS_INITRD "$DEFAULT_COMPRESS_INITRD" + set_config_with_override STRING COMPRESS_INITRD_TYPE CMD_COMPRESS_INITRD_TYPE "$DEFAULT_COMPRESS_INITRD_TYPE" + set_config_with_override STRING MAKEOPTS CMD_MAKEOPTS "$DEFAULT_MAKEOPTS" + set_config_with_override STRING KERNEL_MAKE CMD_KERNEL_MAKE "$DEFAULT_KERNEL_MAKE" + set_config_with_override STRING UTILS_MAKE CMD_UTILS_MAKE "$DEFAULT_UTILS_MAKE" + set_config_with_override STRING KERNEL_CC CMD_KERNEL_CC "$DEFAULT_KERNEL_CC" + set_config_with_override STRING KERNEL_LD CMD_KERNEL_LD "$DEFAULT_KERNEL_LD" + set_config_with_override STRING KERNEL_AS CMD_KERNEL_AS "$DEFAULT_KERNEL_AS" + set_config_with_override STRING UTILS_CC CMD_UTILS_CC "$DEFAULT_UTILS_CC" + set_config_with_override STRING UTILS_LD CMD_UTILS_LD "$DEFAULT_UTILS_LD" + set_config_with_override STRING UTILS_AS CMD_UTILS_AS "$DEFAULT_UTILS_AS" + + set_config_with_override STRING BOOTDIR CMD_BOOTDIR "/boot" + set_config_with_override STRING KERNEL_OUTPUTDIR CMD_KERNEL_OUTPUTDIR "${KERNEL_DIR}" + set_config_with_override STRING MODPROBEDIR CMD_MODPROBEDIR "/etc/modprobe.d" + + set_config_with_override BOOL SPLASH CMD_SPLASH + set_config_with_override BOOL PLYMOUTH CMD_PLYMOUTH + set_config_with_override BOOL POSTCLEAR CMD_POSTCLEAR + set_config_with_override BOOL MRPROPER CMD_MRPROPER + set_config_with_override BOOL MENUCONFIG CMD_MENUCONFIG + set_config_with_override BOOL NCONFIG CMD_NCONFIG + set_config_with_override BOOL CLEAN CMD_CLEAN + + set_config_with_override STRING MINKERNPACKAGE CMD_MINKERNPACKAGE + set_config_with_override STRING MODULESPACKAGE CMD_MODULESPACKAGE + set_config_with_override STRING KERNCACHE CMD_KERNCACHE + set_config_with_override BOOL RAMDISKMODULES CMD_RAMDISKMODULES "yes" + set_config_with_override BOOL ALLRAMDISKMODULES CMD_ALLRAMDISKMODULES + set_config_with_override STRING INITRAMFS_OVERLAY CMD_INITRAMFS_OVERLAY + set_config_with_override BOOL MOUNTBOOT CMD_MOUNTBOOT + set_config_with_override BOOL BUILD_STATIC CMD_STATIC + set_config_with_override BOOL SAVE_CONFIG CMD_SAVE_CONFIG + set_config_with_override BOOL SYMLINK CMD_SYMLINK + set_config_with_override STRING INSTALL_MOD_PATH CMD_INSTALL_MOD_PATH + set_config_with_override BOOL OLDCONFIG CMD_OLDCONFIG + set_config_with_override BOOL UDEV CMD_UDEV + set_config_with_override BOOL LVM CMD_LVM + set_config_with_override BOOL DMRAID CMD_DMRAID + set_config_with_override BOOL ISCSI CMD_ISCSI + set_config_with_override BOOL BUSYBOX CMD_BUSYBOX "yes" + set_config_with_override BOOL NETBOOT CMD_NETBOOT + set_config_with_override STRING REAL_ROOT CMD_REAL_ROOT + set_config_with_override BOOL LUKS CMD_LUKS + set_config_with_override BOOL GPG CMD_GPG + set_config_with_override BOOL MDADM CMD_MDADM + set_config_with_override STRING MDADM_CONFIG CMD_MDADM_CONFIG + set_config_with_override BOOL E2FSPROGS CMD_E2FSPROGS "no" + set_config_with_override BOOL ZFS CMD_ZFS + set_config_with_override BOOL BTRFS CMD_BTRFS + set_config_with_override BOOL VIRTIO CMD_VIRTIO "no" + set_config_with_override BOOL MULTIPATH CMD_MULTIPATH + set_config_with_override BOOL FIRMWARE CMD_FIRMWARE + set_config_with_override STRING FIRMWARE_DIR CMD_FIRMWARE_DIR "/lib/firmware" + set_config_with_override STRING FIRMWARE_FILES CMD_FIRMWARE_FILES + set_config_with_override BOOL INTEGRATED_INITRAMFS CMD_INTEGRATED_INITRAMFS + set_config_with_override BOOL GENZIMAGE CMD_GENZIMAGE + set_config_with_override BOOL KEYMAP CMD_KEYMAP "yes" + set_config_with_override BOOL DOKEYMAPAUTO CMD_DOKEYMAPAUTO + set_config_with_override STRING BUSYBOX_CONFIG CMD_BUSYBOX_CONFIG + set_config_with_override BOOL INSTALL CMD_INSTALL "yes" + + BOOTDIR=`arch_replace "${BOOTDIR}"` + BOOTDIR=${BOOTDIR%/} # Remove any trailing slash + MODPROBEDIR=${MODPROBEDIR%/} # Remove any trailing slash + + CACHE_DIR=`arch_replace "${CACHE_DIR}"` + BUSYBOX_BINCACHE=`cache_replace "${BUSYBOX_BINCACHE}"` + + DEFAULT_KERNEL_CONFIG=`arch_replace "${DEFAULT_KERNEL_CONFIG}"` + BUSYBOX_CONFIG=`arch_replace "${BUSYBOX_CONFIG}"` + BUSYBOX_BINCACHE=`arch_replace "${BUSYBOX_BINCACHE}"` + + if [ -n "${CMD_BOOTLOADER}" ] + then + BOOTLOADER="${CMD_BOOTLOADER}" + if [ "${CMD_BOOTLOADER}" != "${CMD_BOOTLOADER/:/}" ] + then + BOOTFS=`echo "${CMD_BOOTLOADER}" | cut -f2- -d:` + BOOTLOADER=`echo "${CMD_BOOTLOADER}" | cut -f1 -d:` + fi + fi + + if [ "${KERNEL_SOURCES}" != "0" ] + then + if [ ! -d ${KERNEL_DIR} ] + then + gen_die "kernel source directory \"${KERNEL_DIR}\" was not found!" + fi + fi + + if [ -z "${KERNCACHE}" ] + then + if [ "${KERNEL_DIR}" = '' -a "${KERNEL_SOURCES}" != "0" ] + then + gen_die 'No kernel source directory!' + fi + if [ ! -e "${KERNEL_DIR}" -a "${KERNEL_SOURCES}" != "0" ] + then + gen_die 'No kernel source directory!' + fi + else + if [ "${KERNEL_DIR}" = '' ] + then + gen_die 'Kernel Cache specified but no kernel tree to verify against!' + fi + fi + + # Special case: If --no-clean is specified on the command line, + # imply --no-mrproper. + if [ "${CMD_CLEAN}" != '' ] + then + if ! isTrue ${CLEAN} + then + MRPROPER=0 + fi + fi + + if [ -n "${MINKERNPACKAGE}" ] + then + mkdir -p `dirname ${MINKERNPACKAGE}` + fi + + if [ -n "${MODULESPACKAGE}" ] + then + mkdir -p `dirname ${MODULESPACKAGE}` + fi + + if [ -n "${KERNCACHE}" ] + then + mkdir -p `dirname ${KERNCACHE}` + fi + + if ! isTrue "${BUILD_RAMDISK}" + then + INTEGRATED_INITRAMFS=0 + fi + + get_KV } diff --git a/gen_funcs.sh b/gen_funcs.sh index 6721d62..f5cd555 100755 --- a/gen_funcs.sh +++ b/gen_funcs.sh @@ -2,169 +2,169 @@ # $Id$ isTrue() { - case "$1" in - [Tt][Rr][Uu][Ee]) - return 0 - ;; - [Tt]) - return 0 - ;; - [Yy][Ee][Ss]) - return 0 - ;; - [Yy]) - return 0 - ;; - 1) - return 0 - ;; - esac - return 1 + case "$1" in + [Tt][Rr][Uu][Ee]) + return 0 + ;; + [Tt]) + return 0 + ;; + [Yy][Ee][Ss]) + return 0 + ;; + [Yy]) + return 0 + ;; + 1) + return 0 + ;; + esac + return 1 } setColorVars() { if isTrue ${USECOLOR} then - GOOD=$'\e[32;01m' - WARN=$'\e[33;01m' - BAD=$'\e[31;01m' - NORMAL=$'\e[0m' - BOLD=$'\e[0;01m' - UNDER=$'\e[4m' + GOOD=$'\e[32;01m' + WARN=$'\e[33;01m' + BAD=$'\e[31;01m' + NORMAL=$'\e[0m' + BOLD=$'\e[0;01m' + UNDER=$'\e[4m' else - GOOD='' - WARN='' - BAD='' - NORMAL='' - BOLD='' - UNDER='' + GOOD='' + WARN='' + BAD='' + NORMAL='' + BOLD='' + UNDER='' fi } setColorVars dump_debugcache() { - TODEBUGCACHE=0 - echo "${DEBUGCACHE}" >> ${LOGFILE} + TODEBUGCACHE=0 + echo "${DEBUGCACHE}" >> ${LOGFILE} } # print_info(loglevel, print [, newline [, prefixline [, forcefile ] ] ]) print_info() { - local NEWLINE=1 - local FORCEFILE=0 - local PREFIXLINE=1 - local SCRPRINT=0 - local STR='' - - # NOT ENOUGH ARGS - if [ "$#" -lt '2' ] ; then return 1; fi - - # IF 3 OR MORE ARGS, CHECK IF WE WANT A NEWLINE AFTER PRINT - if [ "$#" -gt '2' ] - then - if isTrue "$3" - then - NEWLINE='1'; - else - NEWLINE='0'; - fi - fi - - # IF 4 OR MORE ARGS, CHECK IF WE WANT TO PREFIX WITH A * - if [ "$#" -gt '3' ] - then - if isTrue "$4" - then - PREFIXLINE='1' - else - PREFIXLINE='0' - fi - fi - - # IF 5 OR MORE ARGS, CHECK IF WE WANT TO FORCE OUTPUT TO DEBUG - # FILE EVEN IF IT DOESN'T MEET THE MINIMUM DEBUG REQS - if [ "$#" -gt '4' ] - then - if isTrue "$5" - then - FORCEFILE='1' - else - FORCEFILE='0' - fi - fi - - # PRINT TO SCREEN ONLY IF PASSED LOGLEVEL IS HIGHER THAN - # OR EQUAL TO SET DEBUG LEVEL - if [ "$1" -lt "${LOGLEVEL}" -o "$1" = "${LOGLEVEL}" ] - then - SCRPRINT='1' - fi - - # RETURN IF NOT OUTPUTTING ANYWHERE - if [ "${SCRPRINT}" != '1' -a "${FORCEFILE}" != '1' ] - then - return 0 - fi - - # STRUCTURE DATA TO BE OUTPUT TO SCREEN, AND OUTPUT IT - if [ "${SCRPRINT}" = '1' ] - then - if [ "${PREFIXLINE}" = '1' ] - then - STR="${GOOD}*${NORMAL} ${2}" - else - STR="${2}" - fi - - if [ "${NEWLINE}" = '0' ] - then - echo -ne "${STR}" - else - echo "${STR}" - fi - fi - - # STRUCTURE DATA TO BE OUTPUT TO FILE, AND OUTPUT IT - if [ "${SCRPRINT}" = '1' -o "${FORCEFILE}" = '1' ] - then - STRR=${2//${WARN}/} - STRR=${STRR//${BAD}/} - STRR=${STRR//${BOLD}/} - STRR=${STRR//${NORMAL}/} - - if [ "${PREFIXLINE}" = '1' ] - then - STR="* ${STRR}" - else - STR="${STRR}" - fi - - if [ "${NEWLINE}" = '0' ] - then - if [ "${TODEBUGCACHE}" = '1' ]; then - DEBUGCACHE="${DEBUGCACHE}${STR}" - else - echo -ne "${STR}" >> ${LOGFILE} - fi - else - if [ "${TODEBUGCACHE}" = '1' ]; then - DEBUGCACHE="${DEBUGCACHE}${STR}"$'\n' - else - echo "${STR}" >> ${LOGFILE} - fi - fi - fi - - return 0 + local NEWLINE=1 + local FORCEFILE=0 + local PREFIXLINE=1 + local SCRPRINT=0 + local STR='' + + # NOT ENOUGH ARGS + if [ "$#" -lt '2' ] ; then return 1; fi + + # IF 3 OR MORE ARGS, CHECK IF WE WANT A NEWLINE AFTER PRINT + if [ "$#" -gt '2' ] + then + if isTrue "$3" + then + NEWLINE='1'; + else + NEWLINE='0'; + fi + fi + + # IF 4 OR MORE ARGS, CHECK IF WE WANT TO PREFIX WITH A * + if [ "$#" -gt '3' ] + then + if isTrue "$4" + then + PREFIXLINE='1' + else + PREFIXLINE='0' + fi + fi + + # IF 5 OR MORE ARGS, CHECK IF WE WANT TO FORCE OUTPUT TO DEBUG + # FILE EVEN IF IT DOESN'T MEET THE MINIMUM DEBUG REQS + if [ "$#" -gt '4' ] + then + if isTrue "$5" + then + FORCEFILE='1' + else + FORCEFILE='0' + fi + fi + + # PRINT TO SCREEN ONLY IF PASSED LOGLEVEL IS HIGHER THAN + # OR EQUAL TO SET DEBUG LEVEL + if [ "$1" -lt "${LOGLEVEL}" -o "$1" = "${LOGLEVEL}" ] + then + SCRPRINT='1' + fi + + # RETURN IF NOT OUTPUTTING ANYWHERE + if [ "${SCRPRINT}" != '1' -a "${FORCEFILE}" != '1' ] + then + return 0 + fi + + # STRUCTURE DATA TO BE OUTPUT TO SCREEN, AND OUTPUT IT + if [ "${SCRPRINT}" = '1' ] + then + if [ "${PREFIXLINE}" = '1' ] + then + STR="${GOOD}*${NORMAL} ${2}" + else + STR="${2}" + fi + + if [ "${NEWLINE}" = '0' ] + then + echo -ne "${STR}" + else + echo "${STR}" + fi + fi + + # STRUCTURE DATA TO BE OUTPUT TO FILE, AND OUTPUT IT + if [ "${SCRPRINT}" = '1' -o "${FORCEFILE}" = '1' ] + then + STRR=${2//${WARN}/} + STRR=${STRR//${BAD}/} + STRR=${STRR//${BOLD}/} + STRR=${STRR//${NORMAL}/} + + if [ "${PREFIXLINE}" = '1' ] + then + STR="* ${STRR}" + else + STR="${STRR}" + fi + + if [ "${NEWLINE}" = '0' ] + then + if [ "${TODEBUGCACHE}" = '1' ]; then + DEBUGCACHE="${DEBUGCACHE}${STR}" + else + echo -ne "${STR}" >> ${LOGFILE} + fi + else + if [ "${TODEBUGCACHE}" = '1' ]; then + DEBUGCACHE="${DEBUGCACHE}${STR}"$'\n' + else + echo "${STR}" >> ${LOGFILE} + fi + fi + fi + + return 0 } print_error() { - GOOD=${BAD} print_info "$@" + GOOD=${BAD} print_info "$@" } print_warning() { - GOOD=${WARN} print_info "$@" + GOOD=${WARN} print_info "$@" } # var_replace(var_name, var_value, string) @@ -193,50 +193,50 @@ cache_replace() { clear_log() { if [ -f "${LOGFILE}" ] then - (echo > "${LOGFILE}") 2>/dev/null || small_die "Genkernel: Could not write to ${LOGFILE}." + (echo > "${LOGFILE}") 2>/dev/null || small_die "Genkernel: Could not write to ${LOGFILE}." fi } gen_die() { - dump_debugcache - - if [ "$#" -gt '0' ] - then - print_error 1 "ERROR: ${1}" - fi - print_error 1 '' - print_error 1 "-- Grepping log... --" - print_error 1 '' - - if isTrue ${USECOLOR} - then - GREP_COLOR='1' grep -B5 -E --colour=always "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE} \ - | sed -s "s|^\(*\)\?|${BAD}*${NORMAL}|" - else - grep -B5 -E "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE} - fi - print_error 1 '' - print_error 1 "-- End log... --" - print_error 1 '' - print_error 1 "Please consult ${LOGFILE} for more information and any" - print_error 1 "errors that were reported above." - print_error 1 '' - print_error 1 "Report any genkernel bugs to bugs.gentoo.org and" - print_error 1 "assign your bug to genkernel@gentoo.org. Please include" - print_error 1 "as much information as you can in your bug report; attaching" - print_error 1 "${LOGFILE} so that your issue can be dealt with effectively." - print_error 1 '' - print_error 1 'Please do *not* report compilation failures as genkernel bugs!' - print_error 1 '' - - # Cleanup temp dirs and caches if requested - cleanup - exit 1 + dump_debugcache + + if [ "$#" -gt '0' ] + then + print_error 1 "ERROR: ${1}" + fi + print_error 1 '' + print_error 1 "-- Grepping log... --" + print_error 1 '' + + if isTrue ${USECOLOR} + then + GREP_COLOR='1' grep -B5 -E --colour=always "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE} \ + | sed -s "s|^\(*\)\?|${BAD}*${NORMAL}|" + else + grep -B5 -E "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE} + fi + print_error 1 '' + print_error 1 "-- End log... --" + print_error 1 '' + print_error 1 "Please consult ${LOGFILE} for more information and any" + print_error 1 "errors that were reported above." + print_error 1 '' + print_error 1 "Report any genkernel bugs to bugs.gentoo.org and" + print_error 1 "assign your bug to genkernel@gentoo.org. Please include" + print_error 1 "as much information as you can in your bug report; attaching" + print_error 1 "${LOGFILE} so that your issue can be dealt with effectively." + print_error 1 '' + print_error 1 'Please do *not* report compilation failures as genkernel bugs!' + print_error 1 '' + + # Cleanup temp dirs and caches if requested + cleanup + exit 1 } isBootRO() { - return $(awk '( $2 == "'${BOOTDIR}'" && $4 ~ /(^|,)ro(,|$)/){ I=1; exit }END{print !I }' /proc/mounts); + return $(awk '( $2 == "'${BOOTDIR}'" && $4 ~ /(^|,)ro(,|$)/){ I=1; exit }END{print !I }' /proc/mounts); } setup_cache_dir() @@ -246,12 +246,12 @@ setup_cache_dir() if [ "${CLEAR_CACHE_DIR}" == 'yes' ] then - print_info 1 "Clearing cache dir contents from ${CACHE_DIR}" - while read i - do - print_info 1 " >> removing ${i}" - rm "${i}" - done < <(find "${CACHE_DIR}" -maxdepth 1 -type f -name '*.tar.*' -o -name '*.bz2') + print_info 1 "Clearing cache dir contents from ${CACHE_DIR}" + while read i + do + print_info 1 " >> removing ${i}" + rm "${i}" + done < <(find "${CACHE_DIR}" -maxdepth 1 -type f -name '*.tar.*' -o -name '*.bz2') fi } @@ -260,13 +260,13 @@ clear_tmpdir() { if isTrue ${CMD_INSTALL} then - TMPDIR_CONTENTS=`ls ${TMPDIR}` - print_info 1 "Removing tmp dir contents" - for i in ${TMPDIR_CONTENTS} - do - print_info 1 " >> removing ${i}" - rm ${TMPDIR}/${i} - done + TMPDIR_CONTENTS=`ls ${TMPDIR}` + print_info 1 "Removing tmp dir contents" + for i in ${TMPDIR_CONTENTS} + do + print_info 1 " >> removing ${i}" + rm ${TMPDIR}/${i} + done fi } @@ -285,127 +285,127 @@ fi # - JRG # copy_image_with_preserve() { - local symlinkName=$1 - local newSrceImage=$2 - local fullDestName=$3 - - local currDestImage - local prevDestImage - local currDestImageExists=0 - local prevDestImageExists=0 - - print_info 4 "Copying new ${symlinkName} image, " 0 - - # Old product might be a different version. If so, we need to read - # the symlink to see what it's name is, if there are symlinks. - cd ${KERNEL_OUTPUTDIR} - if [ "${SYMLINK}" = '1' ] - then - print_info 4 "automatically managing symlinks and old images." 1 0 - if [ -e "${BOOTDIR}/${symlinkName}" ] - then - # JRG: Do I need a special case here for when the standard symlink - # name is, in fact, not a symlink? - currDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}` - print_info 5 " Current ${symlinkName} symlink exists:" - print_info 5 " ${currDestImage}" - else - currDestImage="${fullDestName}" - print_info 5 " Current ${symlinkName} symlink did not exist." - print_info 5 " Defaulted to: ${currDestImage}" - fi - if [ -e "${BOOTDIR}/${currDestImage}" ] - then - currDestImageExists=1 - print_info 5 " Actual image file exists." - fi - - if [ -e "${BOOTDIR}/${symlinkName}.old" ] - then - # JRG: Do I need a special case here for when the standard symlink - # name is, in fact, not a symlink? - prevDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}.old` - print_info 5 " Old ${symlinkName} symlink exists:" - print_info 5 " ${prevDestImage}" - else - prevDestImage="${fullDestName}.old" - print_info 5 " Old ${symlinkName} symlink did not exist." - print_info 5 " Defaulted to: ${prevDestImage}" - fi - if [ -e "${BOOTDIR}/${prevDestImage}" ] - then - prevDestImageExists=1 - print_info 5 " Actual old image file exists." - fi - else - print_info 4 "symlinks not being handled by genkernel." 1 0 - currDestImage="${fullDestName}" - prevDestImage="${fullDestName}.old" - fi - - # When symlinks are not being managed by genkernel, old symlinks might + local symlinkName=$1 + local newSrceImage=$2 + local fullDestName=$3 + + local currDestImage + local prevDestImage + local currDestImageExists=0 + local prevDestImageExists=0 + + print_info 4 "Copying new ${symlinkName} image, " 0 + + # Old product might be a different version. If so, we need to read + # the symlink to see what it's name is, if there are symlinks. + cd ${KERNEL_OUTPUTDIR} + if [ "${SYMLINK}" = '1' ] + then + print_info 4 "automatically managing symlinks and old images." 1 0 + if [ -e "${BOOTDIR}/${symlinkName}" ] + then + # JRG: Do I need a special case here for when the standard symlink + # name is, in fact, not a symlink? + currDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}` + print_info 5 " Current ${symlinkName} symlink exists:" + print_info 5 " ${currDestImage}" + else + currDestImage="${fullDestName}" + print_info 5 " Current ${symlinkName} symlink did not exist." + print_info 5 " Defaulted to: ${currDestImage}" + fi + if [ -e "${BOOTDIR}/${currDestImage}" ] + then + currDestImageExists=1 + print_info 5 " Actual image file exists." + fi + + if [ -e "${BOOTDIR}/${symlinkName}.old" ] + then + # JRG: Do I need a special case here for when the standard symlink + # name is, in fact, not a symlink? + prevDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}.old` + print_info 5 " Old ${symlinkName} symlink exists:" + print_info 5 " ${prevDestImage}" + else + prevDestImage="${fullDestName}.old" + print_info 5 " Old ${symlinkName} symlink did not exist." + print_info 5 " Defaulted to: ${prevDestImage}" + fi + if [ -e "${BOOTDIR}/${prevDestImage}" ] + then + prevDestImageExists=1 + print_info 5 " Actual old image file exists." + fi + else + print_info 4 "symlinks not being handled by genkernel." 1 0 + currDestImage="${fullDestName}" + prevDestImage="${fullDestName}.old" + fi + + # When symlinks are not being managed by genkernel, old symlinks might # still be useful. Leave 'em alone unless managed. - if [ "${SYMLINK}" = '1' ] - then - print_info 5 " Deleting old symlinks, if any." - rm -f "${BOOTDIR}/${symlinkName}" - rm -f "${BOOTDIR}/${symlinkName}.old" - fi - - # We only erase the .old image when it is the exact same version as the - # current and new images. Different version .old (and current) images are - # left behind. This is consistent with how "make install" of the manual - # kernel build works. - if [ "${currDestImage}" == "${fullDestName}" ] - then - # - # Case for new and currrent of the same base version. - # - print_info 5 " Same base version. May have to delete old image to make room." - - if [ "${currDestImageExists}" = '1' ] - then - if [ -e "${BOOTDIR}/${currDestImage}.old" ] - then - print_info 5 " Deleting old identical version ${symlinkName}." - rm -f "${BOOTDIR}/${currDestImage}.old" - fi - print_info 5 " Moving ${BOOTDIR}/${currDestImage}" - print_info 5 " to ${BOOTDIR}/${currDestImage}.old" - mv "${BOOTDIR}/${currDestImage}" "${BOOTDIR}/${currDestImage}.old" || - gen_die "Could not rename the old ${symlinkName} image!" - prevDestImage="${currDestImage}.old" - prevDestImageExists=1 - fi - else - # - # Case for new / current not of the same base version. - # - print_info 5 " Different base version. Do not delete old images." - prevDestImage="${currDestImage}" - currDestImage="${fullDestName}" - fi - - print_info 5 " Copying ${symlinkName}: ${newSrceImage}" - print_info 5 " to ${BOOTDIR}/${currDestImage}" - cp "${newSrceImage}" "${BOOTDIR}/${currDestImage}" || - gen_die "Could not copy the ${symlinkName} image to ${BOOTDIR}!" - - if [ "${SYMLINK}" = '1' ] - then - print_info 5 " Make new symlink(s) (from ${BOOTDIR}):" - print_info 5 " ${symlinkName} -> ${currDestImage}" - pushd ${BOOTDIR} >/dev/null - ln -s "${currDestImage}" "${symlinkName}" || - gen_die "Could not create the ${symlinkName} symlink!" - if [ "${prevDestImageExists}" = '1' ] - then - print_info 5 " ${symlinkName}.old -> ${prevDestImage}" - ln -s "${prevDestImage}" "${symlinkName}.old" || - gen_die "Could not create the ${symlinkName}.old symlink!" - fi - popd >/dev/null - fi + if [ "${SYMLINK}" = '1' ] + then + print_info 5 " Deleting old symlinks, if any." + rm -f "${BOOTDIR}/${symlinkName}" + rm -f "${BOOTDIR}/${symlinkName}.old" + fi + + # We only erase the .old image when it is the exact same version as the + # current and new images. Different version .old (and current) images are + # left behind. This is consistent with how "make install" of the manual + # kernel build works. + if [ "${currDestImage}" == "${fullDestName}" ] + then + # + # Case for new and currrent of the same base version. + # + print_info 5 " Same base version. May have to delete old image to make room." + + if [ "${currDestImageExists}" = '1' ] + then + if [ -e "${BOOTDIR}/${currDestImage}.old" ] + then + print_info 5 " Deleting old identical version ${symlinkName}." + rm -f "${BOOTDIR}/${currDestImage}.old" + fi + print_info 5 " Moving ${BOOTDIR}/${currDestImage}" + print_info 5 " to ${BOOTDIR}/${currDestImage}.old" + mv "${BOOTDIR}/${currDestImage}" "${BOOTDIR}/${currDestImage}.old" || + gen_die "Could not rename the old ${symlinkName} image!" + prevDestImage="${currDestImage}.old" + prevDestImageExists=1 + fi + else + # + # Case for new / current not of the same base version. + # + print_info 5 " Different base version. Do not delete old images." + prevDestImage="${currDestImage}" + currDestImage="${fullDestName}" + fi + + print_info 5 " Copying ${symlinkName}: ${newSrceImage}" + print_info 5 " to ${BOOTDIR}/${currDestImage}" + cp "${newSrceImage}" "${BOOTDIR}/${currDestImage}" || + gen_die "Could not copy the ${symlinkName} image to ${BOOTDIR}!" + + if [ "${SYMLINK}" = '1' ] + then + print_info 5 " Make new symlink(s) (from ${BOOTDIR}):" + print_info 5 " ${symlinkName} -> ${currDestImage}" + pushd ${BOOTDIR} >/dev/null + ln -s "${currDestImage}" "${symlinkName}" || + gen_die "Could not create the ${symlinkName} symlink!" + if [ "${prevDestImageExists}" = '1' ] + then + print_info 5 " ${symlinkName}.old -> ${prevDestImage}" + ln -s "${prevDestImage}" "${symlinkName}.old" || + gen_die "Could not create the ${symlinkName}.old symlink!" + fi + popd >/dev/null + fi } # @@ -436,92 +436,92 @@ copy_image_with_preserve() { # - JRG # set_config_with_override() { - local VarType=$1 - local CfgVar=$2 - local OverrideVar=$3 - local Default=$4 - local Result - - # - # Syntax check the function arguments. - # - case "$VarType" in - BOOL|STRING) - ;; - *) - gen_die "Illegal variable type \"$VarType\" passed to set_config_with_override()." - ;; - esac - - if [ -n "${!OverrideVar}" ] - then - Result=${!OverrideVar} - if [ -n "${!CfgVar}" ] - then - print_info 5 " $CfgVar overridden on command line to \"$Result\"." - else - print_info 5 " $CfgVar set on command line to \"$Result\"." - fi - else - if [ -n "${!CfgVar}" ] - then - Result=${!CfgVar} - # we need to set the CMD_* according to configfile... - eval ${OverrideVar}=\"${Result}\" - print_info 5 " $CfgVar set in config file to \"${Result}\"." - else - if [ -n "$Default" ] - then - Result=${Default} - # set OverrideVar to Result, otherwise CMD_* may not be initialized... - eval ${OverrideVar}=\"${Result}\" - print_info 5 " $CfgVar defaulted to \"${Result}\"." - else - print_info 5 " $CfgVar not set." - fi - fi - fi - - if [ "${VarType}" = BOOL ] - then - if isTrue "${Result}" - then - Result=1 - else - Result=0 - fi - fi - - eval ${CfgVar}=\"${Result}\" + local VarType=$1 + local CfgVar=$2 + local OverrideVar=$3 + local Default=$4 + local Result + + # + # Syntax check the function arguments. + # + case "$VarType" in + BOOL|STRING) + ;; + *) + gen_die "Illegal variable type \"$VarType\" passed to set_config_with_override()." + ;; + esac + + if [ -n "${!OverrideVar}" ] + then + Result=${!OverrideVar} + if [ -n "${!CfgVar}" ] + then + print_info 5 " $CfgVar overridden on command line to \"$Result\"." + else + print_info 5 " $CfgVar set on command line to \"$Result\"." + fi + else + if [ -n "${!CfgVar}" ] + then + Result=${!CfgVar} + # we need to set the CMD_* according to configfile... + eval ${OverrideVar}=\"${Result}\" + print_info 5 " $CfgVar set in config file to \"${Result}\"." + else + if [ -n "$Default" ] + then + Result=${Default} + # set OverrideVar to Result, otherwise CMD_* may not be initialized... + eval ${OverrideVar}=\"${Result}\" + print_info 5 " $CfgVar defaulted to \"${Result}\"." + else + print_info 5 " $CfgVar not set." + fi + fi + fi + + if [ "${VarType}" = BOOL ] + then + if isTrue "${Result}" + then + Result=1 + else + Result=0 + fi + fi + + eval ${CfgVar}=\"${Result}\" } check_distfiles() { - for i in $BUSYBOX_SRCTAR $MULTIPATH_SRCTAR $ISCSI_SRCTAR $GPG_SRCTAR - do - if [ ! -f "${i}" ] - then - small_die "Could not find source tarball ${i}. Please refetch." - fi - done + for i in $BUSYBOX_SRCTAR $MULTIPATH_SRCTAR $ISCSI_SRCTAR $GPG_SRCTAR + do + if [ ! -f "${i}" ] + then + small_die "Could not find source tarball ${i}. Please refetch." + fi + done } find_kernel_binary() { - local kernel_binary=$* - local curdir=$(pwd) - - cd "${KERNEL_OUTPUTDIR}" - for i in ${kernel_binary} - do - if [ -e "${i}" ] - then - tmp_kernel_binary=$i - break - fi - done -# if [ -z "${tmp_kernel_binary}" ] -# then -# gen_die "Cannot locate kernel binary!" -# fi - cd "${curdir}" - echo "${tmp_kernel_binary}" + local kernel_binary=$* + local curdir=$(pwd) + + cd "${KERNEL_OUTPUTDIR}" + for i in ${kernel_binary} + do + if [ -e "${i}" ] + then + tmp_kernel_binary=$i + break + fi + done +# if [ -z "${tmp_kernel_binary}" ] +# then +# gen_die "Cannot locate kernel binary!" +# fi + cd "${curdir}" + echo "${tmp_kernel_binary}" } diff --git a/gen_initramfs.sh b/gen_initramfs.sh index 724af3b..5330190 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -21,1071 +21,1071 @@ CPIO_ARGS="--quiet -o -H newc" # Usage: # copy_binaries DESTDIR BINARIES... copy_binaries() { - local destdir=$1 - shift - - for binary in "$@"; do - [[ -e "${binary}" ]] \ - || gen_die "Binary ${binary} could not be found" - - if LC_ALL=C lddtree "${binary}" 2>&1 | fgrep -q 'not found'; then - gen_die "Binary ${binary} is linked to missing libraries and may need to be re-built" - fi - done - # This must be OUTSIDE the for loop, we only want to run lddtree etc ONCE. - # lddtree does not have the -V (version) nor the -l (list) options prior to version 1.18 - ( - if lddtree -V > /dev/null 2>&1 ; then - lddtree -l "$@" - else - lddtree "$@" \ - | tr ')(' '\n' \ - | awk '/=>/{ if($3 ~ /^\//){print $3}}' - fi ) \ - | sort \ - | uniq \ - | cpio -p --make-directories --dereference --quiet "${destdir}" \ - || gen_die "Binary ${f} or some of its library dependencies could not be copied" + local destdir=$1 + shift + + for binary in "$@"; do + [[ -e "${binary}" ]] \ + || gen_die "Binary ${binary} could not be found" + + if LC_ALL=C lddtree "${binary}" 2>&1 | fgrep -q 'not found'; then + gen_die "Binary ${binary} is linked to missing libraries and may need to be re-built" + fi + done + # This must be OUTSIDE the for loop, we only want to run lddtree etc ONCE. + # lddtree does not have the -V (version) nor the -l (list) options prior to version 1.18 + ( + if lddtree -V > /dev/null 2>&1 ; then + lddtree -l "$@" + else + lddtree "$@" \ + | tr ')(' '\n' \ + | awk '/=>/{ if($3 ~ /^\//){print $3}}' + fi ) \ + | sort \ + | uniq \ + | cpio -p --make-directories --dereference --quiet "${destdir}" \ + || gen_die "Binary ${f} or some of its library dependencies could not be copied" } log_future_cpio_content() { - if [[ "${LOGLEVEL}" -gt 1 ]]; then - echo ================================================================= - echo "About to add these files from '${PWD}' to cpio archive:" - find . | xargs ls -ald - echo ================================================================= - fi + if [[ "${LOGLEVEL}" -gt 1 ]]; then + echo ================================================================= + echo "About to add these files from '${PWD}' to cpio archive:" + find . | xargs ls -ald + echo ================================================================= + fi } get_firmware_files() { - local kmod="${1}" - modinfo --set-version="${KV}" -F firmware "${kmod}" || \ - gen_die "cannot execute modinfo for ${kmod}" + local kmod="${1}" + modinfo --set-version="${KV}" -F firmware "${kmod}" || \ + gen_die "cannot execute modinfo for ${kmod}" } append_base_layout() { - if [ -d "${TEMP}/initramfs-base-temp" ] - then - rm -rf "${TEMP}/initramfs-base-temp" > /dev/null - fi - - mkdir -p ${TEMP}/initramfs-base-temp/dev/shm - mkdir -p ${TEMP}/initramfs-base-temp/bin - mkdir -p ${TEMP}/initramfs-base-temp/etc - mkdir -p ${TEMP}/initramfs-base-temp/usr - mkdir -p ${TEMP}/initramfs-base-temp/lib - mkdir -p ${TEMP}/initramfs-base-temp/mnt - mkdir -p ${TEMP}/initramfs-base-temp/run - mkdir -p ${TEMP}/initramfs-base-temp/sbin - mkdir -p ${TEMP}/initramfs-base-temp/proc - mkdir -p ${TEMP}/initramfs-base-temp/temp - mkdir -p ${TEMP}/initramfs-base-temp/tmp - mkdir -p ${TEMP}/initramfs-base-temp/sys - mkdir -p ${TEMP}/initramfs-temp/.initrd - mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid - mkdir -p ${TEMP}/initramfs-base-temp/sbin - mkdir -p ${TEMP}/initramfs-base-temp/usr/bin - mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin - mkdir -p ${TEMP}/initramfs-base-temp/usr/share - mkdir -p ${TEMP}/initramfs-base-temp/usr/lib - ln -s lib ${TEMP}/initramfs-base-temp/lib64 - ln -s lib ${TEMP}/initramfs-base-temp/usr/lib64 - - echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab - echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab - - cd ${TEMP}/initramfs-base-temp/dev - mknod -m 660 console c 5 1 - mknod -m 660 null c 1 3 - mknod -m 660 zero c 1 5 - mknod -m 600 tty0 c 4 0 - mknod -m 600 tty1 c 4 1 - mknod -m 600 ttyS0 c 4 64 - chmod 1777 shm # bug 476278 - - date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date - echo "Genkernel $GK_V" > ${TEMP}/initramfs-base-temp/etc/build_id - - cd "${TEMP}/initramfs-base-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing baselayout cpio" - cd "${TEMP}" - rm -rf "${TEMP}/initramfs-base-temp" > /dev/null + if [ -d "${TEMP}/initramfs-base-temp" ] + then + rm -rf "${TEMP}/initramfs-base-temp" > /dev/null + fi + + mkdir -p ${TEMP}/initramfs-base-temp/dev/shm + mkdir -p ${TEMP}/initramfs-base-temp/bin + mkdir -p ${TEMP}/initramfs-base-temp/etc + mkdir -p ${TEMP}/initramfs-base-temp/usr + mkdir -p ${TEMP}/initramfs-base-temp/lib + mkdir -p ${TEMP}/initramfs-base-temp/mnt + mkdir -p ${TEMP}/initramfs-base-temp/run + mkdir -p ${TEMP}/initramfs-base-temp/sbin + mkdir -p ${TEMP}/initramfs-base-temp/proc + mkdir -p ${TEMP}/initramfs-base-temp/temp + mkdir -p ${TEMP}/initramfs-base-temp/tmp + mkdir -p ${TEMP}/initramfs-base-temp/sys + mkdir -p ${TEMP}/initramfs-temp/.initrd + mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid + mkdir -p ${TEMP}/initramfs-base-temp/sbin + mkdir -p ${TEMP}/initramfs-base-temp/usr/bin + mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin + mkdir -p ${TEMP}/initramfs-base-temp/usr/share + mkdir -p ${TEMP}/initramfs-base-temp/usr/lib + ln -s lib ${TEMP}/initramfs-base-temp/lib64 + ln -s lib ${TEMP}/initramfs-base-temp/usr/lib64 + + echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab + echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab + + cd ${TEMP}/initramfs-base-temp/dev + mknod -m 660 console c 5 1 + mknod -m 660 null c 1 3 + mknod -m 660 zero c 1 5 + mknod -m 600 tty0 c 4 0 + mknod -m 600 tty1 c 4 1 + mknod -m 600 ttyS0 c 4 64 + chmod 1777 shm # bug 476278 + + date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date + echo "Genkernel $GK_V" > ${TEMP}/initramfs-base-temp/etc/build_id + + cd "${TEMP}/initramfs-base-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing baselayout cpio" + cd "${TEMP}" + rm -rf "${TEMP}/initramfs-base-temp" > /dev/null } append_busybox() { - if [ -d "${TEMP}/initramfs-busybox-temp" ] - then - rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null - fi - - mkdir -p "${TEMP}/initramfs-busybox-temp/bin/" - tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox || - gen_die 'Could not extract busybox bincache!' - chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox" - - mkdir -p "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/" - cp "${GK_SHARE}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script - chmod +x "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script" - - # Set up a few default symlinks - local default_applets="[ ash sh mount uname ls echo cut cat flock stty" - default_applets+=" readlink mountpoint" - for i in ${BUSYBOX_APPLETS:-${default_applets}}; do - rm -f ${TEMP}/initramfs-busybox-temp/bin/$i - ln -s busybox ${TEMP}/initramfs-busybox-temp/bin/$i || - gen_die "Busybox error: could not link ${i}!" - done - - local mod_applets="sbin/modprobe sbin/insmod sbin/rmmod bin/lsmod" - local dir= - local name= - for i in ${mod_applets}; do - dir=$(dirname $i) - name=$(basename $i) - rm -f ${TEMP}/initramfs-busybox-temp/$dir/$name - mkdir -p ${TEMP}/initramfs-busybox-temp/$dir || - gen_die "Busybox error: could not create dir: $dir" - ln -s ../bin/busybox ${TEMP}/initramfs-busybox-temp/$dir/$name || - gen_die "Busybox error: could not link ${i}!" - done - - cd "${TEMP}/initramfs-busybox-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing busybox cpio" - cd "${TEMP}" - rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null + if [ -d "${TEMP}/initramfs-busybox-temp" ] + then + rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null + fi + + mkdir -p "${TEMP}/initramfs-busybox-temp/bin/" + tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox || + gen_die 'Could not extract busybox bincache!' + chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox" + + mkdir -p "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/" + cp "${GK_SHARE}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script + chmod +x "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script" + + # Set up a few default symlinks + local default_applets="[ ash sh mount uname ls echo cut cat flock stty" + default_applets+=" readlink mountpoint" + for i in ${BUSYBOX_APPLETS:-${default_applets}}; do + rm -f ${TEMP}/initramfs-busybox-temp/bin/$i + ln -s busybox ${TEMP}/initramfs-busybox-temp/bin/$i || + gen_die "Busybox error: could not link ${i}!" + done + + local mod_applets="sbin/modprobe sbin/insmod sbin/rmmod bin/lsmod" + local dir= + local name= + for i in ${mod_applets}; do + dir=$(dirname $i) + name=$(basename $i) + rm -f ${TEMP}/initramfs-busybox-temp/$dir/$name + mkdir -p ${TEMP}/initramfs-busybox-temp/$dir || + gen_die "Busybox error: could not create dir: $dir" + ln -s ../bin/busybox ${TEMP}/initramfs-busybox-temp/$dir/$name || + gen_die "Busybox error: could not link ${i}!" + done + + cd "${TEMP}/initramfs-busybox-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing busybox cpio" + cd "${TEMP}" + rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null } append_e2fsprogs(){ - if [ -d "${TEMP}"/initramfs-e2fsprogs-temp ] - then - rm -r "${TEMP}"/initramfs-e2fsprogs-temp - fi - - cd "${TEMP}" \ - || gen_die "cd '${TEMP}' failed" - mkdir -p initramfs-e2fsprogs-temp - copy_binaries "${TEMP}"/initramfs-e2fsprogs-temp/ /sbin/{e2fsck,mke2fs} - - cd "${TEMP}"/initramfs-e2fsprogs-temp \ - || gen_die "cd '${TEMP}/initramfs-e2fsprogs-temp' failed" - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" - rm -rf "${TEMP}"/initramfs-e2fsprogs-temp > /dev/null + if [ -d "${TEMP}"/initramfs-e2fsprogs-temp ] + then + rm -r "${TEMP}"/initramfs-e2fsprogs-temp + fi + + cd "${TEMP}" \ + || gen_die "cd '${TEMP}' failed" + mkdir -p initramfs-e2fsprogs-temp + copy_binaries "${TEMP}"/initramfs-e2fsprogs-temp/ /sbin/{e2fsck,mke2fs} + + cd "${TEMP}"/initramfs-e2fsprogs-temp \ + || gen_die "cd '${TEMP}/initramfs-e2fsprogs-temp' failed" + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" + rm -rf "${TEMP}"/initramfs-e2fsprogs-temp > /dev/null } append_blkid(){ - if [ -d "${TEMP}/initramfs-blkid-temp" ] - then - rm -r "${TEMP}/initramfs-blkid-temp/" - fi - cd ${TEMP} - mkdir -p "${TEMP}/initramfs-blkid-temp/" - - copy_binaries "${TEMP}"/initramfs-blkid-temp/ /sbin/blkid - - cd "${TEMP}/initramfs-blkid-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing blkid cpio" - cd "${TEMP}" - rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null + if [ -d "${TEMP}/initramfs-blkid-temp" ] + then + rm -r "${TEMP}/initramfs-blkid-temp/" + fi + cd ${TEMP} + mkdir -p "${TEMP}/initramfs-blkid-temp/" + + copy_binaries "${TEMP}"/initramfs-blkid-temp/ /sbin/blkid + + cd "${TEMP}/initramfs-blkid-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing blkid cpio" + cd "${TEMP}" + rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null } append_multipath(){ - if [ -d "${TEMP}/initramfs-multipath-temp" ] - then - rm -r "${TEMP}/initramfs-multipath-temp" - fi - print_info 1 ' Multipath support being added' - mkdir -p "${TEMP}"/initramfs-multipath-temp/{bin,etc,sbin,lib}/ - - # Copy files - copy_binaries "${TEMP}/initramfs-multipath-temp" \ - /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} \ - /{lib,lib64}/{udev/scsi_id,multipath/*so} - - if [ -x /sbin/multipath ] - then - cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this' - fi - # /etc/scsi_id.config does not exist in newer udevs - # copy it optionally. - if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ] - then - cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config' - fi - cd "${TEMP}/initramfs-multipath-temp" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing multipath cpio" - cd "${TEMP}" - rm -r "${TEMP}/initramfs-multipath-temp/" + if [ -d "${TEMP}/initramfs-multipath-temp" ] + then + rm -r "${TEMP}/initramfs-multipath-temp" + fi + print_info 1 ' Multipath support being added' + mkdir -p "${TEMP}"/initramfs-multipath-temp/{bin,etc,sbin,lib}/ + + # Copy files + copy_binaries "${TEMP}/initramfs-multipath-temp" \ + /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} \ + /{lib,lib64}/{udev/scsi_id,multipath/*so} + + if [ -x /sbin/multipath ] + then + cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this' + fi + # /etc/scsi_id.config does not exist in newer udevs + # copy it optionally. + if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ] + then + cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config' + fi + cd "${TEMP}/initramfs-multipath-temp" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing multipath cpio" + cd "${TEMP}" + rm -r "${TEMP}/initramfs-multipath-temp/" } append_dmraid(){ - if [ -d "${TEMP}/initramfs-dmraid-temp" ] - then - rm -r "${TEMP}/initramfs-dmraid-temp/" - fi - print_info 1 'DMRAID: Adding support (copying binaries from system)...' - - mkdir -p "${TEMP}/initramfs-dmraid-temp/sbin" - - copy_binaries "${TEMP}/initramfs-dmraid-temp" \ - /usr/sbin/dmraid /usr/sbin/dmevent_tool - - cd "${TEMP}/initramfs-dmraid-temp" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing dmraid cpio" - cd "${TEMP}" - rm -r "${TEMP}/initramfs-dmraid-temp/" + if [ -d "${TEMP}/initramfs-dmraid-temp" ] + then + rm -r "${TEMP}/initramfs-dmraid-temp/" + fi + print_info 1 'DMRAID: Adding support (copying binaries from system)...' + + mkdir -p "${TEMP}/initramfs-dmraid-temp/sbin" + + copy_binaries "${TEMP}/initramfs-dmraid-temp" \ + /usr/sbin/dmraid /usr/sbin/dmevent_tool + + cd "${TEMP}/initramfs-dmraid-temp" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing dmraid cpio" + cd "${TEMP}" + rm -r "${TEMP}/initramfs-dmraid-temp/" } append_iscsi(){ - if [ -d "${TEMP}/initramfs-iscsi-temp" ] - then - rm -r "${TEMP}/initramfs-iscsi-temp/" - fi - print_info 1 'iSCSI: Adding support (copying binaries from system)...' - - mkdir -p "${TEMP}/initramfs-iscsi-temp/usr/sbin/" - - copy_binaries /usr/sbin/iscsistart - - cd "${TEMP}/initramfs-iscsi-temp" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing iscsi cpio" - cd "${TEMP}" - rm -r "${TEMP}/initramfs-iscsi-temp/" + if [ -d "${TEMP}/initramfs-iscsi-temp" ] + then + rm -r "${TEMP}/initramfs-iscsi-temp/" + fi + print_info 1 'iSCSI: Adding support (copying binaries from system)...' + + mkdir -p "${TEMP}/initramfs-iscsi-temp/usr/sbin/" + + copy_binaries /usr/sbin/iscsistart + + cd "${TEMP}/initramfs-iscsi-temp" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing iscsi cpio" + cd "${TEMP}" + rm -r "${TEMP}/initramfs-iscsi-temp/" } append_lvm(){ - if [ -d "${TEMP}/initramfs-lvm-temp" ] - then - rm -r "${TEMP}/initramfs-lvm-temp/" - fi - cd ${TEMP} - mkdir -p "${TEMP}/initramfs-lvm-temp"/{bin,sbin} - mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/" - print_info 1 'LVM: Adding support (copying binaries from system)...' - - local udev_dir="$(pkg-config --variable udevdir udev)" - udev_files=( $(qlist -e sys-fs/lvm2:0 | grep ^${udev_dir}/rules.d) ) - for f in "${udev_files[@]}"; do - [ -f "${f}" ] || gen_die "append_lvm: not a file: ${f}" - mkdir -p "${TEMP}/initramfs-lvm-temp"/$(dirname "${f}") || \ - gen_die "cannot create rules.d directory" - cp "${f}" "${TEMP}/initramfs-lvm-temp/${f}" || \ - gen_die "cannot copy ${f} from system" - done - - copy_binaries "${TEMP}/initramfs-lvm-temp" \ - /sbin/lvm /sbin/dmsetup /sbin/thin_check \ - /sbin/thin_restore /sbin/thin_dump - - if [ -f /etc/lvm/lvm.conf ] - then - cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" || - gen_die 'Could not copy over lvm.conf!' - fi - cd "${TEMP}/initramfs-lvm-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing lvm cpio" - cd "${TEMP}" - rm -r "${TEMP}/initramfs-lvm-temp/" + if [ -d "${TEMP}/initramfs-lvm-temp" ] + then + rm -r "${TEMP}/initramfs-lvm-temp/" + fi + cd ${TEMP} + mkdir -p "${TEMP}/initramfs-lvm-temp"/{bin,sbin} + mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/" + print_info 1 'LVM: Adding support (copying binaries from system)...' + + local udev_dir="$(pkg-config --variable udevdir udev)" + udev_files=( $(qlist -e sys-fs/lvm2:0 | grep ^${udev_dir}/rules.d) ) + for f in "${udev_files[@]}"; do + [ -f "${f}" ] || gen_die "append_lvm: not a file: ${f}" + mkdir -p "${TEMP}/initramfs-lvm-temp"/$(dirname "${f}") || \ + gen_die "cannot create rules.d directory" + cp "${f}" "${TEMP}/initramfs-lvm-temp/${f}" || \ + gen_die "cannot copy ${f} from system" + done + + copy_binaries "${TEMP}/initramfs-lvm-temp" \ + /sbin/lvm /sbin/dmsetup /sbin/thin_check \ + /sbin/thin_restore /sbin/thin_dump + + if [ -f /etc/lvm/lvm.conf ] + then + cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" || + gen_die 'Could not copy over lvm.conf!' + fi + cd "${TEMP}/initramfs-lvm-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing lvm cpio" + cd "${TEMP}" + rm -r "${TEMP}/initramfs-lvm-temp/" } append_mdadm(){ - if [ -d "${TEMP}/initramfs-mdadm-temp" ] - then - rm -r "${TEMP}/initramfs-mdadm-temp/" - fi - cd ${TEMP} - mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/" - mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/" - - copy_binaries "${TEMP}/initramfs-mdadm-temp" \ - /sbin/mdadm /sbin/mdmon /sbin/mdassemble - - if [ -n "${MDADM_CONFIG}" ] - then - if [ -f "${MDADM_CONFIG}" ] - then - cp -a "${MDADM_CONFIG}" \ - "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \ - || gen_die "Could not copy mdadm.conf!" - else - gen_die 'sl${MDADM_CONFIG} does not exist!' - fi - else - print_info 1 ' MDADM: Skipping inclusion of mdadm.conf' - fi - - cd "${TEMP}/initramfs-mdadm-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing mdadm cpio" - cd "${TEMP}" - rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null + if [ -d "${TEMP}/initramfs-mdadm-temp" ] + then + rm -r "${TEMP}/initramfs-mdadm-temp/" + fi + cd ${TEMP} + mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/" + mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/" + + copy_binaries "${TEMP}/initramfs-mdadm-temp" \ + /sbin/mdadm /sbin/mdmon /sbin/mdassemble + + if [ -n "${MDADM_CONFIG}" ] + then + if [ -f "${MDADM_CONFIG}" ] + then + cp -a "${MDADM_CONFIG}" \ + "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \ + || gen_die "Could not copy mdadm.conf!" + else + gen_die 'sl${MDADM_CONFIG} does not exist!' + fi + else + print_info 1 ' MDADM: Skipping inclusion of mdadm.conf' + fi + + cd "${TEMP}/initramfs-mdadm-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing mdadm cpio" + cd "${TEMP}" + rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null } append_zfs(){ - if [ -d "${TEMP}/initramfs-zfs-temp" ] - then - rm -r "${TEMP}/initramfs-zfs-temp" - fi - - mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs" - - # Copy files to /etc/zfs - for i in zdev.conf zpool.cache - do - if [ -f /etc/zfs/${i} ] - then - print_info 1 " >> Including ${i}" - cp -a "/etc/zfs/${i}" "${TEMP}/initramfs-zfs-temp/etc/zfs" 2> /dev/null \ - || gen_die "Could not copy file ${i} for ZFS" - fi - done - - # Copy binaries - copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zfs,zpool} - - cd "${TEMP}/initramfs-zfs-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing zfs cpio" - cd "${TEMP}" - rm -rf "${TEMP}/initramfs-zfs-temp" > /dev/null + if [ -d "${TEMP}/initramfs-zfs-temp" ] + then + rm -r "${TEMP}/initramfs-zfs-temp" + fi + + mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs" + + # Copy files to /etc/zfs + for i in zdev.conf zpool.cache + do + if [ -f /etc/zfs/${i} ] + then + print_info 1 " >> Including ${i}" + cp -a "/etc/zfs/${i}" "${TEMP}/initramfs-zfs-temp/etc/zfs" 2> /dev/null \ + || gen_die "Could not copy file ${i} for ZFS" + fi + done + + # Copy binaries + copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zfs,zpool} + + cd "${TEMP}/initramfs-zfs-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing zfs cpio" + cd "${TEMP}" + rm -rf "${TEMP}/initramfs-zfs-temp" > /dev/null } append_btrfs() { - if [ -d "${TEMP}/initramfs-btrfs-temp" ] - then - rm -r "${TEMP}/initramfs-btrfs-temp" - fi - - # Copy binaries - copy_binaries "${TEMP}/initramfs-btrfs-temp" /sbin/btrfs - - cd "${TEMP}/initramfs-btrfs-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing btrfs cpio" - cd "${TEMP}" - rm -rf "${TEMP}/initramfs-btrfs-temp" > /dev/null + if [ -d "${TEMP}/initramfs-btrfs-temp" ] + then + rm -r "${TEMP}/initramfs-btrfs-temp" + fi + + # Copy binaries + copy_binaries "${TEMP}/initramfs-btrfs-temp" /sbin/btrfs + + cd "${TEMP}/initramfs-btrfs-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing btrfs cpio" + cd "${TEMP}" + rm -rf "${TEMP}/initramfs-btrfs-temp" > /dev/null } append_splash(){ - splash_geninitramfs=`which splash_geninitramfs 2>/dev/null` - if [ -x "${splash_geninitramfs}" ] - then - [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash - [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default - print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..." - if [ -d "${TEMP}/initramfs-splash-temp" ] - then - rm -r "${TEMP}/initramfs-splash-temp/" - fi - mkdir -p "${TEMP}/initramfs-splash-temp" - cd / - local tmp="" - [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}" - splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive" - if [ -e "/usr/share/splashutils/initrd.splash" ]; then - mkdir -p "${TEMP}/initramfs-splash-temp/etc" - cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc" - fi - cd "${TEMP}/initramfs-splash-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing splash cpio" - cd "${TEMP}" - rm -r "${TEMP}/initramfs-splash-temp/" - else - print_warning 1 ' >> No splash detected; skipping!' - fi + splash_geninitramfs=`which splash_geninitramfs 2>/dev/null` + if [ -x "${splash_geninitramfs}" ] + then + [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash + [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default + print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..." + if [ -d "${TEMP}/initramfs-splash-temp" ] + then + rm -r "${TEMP}/initramfs-splash-temp/" + fi + mkdir -p "${TEMP}/initramfs-splash-temp" + cd / + local tmp="" + [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}" + splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive" + if [ -e "/usr/share/splashutils/initrd.splash" ]; then + mkdir -p "${TEMP}/initramfs-splash-temp/etc" + cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc" + fi + cd "${TEMP}/initramfs-splash-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing splash cpio" + cd "${TEMP}" + rm -r "${TEMP}/initramfs-splash-temp/" + else + print_warning 1 ' >> No splash detected; skipping!' + fi } append_plymouth() { - [ -z "${PLYMOUTH_THEME}" ] && \ - PLYMOUTH_THEME=$(plymouth-set-default-theme) - [ -z "${PLYMOUTH_THEME}" ] && PLYMOUTH_THEME=text - - if [ -d "${TEMP}/initramfs-ply-temp" ] - then - rm -r "${TEMP}/initramfs-ply-temp" - fi - - mkdir -p "${TEMP}/initramfs-ply-temp/usr/share/plymouth/themes" - mkdir -p "${TEMP}/initramfs-ply-temp/etc/plymouth" - mkdir -p "${TEMP}/initramfs-ply-temp/"{bin,sbin} - - cd "${TEMP}/initramfs-ply-temp" - - local theme_dir="/usr/share/plymouth/themes" - local t= - - local p= - local ply="${theme_dir}/${PLYMOUTH_THEME}/${PLYMOUTH_THEME}.plymouth" - local plugin=$(grep "^ModuleName=" "${ply}" | cut -d= -f2-) - local plugin_binary= - if [ -n "${plugin}" ] - then - plugin_binary="$(plymouth --get-splash-plugin-path)/${plugin}.so" - fi - - print_info 1 " >> Installing plymouth [ using the ${PLYMOUTH_THEME} theme and plugin: \"${plugin}\" ]..." - - for t in text details ${PLYMOUTH_THEME}; do - cp -R "${theme_dir}/${t}" \ - "${TEMP}/initramfs-ply-temp${theme_dir}/" || \ - gen_die "cannot copy ${theme_dir}/details" - done - cp /usr/share/plymouth/{bizcom.png,plymouthd.defaults} \ - "${TEMP}/initramfs-ply-temp/usr/share/plymouth/" || \ - gen_die "cannot copy bizcom.png and plymouthd.defaults" - - # Do both config setup - echo -en "[Daemon]\nTheme=${PLYMOUTH_THEME}\n" > \ - "${TEMP}/initramfs-ply-temp/etc/plymouth/plymouthd.conf" || \ - gen_die "Cannot create /etc/plymouth/plymouthd.conf" - ln -sf "${PLYMOUTH_THEME}/${PLYMOUTH_THEME}.plymouth" \ - "${TEMP}/initramfs-ply-temp${theme_dir}/default.plymouth" || \ - gen_die "cannot setup the default plymouth theme" - - local libs=( - "/lib*/libply-splash-core.so.*" - "/usr/lib*/libply-splash-graphics.so.*" - "/usr/lib*/plymouth/text.so" - "/usr/lib*/plymouth/details.so" - "/usr/lib*/plymouth/renderers/frame-buffer.so" - "/usr/lib*/plymouth/renderers/drm.so" - "${plugin_binary}" - ) - # lib64 must take the precedence or all the cpio archive - # symlinks will be fubared - local slib= lib= final_lib= final_libs=() - for slib in "${libs[@]}"; do - lib=( ${slib} ) - final_lib="${lib[0]}" - final_libs+=( "${final_lib}" ) - done - - copy_binaries "${TEMP}/initramfs-ply-temp" \ - /sbin/plymouthd /bin/plymouth \ - "${final_libs[@]}" || gen_die "cannot copy plymouth" - - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "appending plymouth to cpio" - - cd "${TEMP}" - rm -r "${TEMP}/initramfs-ply-temp/" + [ -z "${PLYMOUTH_THEME}" ] && \ + PLYMOUTH_THEME=$(plymouth-set-default-theme) + [ -z "${PLYMOUTH_THEME}" ] && PLYMOUTH_THEME=text + + if [ -d "${TEMP}/initramfs-ply-temp" ] + then + rm -r "${TEMP}/initramfs-ply-temp" + fi + + mkdir -p "${TEMP}/initramfs-ply-temp/usr/share/plymouth/themes" + mkdir -p "${TEMP}/initramfs-ply-temp/etc/plymouth" + mkdir -p "${TEMP}/initramfs-ply-temp/"{bin,sbin} + + cd "${TEMP}/initramfs-ply-temp" + + local theme_dir="/usr/share/plymouth/themes" + local t= + + local p= + local ply="${theme_dir}/${PLYMOUTH_THEME}/${PLYMOUTH_THEME}.plymouth" + local plugin=$(grep "^ModuleName=" "${ply}" | cut -d= -f2-) + local plugin_binary= + if [ -n "${plugin}" ] + then + plugin_binary="$(plymouth --get-splash-plugin-path)/${plugin}.so" + fi + + print_info 1 " >> Installing plymouth [ using the ${PLYMOUTH_THEME} theme and plugin: \"${plugin}\" ]..." + + for t in text details ${PLYMOUTH_THEME}; do + cp -R "${theme_dir}/${t}" \ + "${TEMP}/initramfs-ply-temp${theme_dir}/" || \ + gen_die "cannot copy ${theme_dir}/details" + done + cp /usr/share/plymouth/{bizcom.png,plymouthd.defaults} \ + "${TEMP}/initramfs-ply-temp/usr/share/plymouth/" || \ + gen_die "cannot copy bizcom.png and plymouthd.defaults" + + # Do both config setup + echo -en "[Daemon]\nTheme=${PLYMOUTH_THEME}\n" > \ + "${TEMP}/initramfs-ply-temp/etc/plymouth/plymouthd.conf" || \ + gen_die "Cannot create /etc/plymouth/plymouthd.conf" + ln -sf "${PLYMOUTH_THEME}/${PLYMOUTH_THEME}.plymouth" \ + "${TEMP}/initramfs-ply-temp${theme_dir}/default.plymouth" || \ + gen_die "cannot setup the default plymouth theme" + + local libs=( + "/lib*/libply-splash-core.so.*" + "/usr/lib*/libply-splash-graphics.so.*" + "/usr/lib*/plymouth/text.so" + "/usr/lib*/plymouth/details.so" + "/usr/lib*/plymouth/renderers/frame-buffer.so" + "/usr/lib*/plymouth/renderers/drm.so" + "${plugin_binary}" + ) + # lib64 must take the precedence or all the cpio archive + # symlinks will be fubared + local slib= lib= final_lib= final_libs=() + for slib in "${libs[@]}"; do + lib=( ${slib} ) + final_lib="${lib[0]}" + final_libs+=( "${final_lib}" ) + done + + copy_binaries "${TEMP}/initramfs-ply-temp" \ + /sbin/plymouthd /bin/plymouth \ + "${final_libs[@]}" || gen_die "cannot copy plymouth" + + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "appending plymouth to cpio" + + cd "${TEMP}" + rm -r "${TEMP}/initramfs-ply-temp/" } append_overlay(){ - cd ${INITRAMFS_OVERLAY} - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing overlay cpio" + cd ${INITRAMFS_OVERLAY} + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing overlay cpio" } append_luks() { - local _luks_error_format="LUKS support cannot be included: %s. Please emerge sys-fs/cryptsetup[static]." - local _luks_source=/sbin/cryptsetup - local _luks_dest=/sbin/cryptsetup - - if [ -d "${TEMP}/initramfs-luks-temp" ] - then - rm -r "${TEMP}/initramfs-luks-temp/" - fi - - mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/" - mkdir -p "${TEMP}/initramfs-luks-temp/sbin" - cd "${TEMP}/initramfs-luks-temp" - - if isTrue ${LUKS} - then - [ -x "${_luks_source}" ] \ - || gen_die "$(printf "${_luks_error_format}" "no file ${_luks_source}")" - - print_info 1 "Including LUKS support" - copy_binaries "${TEMP}/initramfs-luks-temp/" /sbin/cryptsetup - fi - - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "appending cryptsetup to cpio" - - cd "${TEMP}" - rm -r "${TEMP}/initramfs-luks-temp/" + local _luks_error_format="LUKS support cannot be included: %s. Please emerge sys-fs/cryptsetup[static]." + local _luks_source=/sbin/cryptsetup + local _luks_dest=/sbin/cryptsetup + + if [ -d "${TEMP}/initramfs-luks-temp" ] + then + rm -r "${TEMP}/initramfs-luks-temp/" + fi + + mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/" + mkdir -p "${TEMP}/initramfs-luks-temp/sbin" + cd "${TEMP}/initramfs-luks-temp" + + if isTrue ${LUKS} + then + [ -x "${_luks_source}" ] \ + || gen_die "$(printf "${_luks_error_format}" "no file ${_luks_source}")" + + print_info 1 "Including LUKS support" + copy_binaries "${TEMP}/initramfs-luks-temp/" /sbin/cryptsetup + fi + + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "appending cryptsetup to cpio" + + cd "${TEMP}" + rm -r "${TEMP}/initramfs-luks-temp/" } append_firmware() { - if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ] - then - gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist" - fi - if [ -d "${TEMP}/initramfs-firmware-temp" ] - then - rm -r "${TEMP}/initramfs-firmware-temp/" - fi - mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware" - cd "${TEMP}/initramfs-firmware-temp" - if [ -n "${FIRMWARE_FILES}" ] - then - OLD_IFS=$IFS - IFS="," - for i in ${FIRMWARE_FILES} - do - cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/ - done - IFS=$OLD_IFS - else - cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/ - fi - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "appending firmware to cpio" - cd "${TEMP}" - rm -r "${TEMP}/initramfs-firmware-temp/" + if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ] + then + gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist" + fi + if [ -d "${TEMP}/initramfs-firmware-temp" ] + then + rm -r "${TEMP}/initramfs-firmware-temp/" + fi + mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware" + cd "${TEMP}/initramfs-firmware-temp" + if [ -n "${FIRMWARE_FILES}" ] + then + OLD_IFS=$IFS + IFS="," + for i in ${FIRMWARE_FILES} + do + cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/ + done + IFS=$OLD_IFS + else + cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/ + fi + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "appending firmware to cpio" + cd "${TEMP}" + rm -r "${TEMP}/initramfs-firmware-temp/" } append_gpg() { - if [ -d "${TEMP}/initramfs-gpg-temp" ] - then - rm -r "${TEMP}/initramfs-gpg-temp" - fi - mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/" - - print_info 1 "Including GPG support" - copy_binaries "${TEMP}/initramfs-gpg-temp" /usr/bin/gpg - - cd "${TEMP}/initramfs-gpg-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing gpg cpio" - cd "${TEMP}" - rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null + if [ -d "${TEMP}/initramfs-gpg-temp" ] + then + rm -r "${TEMP}/initramfs-gpg-temp" + fi + mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/" + + print_info 1 "Including GPG support" + copy_binaries "${TEMP}/initramfs-gpg-temp" /usr/bin/gpg + + cd "${TEMP}/initramfs-gpg-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing gpg cpio" + cd "${TEMP}" + rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null } append_udev() { - if [ -d "${TEMP}/initramfs-udev-temp" ] - then - rm -r "${TEMP}/initramfs-udev-temp" - fi - - local udev_dir="$(pkg-config --variable udevdir udev)" - udev_files=" - ${udev_dir}/rules.d/50-udev-default.rules - ${udev_dir}/rules.d/60-persistent-storage.rules - ${udev_dir}/rules.d/80-drivers.rules - /etc/udev/udev.conf - " - udev_maybe_files=" - ${udev_dir}/rules.d/40-gentoo.rules - ${udev_dir}/rules.d/99-systemd.rules - /etc/modprobe.d/blacklist.conf - " - is_maybe=0 - for f in ${udev_files} -- ${udev_maybe_files}; do - [ "${f}" = "--" ] && { - is_maybe=1; - continue; - } - mkdir -p "${TEMP}/initramfs-udev-temp"/$(dirname "${f}") || \ - gen_die "cannot create rules.d directory" - cp "${f}" "${TEMP}/initramfs-udev-temp/${f}" - if [ "${?}" != "0" ] - then - [ "${is_maybe}" = "0" ] && \ - gen_die "cannot copy ${f} from udev" - [ "${is_maybe}" = "1" ] && \ - print_warning 1 "cannot copy ${f} from udev" - fi - done - - # Copy binaries - copy_binaries "${TEMP}/initramfs-udev-temp" \ - /sbin/udevd /bin/udevadm "${udev_dir}/scsi_id" \ - "${udev_dir}/ata_id" "${udev_dir}/mtd_probe" - - cd "${TEMP}/initramfs-udev-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing udev cpio" - cd "${TEMP}" - rm -rf "${TEMP}/initramfs-udev-temp" > /dev/null + if [ -d "${TEMP}/initramfs-udev-temp" ] + then + rm -r "${TEMP}/initramfs-udev-temp" + fi + + local udev_dir="$(pkg-config --variable udevdir udev)" + udev_files=" + ${udev_dir}/rules.d/50-udev-default.rules + ${udev_dir}/rules.d/60-persistent-storage.rules + ${udev_dir}/rules.d/80-drivers.rules + /etc/udev/udev.conf + " + udev_maybe_files=" + ${udev_dir}/rules.d/40-gentoo.rules + ${udev_dir}/rules.d/99-systemd.rules + /etc/modprobe.d/blacklist.conf + " + is_maybe=0 + for f in ${udev_files} -- ${udev_maybe_files}; do + [ "${f}" = "--" ] && { + is_maybe=1; + continue; + } + mkdir -p "${TEMP}/initramfs-udev-temp"/$(dirname "${f}") || \ + gen_die "cannot create rules.d directory" + cp "${f}" "${TEMP}/initramfs-udev-temp/${f}" + if [ "${?}" != "0" ] + then + [ "${is_maybe}" = "0" ] && \ + gen_die "cannot copy ${f} from udev" + [ "${is_maybe}" = "1" ] && \ + print_warning 1 "cannot copy ${f} from udev" + fi + done + + # Copy binaries + copy_binaries "${TEMP}/initramfs-udev-temp" \ + /sbin/udevd /bin/udevadm "${udev_dir}/scsi_id" \ + "${udev_dir}/ata_id" "${udev_dir}/mtd_probe" + + cd "${TEMP}/initramfs-udev-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing udev cpio" + cd "${TEMP}" + rm -rf "${TEMP}/initramfs-udev-temp" > /dev/null } append_ld_so_conf() { - print_info 1 'ld.so.conf: adding /etc/ld.so.conf{.d/*,}...' - - local tmp_dir="${TEMP}/initramfs-ld-temp" - rm -rf "${tmp_dir}" - mkdir -p "${tmp_dir}" - - local f= f_dir= - for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do - if [ -f "${f}" ]; then - f_dir=$(dirname "${f}") - tmp_f_dir="${tmp_dir}/${f_dir}" - - mkdir -p "${tmp_f_dir}" || \ - gen_die "cannot create dir ${tmp_f_dir}" - cp -a "${f}" "${tmp_f_dir}/" || \ - gen_die "cannot copy ${f} to ${tmp_f_dir}" - fi - done - - cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing ld.so.conf.* cpio" - cd "$(dirname "${tmp_dir}")" - rm -rf "${tmp_dir}" - - # Unfortunately genkernel works by appending cruft over crut - # but we need to generate a valid ld.so.conf. So we extract the - # current CPIO archive, run ldconfig -r against it and append the - # last bits. - local tmp_dir_ext="${tmp_dir}/extracted" - mkdir -p "${tmp_dir_ext}" - mkdir -p "${tmp_dir}/etc" - cd "${tmp_dir_ext}" || gen_die "cannot cd into ${tmp_dir_ext}" - cpio -id --quiet < "${CPIO}" || gen_die "cannot re-extract ${CPIO}" - - cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" - ldconfig -r "${tmp_dir_ext}" || \ - gen_die "cannot run ldconfig on ${tmp_dir_ext}" - cp -a "${tmp_dir_ext}/etc/ld.so.cache" "${tmp_dir}/etc/ld.so.cache" || \ - gen_die "cannot copy ld.so.cache" - rm -rf "${tmp_dir_ext}" - - cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing ld.so.cache cpio" - cd "$(dirname "${tmp_dir}")" - rm -rf "${tmp_dir}" + print_info 1 'ld.so.conf: adding /etc/ld.so.conf{.d/*,}...' + + local tmp_dir="${TEMP}/initramfs-ld-temp" + rm -rf "${tmp_dir}" + mkdir -p "${tmp_dir}" + + local f= f_dir= + for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do + if [ -f "${f}" ]; then + f_dir=$(dirname "${f}") + tmp_f_dir="${tmp_dir}/${f_dir}" + + mkdir -p "${tmp_f_dir}" || \ + gen_die "cannot create dir ${tmp_f_dir}" + cp -a "${f}" "${tmp_f_dir}/" || \ + gen_die "cannot copy ${f} to ${tmp_f_dir}" + fi + done + + cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing ld.so.conf.* cpio" + cd "$(dirname "${tmp_dir}")" + rm -rf "${tmp_dir}" + + # Unfortunately genkernel works by appending cruft over crut + # but we need to generate a valid ld.so.conf. So we extract the + # current CPIO archive, run ldconfig -r against it and append the + # last bits. + local tmp_dir_ext="${tmp_dir}/extracted" + mkdir -p "${tmp_dir_ext}" + mkdir -p "${tmp_dir}/etc" + cd "${tmp_dir_ext}" || gen_die "cannot cd into ${tmp_dir_ext}" + cpio -id --quiet < "${CPIO}" || gen_die "cannot re-extract ${CPIO}" + + cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" + ldconfig -r "${tmp_dir_ext}" || \ + gen_die "cannot run ldconfig on ${tmp_dir_ext}" + cp -a "${tmp_dir_ext}/etc/ld.so.cache" "${tmp_dir}/etc/ld.so.cache" || \ + gen_die "cannot copy ld.so.cache" + rm -rf "${tmp_dir_ext}" + + cd "${tmp_dir}" || gen_die "cannot cd into ${tmp_dir}" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing ld.so.cache cpio" + cd "$(dirname "${tmp_dir}")" + rm -rf "${tmp_dir}" } print_list() { - local x - for x in ${*} - do - echo ${x} - done + local x + for x in ${*} + do + echo ${x} + done } append_modules() { - local group - local group_modules - local MOD_EXT=".ko" - - print_info 2 "initramfs: >> Searching for modules..." - if [ "${INSTALL_MOD_PATH}" != '' ] - then - cd ${INSTALL_MOD_PATH} - else - cd / - fi - - if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ] - then - rm -r "${TEMP}/initramfs-modules-${KV}-temp/" - fi - mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}" - for i in `gen_dep_list` - do - mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 ` - if [ -z "${mymod}" ] - then - print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..." - continue; - fi - - print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..." - cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp" - done - - cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null - - mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules" - for group_modules in ${!MODULES_*}; do - group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")" - print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}" - done - cd "${TEMP}/initramfs-modules-${KV}-temp/" - log_future_cpio_content - find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing modules cpio" - cd "${TEMP}" - rm -r "${TEMP}/initramfs-modules-${KV}-temp/" + local group + local group_modules + local MOD_EXT=".ko" + + print_info 2 "initramfs: >> Searching for modules..." + if [ "${INSTALL_MOD_PATH}" != '' ] + then + cd ${INSTALL_MOD_PATH} + else + cd / + fi + + if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ] + then + rm -r "${TEMP}/initramfs-modules-${KV}-temp/" + fi + mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}" + for i in `gen_dep_list` + do + mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 ` + if [ -z "${mymod}" ] + then + print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..." + continue; + fi + + print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..." + cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp" + done + + cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null + + mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules" + for group_modules in ${!MODULES_*}; do + group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")" + print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}" + done + cd "${TEMP}/initramfs-modules-${KV}-temp/" + log_future_cpio_content + find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing modules cpio" + cd "${TEMP}" + rm -r "${TEMP}/initramfs-modules-${KV}-temp/" } append_drm() { - local MOD_EXT=".ko" - - print_info 2 "initramfs: >> Appending drm drivers..." - if [ "${INSTALL_MOD_PATH}" != '' ] - then - cd ${INSTALL_MOD_PATH} - else - cd / - fi - - rm -rf "${TEMP}/initramfs-drm-${KV}-temp/" - mkdir -p "${TEMP}/initramfs-drm-${KV}-temp/lib/modules/${KV}" - - local drm_path="./lib/modules/${KV}/kernel/drivers/gpu/drm" - local modules - if [ -d "${drm_path}" ] - then - modules=$(strip_mod_paths $(find "${drm_path}" -name "*${MOD_EXT}")) - else - print_warning 2 "Warning :: no drm modules in drivers/gpu/drm..." - fi - - rm -f "${TEMP}/moddeps" - gen_deps ${modules} - if [ -f "${TEMP}/moddeps" ] - then - modules=$(cat "${TEMP}/moddeps" | sort | uniq) - else - print_warning 2 "Warning :: module dependencies not generated..." - fi - - local mod i fws fw - for i in ${modules} - do - mod=$(find "${drm_path}" -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1) - if [ -z "${mod}" ] - then - print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..." - continue - fi - - print_info 2 "initramfs: >> Copying ${mod}..." - cp -ax --parents "${mod}" "${TEMP}/initramfs-drm-${KV}-temp" - fws=( $(get_firmware_files "${mod}") ) - for fw in "${fws[@]}" - do - # we must use /lib/firmware because kernel may not - # contain all the firmware files and /lib/firmware is - # expected to be more up-to-date. - print_info 2 "initramfs: >> Copying firmware ${fw}..." - cp -ax --parents "/lib/firmware/${fw}" \ - "${TEMP}/initramfs-drm-${KV}-temp" - done - done - - cd "${TEMP}/initramfs-drm-${KV}-temp/" - log_future_cpio_content - find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing drm cpio" - cd "${TEMP}" - rm -r "${TEMP}/initramfs-drm-${KV}-temp/" + local MOD_EXT=".ko" + + print_info 2 "initramfs: >> Appending drm drivers..." + if [ "${INSTALL_MOD_PATH}" != '' ] + then + cd ${INSTALL_MOD_PATH} + else + cd / + fi + + rm -rf "${TEMP}/initramfs-drm-${KV}-temp/" + mkdir -p "${TEMP}/initramfs-drm-${KV}-temp/lib/modules/${KV}" + + local drm_path="./lib/modules/${KV}/kernel/drivers/gpu/drm" + local modules + if [ -d "${drm_path}" ] + then + modules=$(strip_mod_paths $(find "${drm_path}" -name "*${MOD_EXT}")) + else + print_warning 2 "Warning :: no drm modules in drivers/gpu/drm..." + fi + + rm -f "${TEMP}/moddeps" + gen_deps ${modules} + if [ -f "${TEMP}/moddeps" ] + then + modules=$(cat "${TEMP}/moddeps" | sort | uniq) + else + print_warning 2 "Warning :: module dependencies not generated..." + fi + + local mod i fws fw + for i in ${modules} + do + mod=$(find "${drm_path}" -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1) + if [ -z "${mod}" ] + then + print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..." + continue + fi + + print_info 2 "initramfs: >> Copying ${mod}..." + cp -ax --parents "${mod}" "${TEMP}/initramfs-drm-${KV}-temp" + fws=( $(get_firmware_files "${mod}") ) + for fw in "${fws[@]}" + do + # we must use /lib/firmware because kernel may not + # contain all the firmware files and /lib/firmware is + # expected to be more up-to-date. + print_info 2 "initramfs: >> Copying firmware ${fw}..." + cp -ax --parents "/lib/firmware/${fw}" \ + "${TEMP}/initramfs-drm-${KV}-temp" + done + done + + cd "${TEMP}/initramfs-drm-${KV}-temp/" + log_future_cpio_content + find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing drm cpio" + cd "${TEMP}" + rm -r "${TEMP}/initramfs-drm-${KV}-temp/" } # check for static linked file with objdump is_static() { - LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null - return $? + LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null + return $? } append_auxilary() { - if [ -d "${TEMP}/initramfs-aux-temp" ] - then - rm -r "${TEMP}/initramfs-aux-temp/" - fi - mkdir -p "${TEMP}/initramfs-aux-temp/etc" - mkdir -p "${TEMP}/initramfs-aux-temp/sbin" - if [ -f "${CMD_LINUXRC}" ] - then - cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init" - print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init" - else - if isTrue ${NETBOOT} - then - cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init" - else - if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ] - then - cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init" - else - cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init" - fi - fi - fi - - # Make sure it's executable - chmod 0755 "${TEMP}/initramfs-aux-temp/init" - - # Make a symlink to init .. incase we are bundled inside the kernel as one - # big cpio. - cd ${TEMP}/initramfs-aux-temp - ln -s init linuxrc -# ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc - - if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ] - then - cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts" - else - cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts" - fi - - if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ] - then - cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" - else - cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" - fi - - if [ -n "${REAL_ROOT}" ] - then - sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" - fi - - echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" - for group_modules in ${!MODULES_*}; do - group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")" - echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" - done - echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" - - if isTrue $CMD_DOKEYMAPAUTO - then - echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults - fi - if isTrue $CMD_KEYMAP - then - print_info 1 " >> Copying keymaps" - mkdir -p "${TEMP}/initramfs-aux-temp/lib/" - cp -R "${GK_SHARE}/defaults/keymaps" "${TEMP}/initramfs-aux-temp/lib/" \ - || gen_die "Error while copying keymaps" - fi - - cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init - cd ${TEMP} - chmod +x "${TEMP}/initramfs-aux-temp/init" - chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts" - chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" - - if isTrue ${NETBOOT} - then - cd "${GK_SHARE}/netboot/misc" - cp -pPRf * "${TEMP}/initramfs-aux-temp/" - fi - - cd "${TEMP}/initramfs-aux-temp/" - log_future_cpio_content - find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ - || gen_die "compressing auxilary cpio" - cd "${TEMP}" - rm -r "${TEMP}/initramfs-aux-temp/" + if [ -d "${TEMP}/initramfs-aux-temp" ] + then + rm -r "${TEMP}/initramfs-aux-temp/" + fi + mkdir -p "${TEMP}/initramfs-aux-temp/etc" + mkdir -p "${TEMP}/initramfs-aux-temp/sbin" + if [ -f "${CMD_LINUXRC}" ] + then + cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init" + print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init" + else + if isTrue ${NETBOOT} + then + cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init" + else + if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ] + then + cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init" + else + cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init" + fi + fi + fi + + # Make sure it's executable + chmod 0755 "${TEMP}/initramfs-aux-temp/init" + + # Make a symlink to init .. incase we are bundled inside the kernel as one + # big cpio. + cd ${TEMP}/initramfs-aux-temp + ln -s init linuxrc +# ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc + + if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ] + then + cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts" + else + cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts" + fi + + if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ] + then + cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" + else + cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" + fi + + if [ -n "${REAL_ROOT}" ] + then + sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" + fi + + echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" + for group_modules in ${!MODULES_*}; do + group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")" + echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" + done + echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" + + if isTrue $CMD_DOKEYMAPAUTO + then + echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults + fi + if isTrue $CMD_KEYMAP + then + print_info 1 " >> Copying keymaps" + mkdir -p "${TEMP}/initramfs-aux-temp/lib/" + cp -R "${GK_SHARE}/defaults/keymaps" "${TEMP}/initramfs-aux-temp/lib/" \ + || gen_die "Error while copying keymaps" + fi + + cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init + cd ${TEMP} + chmod +x "${TEMP}/initramfs-aux-temp/init" + chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts" + chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults" + + if isTrue ${NETBOOT} + then + cd "${GK_SHARE}/netboot/misc" + cp -pPRf * "${TEMP}/initramfs-aux-temp/" + fi + + cd "${TEMP}/initramfs-aux-temp/" + log_future_cpio_content + find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \ + || gen_die "compressing auxilary cpio" + cd "${TEMP}" + rm -r "${TEMP}/initramfs-aux-temp/" } append_data() { - local name=$1 var=$2 - local func="append_${name}" - - [ $# -eq 0 ] && gen_die "append_data() called with zero arguments" - if [ $# -eq 1 ] || isTrue ${var} - then - print_info 1 " >> Appending ${name} cpio data..." - ${func} || gen_die "${func}() failed" - fi + local name=$1 var=$2 + local func="append_${name}" + + [ $# -eq 0 ] && gen_die "append_data() called with zero arguments" + if [ $# -eq 1 ] || isTrue ${var} + then + print_info 1 " >> Appending ${name} cpio data..." + ${func} || gen_die "${func}() failed" + fi } create_initramfs() { - local compress_ext="" - print_info 1 "initramfs: >> Initializing..." - - # Create empty cpio - CPIO="${TMPDIR}/initramfs-${KV}" - echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \ - || gen_die "Could not create empty cpio at ${CPIO}" - - append_data 'base_layout' - append_data 'udev' "${UDEV}" - append_data 'auxilary' "${BUSYBOX}" - append_data 'busybox' "${BUSYBOX}" - isTrue "${CMD_E2FSPROGS}" && append_data 'e2fsprogs' - append_data 'lvm' "${LVM}" - append_data 'dmraid' "${DMRAID}" - append_data 'iscsi' "${ISCSI}" - append_data 'mdadm' "${MDADM}" - append_data 'luks' "${LUKS}" - append_data 'multipath' "${MULTIPATH}" - append_data 'gpg' "${GPG}" - - if [ "${RAMDISKMODULES}" = '1' ] - then - append_data 'modules' - else - print_info 1 "initramfs: Not copying modules..." - fi - - append_data 'zfs' "${ZFS}" - - append_data 'btrfs' "${BTRFS}" - - append_data 'blkid' - - append_data 'splash' "${SPLASH}" - - append_data 'plymouth' "${PLYMOUTH}" - isTrue "${PLYMOUTH}" && append_data 'drm' - - if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ] - then - append_data 'firmware' - fi - - # This should always be appended last - if [ "${INITRAMFS_OVERLAY}" != '' ] - then - append_data 'overlay' - fi - - # keep this at the very end, generates /etc/ld.so.conf* and cache - append_data 'ld_so_conf' - - # Finalize cpio by removing duplicate files - print_info 1 " >> Finalizing cpio..." - local TDIR="${TEMP}/initramfs-final" - mkdir -p "${TDIR}" - cd "${TDIR}" - - cpio --quiet -i -F "${CPIO}" 2> /dev/null \ - || gen_die "extracting cpio for finalization" - find . -print | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \ - || gen_die "recompressing cpio" - - cd "${TEMP}" - rm -r "${TDIR}" - - if isTrue "${INTEGRATED_INITRAMFS}" - then - # Explicitly do not compress if we are integrating into the kernel. - # The kernel will do a better job of it than us. - mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio - sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config - compress_config='INITRAMFS_COMPRESSION_NONE' - case ${compress_ext} in - gz) compress_config='INITRAMFS_COMPRESSION_GZIP' ;; - bz2) compress_config='INITRAMFS_COMPRESSION_BZIP2' ;; - lzma) compress_config='INITRAMFS_COMPRESSION_LZMA' ;; - xz) compress_config='INITRAMFS_COMPRESSION_XZ' ;; - lzo) compress_config='INITRAMFS_COMPRESSION_LZO' ;; - *) compress_config='INITRAMFS_COMPRESSION_NONE' ;; - esac - # All N default except XZ, so there it gets used if the kernel does - # compression on it's own. - cat >>${KERNEL_DIR}/.config <<-EOF - CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}" - CONFIG_INITRAMFS_ROOT_UID=0 - CONFIG_INITRAMFS_ROOT_GID=0 - CONFIG_INITRAMFS_COMPRESSION_NONE=n - CONFIG_INITRAMFS_COMPRESSION_GZIP=n - CONFIG_INITRAMFS_COMPRESSION_BZIP2=n - CONFIG_INITRAMFS_COMPRESSION_LZMA=n - CONFIG_INITRAMFS_COMPRESSION_XZ=y - CONFIG_INITRAMFS_COMPRESSION_LZO=n - CONFIG_${compress_config}=y - EOF - else - if isTrue "${COMPRESS_INITRD}" - then - # NOTE: We do not work with ${KERNEL_CONFIG} here, since things like - # "make oldconfig" or --noclean could be in effect. - if [ -f "${KERNEL_DIR}"/.config ]; then - local ACTUAL_KERNEL_CONFIG="${KERNEL_DIR}"/.config - else - local ACTUAL_KERNEL_CONFIG="${KERNEL_CONFIG}" - fi - - if [[ "$(file --brief --mime-type "${ACTUAL_KERNEL_CONFIG}")" == application/x-gzip ]]; then - # Support --kernel-config=/proc/config.gz, mainly - local CONFGREP=zgrep - else - local CONFGREP=grep - fi - - cmd_xz=$(type -p xz) - cmd_lzma=$(type -p lzma) - cmd_bzip2=$(type -p bzip2) - cmd_gzip=$(type -p gzip) - cmd_lzop=$(type -p lzop) - pkg_xz='app-arch/xz-utils' - pkg_lzma='app-arch/xz-utils' - pkg_bzip2='app-arch/bzip2' - pkg_gzip='app-arch/gzip' - pkg_lzop='app-arch/lzop' - local compression - case ${COMPRESS_INITRD_TYPE} in - xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;; - lzo) compression=lzop ;; - best|fastest) - for tuple in \ - 'CONFIG_RD_XZ cmd_xz xz' \ - 'CONFIG_RD_LZMA cmd_lzma lzma' \ - 'CONFIG_RD_BZIP2 cmd_bzip2 bzip2' \ - 'CONFIG_RD_GZIP cmd_gzip gzip' \ - 'CONFIG_RD_LZO cmd_lzop lzop'; do - set -- ${tuple} - kernel_option=$1 - cmd_variable_name=$2 - if ${CONFGREP} -q "^${kernel_option}=y" "${ACTUAL_KERNEL_CONFIG}" && test -n "${!cmd_variable_name}" ; then - compression=$3 - [[ ${COMPRESS_INITRD_TYPE} == best ]] && break - fi - done - [[ -z "${compression}" ]] && gen_die "None of the initramfs compression methods we tried are supported by your kernel (config file \"${ACTUAL_KERNEL_CONFIG}\"), strange!?" - ;; - *) - gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown" - ;; - esac - - # Check for actual availability - cmd_variable_name=cmd_${compression} - pkg_variable_name=pkg_${compression} - [[ -z "${!cmd_variable_name}" ]] && gen_die "Compression '${compression}' is not available. Please install package '${!pkg_variable_name}'." - - case $compression in - xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;; - lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;; - bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" ;; - gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;; - lzop) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;; - esac - if [ -n "${compression}" ]; then - print_info 1 " >> Compressing cpio data (${compress_ext})..." - ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed" - mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed" - else - print_info 1 " >> Not compressing cpio data ..." - fi - fi - fi - - if isTrue "${CMD_INSTALL}" - then - if ! isTrue "${INTEGRATED_INITRAMFS}" - then - copy_image_with_preserve "initramfs" \ - "${TMPDIR}/initramfs-${KV}" \ - "initramfs-${KNAME}-${ARCH}-${KV}" - fi - fi + local compress_ext="" + print_info 1 "initramfs: >> Initializing..." + + # Create empty cpio + CPIO="${TMPDIR}/initramfs-${KV}" + echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \ + || gen_die "Could not create empty cpio at ${CPIO}" + + append_data 'base_layout' + append_data 'udev' "${UDEV}" + append_data 'auxilary' "${BUSYBOX}" + append_data 'busybox' "${BUSYBOX}" + isTrue "${CMD_E2FSPROGS}" && append_data 'e2fsprogs' + append_data 'lvm' "${LVM}" + append_data 'dmraid' "${DMRAID}" + append_data 'iscsi' "${ISCSI}" + append_data 'mdadm' "${MDADM}" + append_data 'luks' "${LUKS}" + append_data 'multipath' "${MULTIPATH}" + append_data 'gpg' "${GPG}" + + if [ "${RAMDISKMODULES}" = '1' ] + then + append_data 'modules' + else + print_info 1 "initramfs: Not copying modules..." + fi + + append_data 'zfs' "${ZFS}" + + append_data 'btrfs' "${BTRFS}" + + append_data 'blkid' + + append_data 'splash' "${SPLASH}" + + append_data 'plymouth' "${PLYMOUTH}" + isTrue "${PLYMOUTH}" && append_data 'drm' + + if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ] + then + append_data 'firmware' + fi + + # This should always be appended last + if [ "${INITRAMFS_OVERLAY}" != '' ] + then + append_data 'overlay' + fi + + # keep this at the very end, generates /etc/ld.so.conf* and cache + append_data 'ld_so_conf' + + # Finalize cpio by removing duplicate files + print_info 1 " >> Finalizing cpio..." + local TDIR="${TEMP}/initramfs-final" + mkdir -p "${TDIR}" + cd "${TDIR}" + + cpio --quiet -i -F "${CPIO}" 2> /dev/null \ + || gen_die "extracting cpio for finalization" + find . -print | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \ + || gen_die "recompressing cpio" + + cd "${TEMP}" + rm -r "${TDIR}" + + if isTrue "${INTEGRATED_INITRAMFS}" + then + # Explicitly do not compress if we are integrating into the kernel. + # The kernel will do a better job of it than us. + mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio + sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config + compress_config='INITRAMFS_COMPRESSION_NONE' + case ${compress_ext} in + gz) compress_config='INITRAMFS_COMPRESSION_GZIP' ;; + bz2) compress_config='INITRAMFS_COMPRESSION_BZIP2' ;; + lzma) compress_config='INITRAMFS_COMPRESSION_LZMA' ;; + xz) compress_config='INITRAMFS_COMPRESSION_XZ' ;; + lzo) compress_config='INITRAMFS_COMPRESSION_LZO' ;; + *) compress_config='INITRAMFS_COMPRESSION_NONE' ;; + esac + # All N default except XZ, so there it gets used if the kernel does + # compression on it's own. + cat >>${KERNEL_DIR}/.config <<-EOF + CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}" + CONFIG_INITRAMFS_ROOT_UID=0 + CONFIG_INITRAMFS_ROOT_GID=0 + CONFIG_INITRAMFS_COMPRESSION_NONE=n + CONFIG_INITRAMFS_COMPRESSION_GZIP=n + CONFIG_INITRAMFS_COMPRESSION_BZIP2=n + CONFIG_INITRAMFS_COMPRESSION_LZMA=n + CONFIG_INITRAMFS_COMPRESSION_XZ=y + CONFIG_INITRAMFS_COMPRESSION_LZO=n + CONFIG_${compress_config}=y + EOF + else + if isTrue "${COMPRESS_INITRD}" + then + # NOTE: We do not work with ${KERNEL_CONFIG} here, since things like + # "make oldconfig" or --noclean could be in effect. + if [ -f "${KERNEL_DIR}"/.config ]; then + local ACTUAL_KERNEL_CONFIG="${KERNEL_DIR}"/.config + else + local ACTUAL_KERNEL_CONFIG="${KERNEL_CONFIG}" + fi + + if [[ "$(file --brief --mime-type "${ACTUAL_KERNEL_CONFIG}")" == application/x-gzip ]]; then + # Support --kernel-config=/proc/config.gz, mainly + local CONFGREP=zgrep + else + local CONFGREP=grep + fi + + cmd_xz=$(type -p xz) + cmd_lzma=$(type -p lzma) + cmd_bzip2=$(type -p bzip2) + cmd_gzip=$(type -p gzip) + cmd_lzop=$(type -p lzop) + pkg_xz='app-arch/xz-utils' + pkg_lzma='app-arch/xz-utils' + pkg_bzip2='app-arch/bzip2' + pkg_gzip='app-arch/gzip' + pkg_lzop='app-arch/lzop' + local compression + case ${COMPRESS_INITRD_TYPE} in + xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;; + lzo) compression=lzop ;; + best|fastest) + for tuple in \ + 'CONFIG_RD_XZ cmd_xz xz' \ + 'CONFIG_RD_LZMA cmd_lzma lzma' \ + 'CONFIG_RD_BZIP2 cmd_bzip2 bzip2' \ + 'CONFIG_RD_GZIP cmd_gzip gzip' \ + 'CONFIG_RD_LZO cmd_lzop lzop'; do + set -- ${tuple} + kernel_option=$1 + cmd_variable_name=$2 + if ${CONFGREP} -q "^${kernel_option}=y" "${ACTUAL_KERNEL_CONFIG}" && test -n "${!cmd_variable_name}" ; then + compression=$3 + [[ ${COMPRESS_INITRD_TYPE} == best ]] && break + fi + done + [[ -z "${compression}" ]] && gen_die "None of the initramfs compression methods we tried are supported by your kernel (config file \"${ACTUAL_KERNEL_CONFIG}\"), strange!?" + ;; + *) + gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown" + ;; + esac + + # Check for actual availability + cmd_variable_name=cmd_${compression} + pkg_variable_name=pkg_${compression} + [[ -z "${!cmd_variable_name}" ]] && gen_die "Compression '${compression}' is not available. Please install package '${!pkg_variable_name}'." + + case $compression in + xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;; + lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;; + bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" ;; + gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;; + lzop) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;; + esac + if [ -n "${compression}" ]; then + print_info 1 " >> Compressing cpio data (${compress_ext})..." + ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed" + mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed" + else + print_info 1 " >> Not compressing cpio data ..." + fi + fi + fi + + if isTrue "${CMD_INSTALL}" + then + if ! isTrue "${INTEGRATED_INITRAMFS}" + then + copy_image_with_preserve "initramfs" \ + "${TMPDIR}/initramfs-${KV}" \ + "initramfs-${KNAME}-${ARCH}-${KV}" + fi + fi } diff --git a/gen_moddeps.sh b/gen_moddeps.sh index 0867b56..27dab48 100755 --- a/gen_moddeps.sh +++ b/gen_moddeps.sh @@ -3,17 +3,17 @@ modules_kext() { - KEXT=".ko" - echo ${KEXT} + KEXT=".ko" + echo ${KEXT} } modules_dep_list() { - KEXT=$(modules_kext) - if [ -f ${INSTALL_MOD_PATH}/lib/modules/${KV}/modules.dep ] - then - cat ${INSTALL_MOD_PATH}/lib/modules/${KV}/modules.dep | grep ${1}${KEXT}\: | cut -d\: -f2 - fi + KEXT=$(modules_kext) + if [ -f ${INSTALL_MOD_PATH}/lib/modules/${KV}/modules.dep ] + then + cat ${INSTALL_MOD_PATH}/lib/modules/${KV}/modules.dep | grep ${1}${KEXT}\: | cut -d\: -f2 + fi } # Pass module deps list @@ -34,42 +34,42 @@ strip_mod_paths() gen_deps() { - local modlist - local deps + local modlist + local deps - for x in ${*} - do - echo ${x} >> ${TEMP}/moddeps - modlist=`modules_dep_list ${x}` - if [ "${modlist}" != "" -a "${modlist}" != " " ] - then - deps=`strip_mod_paths ${modlist}` - else - deps="" - fi - for y in ${deps} - do - echo ${y} >> ${TEMP}/moddeps - done - done + for x in ${*} + do + echo ${x} >> ${TEMP}/moddeps + modlist=`modules_dep_list ${x}` + if [ "${modlist}" != "" -a "${modlist}" != " " ] + then + deps=`strip_mod_paths ${modlist}` + else + deps="" + fi + for y in ${deps} + do + echo ${y} >> ${TEMP}/moddeps + done + done } gen_dep_list() { - if [ "${ALLRAMDISKMODULES}" = "1" ]; then - strip_mod_paths $(find "${INSTALL_MOD_PATH}/lib/modules/${KV}" -name "*$(modules_kext)") | sort - else - local group_modules - rm -f ${TEMP}/moddeps > /dev/null + if [ "${ALLRAMDISKMODULES}" = "1" ]; then + strip_mod_paths $(find "${INSTALL_MOD_PATH}/lib/modules/${KV}" -name "*$(modules_kext)") | sort + else + local group_modules + rm -f ${TEMP}/moddeps > /dev/null - for group_modules in ${!MODULES_*}; do - gen_deps ${!group_modules} - done + for group_modules in ${!MODULES_*}; do + gen_deps ${!group_modules} + done - # Only list each module once - if [ -f ${TEMP}/moddeps ] - then - cat ${TEMP}/moddeps | sort | uniq - fi - fi + # Only list each module once + if [ -f ${TEMP}/moddeps ] + then + cat ${TEMP}/moddeps | sort | uniq + fi + fi } diff --git a/gen_package.sh b/gen_package.sh index ed7a5f4..1970a85 100755 --- a/gen_package.sh +++ b/gen_package.sh @@ -2,210 +2,210 @@ # $Id$ gen_minkernpackage() { - print_info 1 'Creating minimal kernel package' - rm -rf "${TEMP}/minkernpackage" > /dev/null 2>&1 - mkdir "${TEMP}/minkernpackage" || gen_die 'Could not make a directory for the kernel package!' - if [ "${KERNCACHE}" != "" ] - then - /bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} kernel-${ARCH}-${KV} - /bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} config-${ARCH}-${KV} - if isTrue "${GENZIMAGE}" - then - /bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} kernelz-${ARCH}-${KV} - fi - else - local tmp_kernel_binary=$(find_kernel_binary ${KERNEL_BINARY}) - local tmp_kernel_binary2=$(find_kernel_binary ${KERNEL_BINARY_2}) - if [ -z "${tmp_kernel_binary}" ] - then - gen_die "Cannot locate kernel binary" - fi - cd "${KERNEL_OUTPUTDIR}" - cp "${tmp_kernel_binary}" "${TEMP}/minkernpackage/kernel-${KV}" || gen_die 'Could not the copy kernel for the min kernel package!' - cp ".config" "${TEMP}/minkernpackage/config-${ARCH}-${KV}" || gen_die 'Could not the copy kernel config for the min kernel package!' - if isTrue "${GENZIMAGE}" - then - cp "${tmp_kernel_binary2}" "${TEMP}/minkernpackage/kernelz-${KV}" || gen_die "Could not copy the kernelz for the min kernel package" - fi - fi - - if ! isTrue "${INTEGRATED_INITRAMFS}" - then - [ "${BUILD_RAMDISK}" != '0' ] && { cp "${TMPDIR}/initramfs-${KV}" "${TEMP}/minkernpackage/initramfs-${ARCH}-${KV}" || gen_die 'Could not copy the initramfs for the kernel package!'; } - fi - - if [ "${KERNCACHE}" != "" ] - then - /bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} System.map-${ARCH}-${KV} - else - cp "${KERNEL_OUTPUTDIR}/System.map" "${TEMP}/minkernpackage/System.map-${ARCH}-${KV}" || gen_die 'Could not copy System.map for the kernel package!'; - fi - - cd "${TEMP}/minkernpackage" - /bin/tar -jcpf ${MINKERNPACKAGE} * || gen_die 'Could not compress the kernel package!' - cd "${TEMP}" && rm -rf "${TEMP}/minkernpackage" > /dev/null 2>&1 + print_info 1 'Creating minimal kernel package' + rm -rf "${TEMP}/minkernpackage" > /dev/null 2>&1 + mkdir "${TEMP}/minkernpackage" || gen_die 'Could not make a directory for the kernel package!' + if [ "${KERNCACHE}" != "" ] + then + /bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} kernel-${ARCH}-${KV} + /bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} config-${ARCH}-${KV} + if isTrue "${GENZIMAGE}" + then + /bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} kernelz-${ARCH}-${KV} + fi + else + local tmp_kernel_binary=$(find_kernel_binary ${KERNEL_BINARY}) + local tmp_kernel_binary2=$(find_kernel_binary ${KERNEL_BINARY_2}) + if [ -z "${tmp_kernel_binary}" ] + then + gen_die "Cannot locate kernel binary" + fi + cd "${KERNEL_OUTPUTDIR}" + cp "${tmp_kernel_binary}" "${TEMP}/minkernpackage/kernel-${KV}" || gen_die 'Could not the copy kernel for the min kernel package!' + cp ".config" "${TEMP}/minkernpackage/config-${ARCH}-${KV}" || gen_die 'Could not the copy kernel config for the min kernel package!' + if isTrue "${GENZIMAGE}" + then + cp "${tmp_kernel_binary2}" "${TEMP}/minkernpackage/kernelz-${KV}" || gen_die "Could not copy the kernelz for the min kernel package" + fi + fi + + if ! isTrue "${INTEGRATED_INITRAMFS}" + then + [ "${BUILD_RAMDISK}" != '0' ] && { cp "${TMPDIR}/initramfs-${KV}" "${TEMP}/minkernpackage/initramfs-${ARCH}-${KV}" || gen_die 'Could not copy the initramfs for the kernel package!'; } + fi + + if [ "${KERNCACHE}" != "" ] + then + /bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} System.map-${ARCH}-${KV} + else + cp "${KERNEL_OUTPUTDIR}/System.map" "${TEMP}/minkernpackage/System.map-${ARCH}-${KV}" || gen_die 'Could not copy System.map for the kernel package!'; + fi + + cd "${TEMP}/minkernpackage" + /bin/tar -jcpf ${MINKERNPACKAGE} * || gen_die 'Could not compress the kernel package!' + cd "${TEMP}" && rm -rf "${TEMP}/minkernpackage" > /dev/null 2>&1 } gen_modulespackage() { - print_info 1 'Creating modules package' - rm -rf "${TEMP}/modulespackage" > /dev/null 2>&1 - mkdir "${TEMP}/modulespackage" || gen_die 'Could not make a directory for the kernel package!' - - if [ -d ${INSTALL_MOD_PATH}/lib/modules/${KV} ] - then - mkdir -p ${TEMP}/modulespackage/lib/modules - cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/modulespackage/lib/modules" - cd "${TEMP}/modulespackage" - /bin/tar -jcpf ${MODULESPACKAGE} * || gen_die 'Could not compress the modules package!' - else - print_info 1 "Could not create a modules package ${INSTALL_MOD_PATH}/lib/modules/${KV} was not found" - fi - cd "${TEMP}" && rm -rf "${TEMP}/modulespackage" > /dev/null 2>&1 + print_info 1 'Creating modules package' + rm -rf "${TEMP}/modulespackage" > /dev/null 2>&1 + mkdir "${TEMP}/modulespackage" || gen_die 'Could not make a directory for the kernel package!' + + if [ -d ${INSTALL_MOD_PATH}/lib/modules/${KV} ] + then + mkdir -p ${TEMP}/modulespackage/lib/modules + cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/modulespackage/lib/modules" + cd "${TEMP}/modulespackage" + /bin/tar -jcpf ${MODULESPACKAGE} * || gen_die 'Could not compress the modules package!' + else + print_info 1 "Could not create a modules package ${INSTALL_MOD_PATH}/lib/modules/${KV} was not found" + fi + cd "${TEMP}" && rm -rf "${TEMP}/modulespackage" > /dev/null 2>&1 } gen_kerncache() { - print_info 1 'Creating kernel cache' - rm -rf "${TEMP}/kerncache" > /dev/null 2>&1 - mkdir "${TEMP}/kerncache" || gen_die 'Could not make a directory for the kernel cache!' - - local tmp_kernel_binary=$(find_kernel_binary ${KERNEL_BINARY}) - local tmp_kernel_binary2=$(find_kernel_binary ${KERNEL_BINARY_2}) - if [ -z "${tmp_kernel_binary}" ] - then - gen_die "Cannot locate kernel binary" - fi - - cd "${KERNEL_OUTPUTDIR}" - cp "${tmp_kernel_binary}" "${TEMP}/kerncache/kernel-${ARCH}-${KV}" || gen_die 'Could not the copy kernel for the kernel package!' - cp "${KERNEL_OUTPUTDIR}/.config" "${TEMP}/kerncache/config-${ARCH}-${KV}" - - if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then - # Support --kernel-config=/proc/config.gz, mainly - zcat "${KERNEL_CONFIG}" > "${TEMP}/kerncache/config-${ARCH}-${KV}.orig" - else - cp "${KERNEL_CONFIG}" "${TEMP}/kerncache/config-${ARCH}-${KV}.orig" - fi - cp "${KERNEL_OUTPUTDIR}/System.map" "${TEMP}/kerncache/System.map-${ARCH}-${KV}" - if isTrue "${GENZIMAGE}" - then - cp "${tmp_kernel_binary2}" "${TEMP}/kerncache/kernelz-${ARCH}-${KV}" || gen_die "Could not copy the kernelz for the kernel package" - fi - - echo "VERSION = ${VER}" > "${TEMP}/kerncache/kerncache.config" - echo "PATCHLEVEL = ${PAT}" >> "${TEMP}/kerncache/kerncache.config" - echo "SUBLEVEL = ${SUB}" >> "${TEMP}/kerncache/kerncache.config" - echo "EXTRAVERSION = ${EXV}" >> "${TEMP}/kerncache/kerncache.config" - - mkdir -p "${TEMP}/kerncache/lib/modules/" - - if [ -d ${INSTALL_MOD_PATH}/lib/modules/${KV} ] - then - cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/kerncache/lib/modules" - fi - - cd "${TEMP}/kerncache" - /bin/tar -jcpf ${KERNCACHE} * || gen_die 'Could not compress the kernel package!' - cd "${TEMP}" && rm -rf "${TEMP}/kerncache" > /dev/null 2>&1 + print_info 1 'Creating kernel cache' + rm -rf "${TEMP}/kerncache" > /dev/null 2>&1 + mkdir "${TEMP}/kerncache" || gen_die 'Could not make a directory for the kernel cache!' + + local tmp_kernel_binary=$(find_kernel_binary ${KERNEL_BINARY}) + local tmp_kernel_binary2=$(find_kernel_binary ${KERNEL_BINARY_2}) + if [ -z "${tmp_kernel_binary}" ] + then + gen_die "Cannot locate kernel binary" + fi + + cd "${KERNEL_OUTPUTDIR}" + cp "${tmp_kernel_binary}" "${TEMP}/kerncache/kernel-${ARCH}-${KV}" || gen_die 'Could not the copy kernel for the kernel package!' + cp "${KERNEL_OUTPUTDIR}/.config" "${TEMP}/kerncache/config-${ARCH}-${KV}" + + if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then + # Support --kernel-config=/proc/config.gz, mainly + zcat "${KERNEL_CONFIG}" > "${TEMP}/kerncache/config-${ARCH}-${KV}.orig" + else + cp "${KERNEL_CONFIG}" "${TEMP}/kerncache/config-${ARCH}-${KV}.orig" + fi + cp "${KERNEL_OUTPUTDIR}/System.map" "${TEMP}/kerncache/System.map-${ARCH}-${KV}" + if isTrue "${GENZIMAGE}" + then + cp "${tmp_kernel_binary2}" "${TEMP}/kerncache/kernelz-${ARCH}-${KV}" || gen_die "Could not copy the kernelz for the kernel package" + fi + + echo "VERSION = ${VER}" > "${TEMP}/kerncache/kerncache.config" + echo "PATCHLEVEL = ${PAT}" >> "${TEMP}/kerncache/kerncache.config" + echo "SUBLEVEL = ${SUB}" >> "${TEMP}/kerncache/kerncache.config" + echo "EXTRAVERSION = ${EXV}" >> "${TEMP}/kerncache/kerncache.config" + + mkdir -p "${TEMP}/kerncache/lib/modules/" + + if [ -d ${INSTALL_MOD_PATH}/lib/modules/${KV} ] + then + cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/kerncache/lib/modules" + fi + + cd "${TEMP}/kerncache" + /bin/tar -jcpf ${KERNCACHE} * || gen_die 'Could not compress the kernel package!' + cd "${TEMP}" && rm -rf "${TEMP}/kerncache" > /dev/null 2>&1 } gen_kerncache_extract_kernel() { - /bin/tar -f ${KERNCACHE} -C ${TEMP} -xj - copy_image_with_preserve "kernel" \ - "${TEMP}/kernel-${ARCH}-${KV}" \ - "kernel-${KNAME}-${ARCH}-${KV}" - - if isTrue "${GENZIMAGE}" - then - copy_image_with_preserve "kernelz" \ - "${TEMP}/kernelz-${ARCH}-${KV}" \ - "kernelz-${KNAME}-${ARCH}-${KV}" - fi - - copy_image_with_preserve "System.map" \ - "${TEMP}/System.map-${ARCH}-${KV}" \ - "System.map-${KNAME}-${ARCH}-${KV}" + /bin/tar -f ${KERNCACHE} -C ${TEMP} -xj + copy_image_with_preserve "kernel" \ + "${TEMP}/kernel-${ARCH}-${KV}" \ + "kernel-${KNAME}-${ARCH}-${KV}" + + if isTrue "${GENZIMAGE}" + then + copy_image_with_preserve "kernelz" \ + "${TEMP}/kernelz-${ARCH}-${KV}" \ + "kernelz-${KNAME}-${ARCH}-${KV}" + fi + + copy_image_with_preserve "System.map" \ + "${TEMP}/System.map-${ARCH}-${KV}" \ + "System.map-${KNAME}-${ARCH}-${KV}" } gen_kerncache_extract_modules() { if [ -e "${KERNCACHE}" ] - then - print_info 1 'Extracting kerncache kernel modules' - if [ "${INSTALL_MOD_PATH}" != '' ] - then - /bin/tar -xjf ${KERNCACHE} -C ${INSTALL_MOD_PATH} lib - else - /bin/tar -xjf ${KERNCACHE} -C / lib - fi - fi + then + print_info 1 'Extracting kerncache kernel modules' + if [ "${INSTALL_MOD_PATH}" != '' ] + then + /bin/tar -xjf ${KERNCACHE} -C ${INSTALL_MOD_PATH} lib + else + /bin/tar -xjf ${KERNCACHE} -C / lib + fi + fi } gen_kerncache_extract_config() { - if [ -e "${KERNCACHE}" ] - then - print_info 1 'Extracting kerncache config to /etc/kernels' - mkdir -p /etc/kernels - /bin/tar -xjf ${KERNCACHE} -C /etc/kernels config-${ARCH}-${KV} - mv /etc/kernels/config-${ARCH}-${KV} /etc/kernels/kernel-config-${ARCH}-${KV} - fi + if [ -e "${KERNCACHE}" ] + then + print_info 1 'Extracting kerncache config to /etc/kernels' + mkdir -p /etc/kernels + /bin/tar -xjf ${KERNCACHE} -C /etc/kernels config-${ARCH}-${KV} + mv /etc/kernels/config-${ARCH}-${KV} /etc/kernels/kernel-config-${ARCH}-${KV} + fi } gen_kerncache_is_valid() { - KERNCACHE_IS_VALID=0 - if [ "${NO_KERNEL_SOURCES}" = '1' ] - then - - BUILD_KERNEL=0 - # Can make this more secure .... - - /bin/tar -xj -f ${KERNCACHE} -C ${TEMP} - if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${TEMP}/kernel-${ARCH}-${KV} ] - then - print_info 1 'Valid kernel cache found; no sources will be used' - KERNCACHE_IS_VALID=1 - fi - else - if [ -e "${KERNCACHE}" ] - then - KERNEL_CONFIG="/${KERNEL_OUTPUTDIR}/.config" - if [ "${CMD_KERNEL_CONFIG}" != '' ] - then - KERNEL_CONFIG="${CMD_KERNEL_CONFIG}" - fi - - /bin/tar -xj -f ${KERNCACHE} -C ${TEMP} - if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${KERNEL_CONFIG} ] - then - - if [ -e ${TEMP}/config-${ARCH}-${KV}.orig ] - then - test1=$(grep -v "^#" ${TEMP}/config-${ARCH}-${KV}.orig | md5sum | cut -d " " -f 1) - else - test1=$(grep -v "^#" ${TEMP}/config-${ARCH}-${KV} | md5sum | cut -d " " -f 1) - fi - - if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then - # Support --kernel-config=/proc/config.gz, mainly - local CONFGREP=zgrep - else - local CONFGREP=grep - fi - test2=$("${CONFGREP}" -v "^#" ${KERNEL_CONFIG} | md5sum | cut -d " " -f 1) - - - if [ "${test1}" == "${test2}" ] - then - echo - print_info 1 "No kernel configuration change, skipping kernel build..." - echo - KERNCACHE_IS_VALID=1 - fi - fi - fi - fi - export KERNCACHE_IS_VALID - return 1 + KERNCACHE_IS_VALID=0 + if [ "${NO_KERNEL_SOURCES}" = '1' ] + then + + BUILD_KERNEL=0 + # Can make this more secure .... + + /bin/tar -xj -f ${KERNCACHE} -C ${TEMP} + if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${TEMP}/kernel-${ARCH}-${KV} ] + then + print_info 1 'Valid kernel cache found; no sources will be used' + KERNCACHE_IS_VALID=1 + fi + else + if [ -e "${KERNCACHE}" ] + then + KERNEL_CONFIG="/${KERNEL_OUTPUTDIR}/.config" + if [ "${CMD_KERNEL_CONFIG}" != '' ] + then + KERNEL_CONFIG="${CMD_KERNEL_CONFIG}" + fi + + /bin/tar -xj -f ${KERNCACHE} -C ${TEMP} + if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${KERNEL_CONFIG} ] + then + + if [ -e ${TEMP}/config-${ARCH}-${KV}.orig ] + then + test1=$(grep -v "^#" ${TEMP}/config-${ARCH}-${KV}.orig | md5sum | cut -d " " -f 1) + else + test1=$(grep -v "^#" ${TEMP}/config-${ARCH}-${KV} | md5sum | cut -d " " -f 1) + fi + + if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then + # Support --kernel-config=/proc/config.gz, mainly + local CONFGREP=zgrep + else + local CONFGREP=grep + fi + test2=$("${CONFGREP}" -v "^#" ${KERNEL_CONFIG} | md5sum | cut -d " " -f 1) + + + if [ "${test1}" == "${test2}" ] + then + echo + print_info 1 "No kernel configuration change, skipping kernel build..." + echo + KERNCACHE_IS_VALID=1 + fi + fi + fi + fi + export KERNCACHE_IS_VALID + return 1 } diff --git a/genkernel b/genkernel index fe14d7b..3e6c565 100755 --- a/genkernel +++ b/genkernel @@ -16,11 +16,11 @@ small_die() { } parse_opt() { - case "$1" in - *\=*) - echo "$1" | cut -f2- -d= - ;; - esac + case "$1" in + *\=*) + echo "$1" | cut -f2- -d= + ;; + esac } # We don't know where our config is, so we check for it, and default to using @@ -28,8 +28,8 @@ parse_opt() { # NOTE: We are look for --config=... in a way that doesn't modify $@ since we access that again, later for (( i=1; i<=$# ; i=i+1 )); do - eval arg="\$$i" - [[ "${arg}" = --config=* ]] && CMD_GK_CONFIG=`parse_opt "${arg}"` + eval arg="\$$i" + [[ "${arg}" = --config=* ]] && CMD_GK_CONFIG=`parse_opt "${arg}"` done # Pull in our configuration @@ -52,27 +52,27 @@ source ${GK_SHARE}/gen_bootloader.sh || gen_die "Could not read ${GK_SHARE}/gen_ TEMP=${TMPDIR}/$RANDOM.$RANDOM.$RANDOM.$$ trap_cleanup(){ - # Call exit code of 1 for failure - cleanup - exit 1 + # Call exit code of 1 for failure + cleanup + exit 1 } cleanup(){ if [ -n "$TEMP" -a -d "$TEMP" ]; then - rm -rf "$TEMP" + rm -rf "$TEMP" fi if isTrue ${POSTCLEAR} then - echo - print_info 1 'RUNNING FINAL CACHE/TMP CLEANUP' - print_info 1 "CACHE_DIR: ${CACHE_DIR}" - CLEAR_CACHE_DIR='yes' - setup_cache_dir - echo - print_info 1 "TMPDIR: ${TMPDIR}" - clear_tmpdir - fi + echo + print_info 1 'RUNNING FINAL CACHE/TMP CLEANUP' + print_info 1 "CACHE_DIR: ${CACHE_DIR}" + CLEAR_CACHE_DIR='yes' + setup_cache_dir + echo + print_info 1 "TMPDIR: ${TMPDIR}" + clear_tmpdir + fi } trap trap_cleanup SIGHUP SIGQUIT SIGINT SIGTERM SIGKILL @@ -84,15 +84,15 @@ BUILD_MODULES=0 Options=$* # Save for later while [ $# -gt 0 ] do - Option=$1; shift - parse_cmdline $Option + Option=$1; shift + parse_cmdline $Option done # Check if no action is specified... if [ "${BUILD_KERNEL}" = '0' -a "${BUILD_RAMDISK}" = '0' ] then - usage - exit 1 + usage + exit 1 fi clear_log @@ -114,10 +114,10 @@ echo # Merge modules_load from config for group_modules in ${!AMODULES_*}; do - group="$(echo $group_modules | cut -d_ -f2)" - eval cmodules="\$$group_modules" - eval MODULES_${group}=\"\${MODULES_${group}} ${cmodules}\" - print_info 1 " Merged AMODULES_${group}:'${cmodules}' into MODULES_${group}" + group="$(echo $group_modules | cut -d_ -f2)" + eval cmodules="\$$group_modules" + eval MODULES_${group}=\"\${MODULES_${group}} ${cmodules}\" + print_info 1 " Merged AMODULES_${group}:'${cmodules}' into MODULES_${group}" done @@ -143,65 +143,65 @@ print_info 1 ".. with config file ${KERNEL_CONFIG}" # Check BOOTDIR is mounted if ! isTrue ${CMD_INSTALL} then - isTrue ${MOUNTBOOT} && print_info 2 'Skipping automatic mount of boot' + isTrue ${MOUNTBOOT} && print_info 2 'Skipping automatic mount of boot' else - [[ -d ${BOOTDIR} ]] || gen_die "${BOOTDIR} is not a directory" - - if ! egrep -q "[[:space:]]${BOOTDIR}[[:space:]]" /proc/mounts - then - if egrep -q "^[^#].+[[:space:]]${BOOTDIR}[[:space:]]" /etc/fstab - then - if isTrue ${MOUNTBOOT} - then - if ! mount ${BOOTDIR} - then - print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to mount ${BOOTDIR}!" - echo - else - print_info 1 "mount: ${BOOTDIR} mounted successfully!" - fi - else - print_warning 1 "${BOLD}WARNING${NORMAL}: No mounted ${BOOTDIR} partition detected!" - print_warning 1 " Run ``mount ${BOOTDIR}`` to mount it!" - echo - fi - fi - elif isBootRO - then - if isTrue ${MOUNTBOOT} - then - if ! mount -o remount,rw ${BOOTDIR} - then - print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to remount ${BOOTDIR} RW!" - echo - else - print_info 1 "mount: ${BOOTDIR} remounted read/write successfully!" - BOOTRW=1 - fi - fi - fi + [[ -d ${BOOTDIR} ]] || gen_die "${BOOTDIR} is not a directory" + + if ! egrep -q "[[:space:]]${BOOTDIR}[[:space:]]" /proc/mounts + then + if egrep -q "^[^#].+[[:space:]]${BOOTDIR}[[:space:]]" /etc/fstab + then + if isTrue ${MOUNTBOOT} + then + if ! mount ${BOOTDIR} + then + print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to mount ${BOOTDIR}!" + echo + else + print_info 1 "mount: ${BOOTDIR} mounted successfully!" + fi + else + print_warning 1 "${BOLD}WARNING${NORMAL}: No mounted ${BOOTDIR} partition detected!" + print_warning 1 " Run ``mount ${BOOTDIR}`` to mount it!" + echo + fi + fi + elif isBootRO + then + if isTrue ${MOUNTBOOT} + then + if ! mount -o remount,rw ${BOOTDIR} + then + print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to remount ${BOOTDIR} RW!" + echo + else + print_info 1 "mount: ${BOOTDIR} remounted read/write successfully!" + BOOTRW=1 + fi + fi + fi fi ## Check whether another Genkernel is running #GENPIDS="`ps -C genkernel --no-headers -o pid | wc -l`" #if [ "${GENPIDS}" -gt '3' ] #then -# [ "${GENPIDS}" -gt '4' ] && EX='s' -# print_warning 1 "${BOLD}WARNING${NORMAL}: Another Genkernel instance is running under" -# print_warning 1 " process ID${EX} " 0 -# GENPIDS=`ps -C genkernel --no-headers -o pid` -# echo -n "${GENPIDS}" | sed -e "s/$$//; s/ /, /g" -# echo 'halting...' -# echo -# print_warning 1 'Running multiple genkernels on the same source tree will cause data loss!' -# print_info 1 "Press ^C to halt; ^D to continue [ ${BOLD}if${NORMAL} you know what you're doing! ]" -# echo -# CTEMP="${TEMP}" -# TEMP=${TMPDIR-/tmp} -# TEMP=${TEMP}/genkernel.$RANDOM.$RANDOM.$RANDOM.$$ -# print_info 1 'thread: Running multiple genkernels may cause problems!' -# print_info 1 "thread: Temporary files reallocated to ${TEMP}..." -# echo +# [ "${GENPIDS}" -gt '4' ] && EX='s' +# print_warning 1 "${BOLD}WARNING${NORMAL}: Another Genkernel instance is running under" +# print_warning 1 " process ID${EX} " 0 +# GENPIDS=`ps -C genkernel --no-headers -o pid` +# echo -n "${GENPIDS}" | sed -e "s/$$//; s/ /, /g" +# echo 'halting...' +# echo +# print_warning 1 'Running multiple genkernels on the same source tree will cause data loss!' +# print_info 1 "Press ^C to halt; ^D to continue [ ${BOLD}if${NORMAL} you know what you're doing! ]" +# echo +# CTEMP="${TEMP}" +# TEMP=${TMPDIR-/tmp} +# TEMP=${TEMP}/genkernel.$RANDOM.$RANDOM.$RANDOM.$$ +# print_info 1 'thread: Running multiple genkernels may cause problems!' +# print_info 1 "thread: Temporary files reallocated to ${TEMP}..." +# echo #fi KERNCACHE_IS_VALID=0 @@ -212,101 +212,101 @@ fi if [ ${BUILD_KERNEL} = '1' -a "${KERNCACHE_IS_VALID}" = '0' ] then - # Configure kernel - config_kernel - - # Make prepare - if [ "${ARCH_HAVENOPREPARE}" = '' ] - then - compile_generic prepare kernel - fi - - # KV may have changed due to the configuration - get_KV - - compile_kernel - - # Compile modules - if [ "${BUILD_MODULES}" = '1' -a "${BUILD_STATIC}" = '0' ] - then - compile_modules - fi - - if [ "${SAVE_CONFIG}" = '1' ] - then - print_info 1 "Copying config for successful build to /etc/kernels/kernel-config-${ARCH}-${KV}" - [ ! -e '/etc/kernels' ] && mkdir -p /etc/kernels - cp "${KERNEL_OUTPUTDIR}/.config" "/etc/kernels/kernel-config-${ARCH}-${KV}" || \ - print_warning "Unable to copy the kernel configuration file." - # Just a warning because ordinary users are not allowed to write in /etc - fi + # Configure kernel + config_kernel + + # Make prepare + if [ "${ARCH_HAVENOPREPARE}" = '' ] + then + compile_generic prepare kernel + fi + + # KV may have changed due to the configuration + get_KV + + compile_kernel + + # Compile modules + if [ "${BUILD_MODULES}" = '1' -a "${BUILD_STATIC}" = '0' ] + then + compile_modules + fi + + if [ "${SAVE_CONFIG}" = '1' ] + then + print_info 1 "Copying config for successful build to /etc/kernels/kernel-config-${ARCH}-${KV}" + [ ! -e '/etc/kernels' ] && mkdir -p /etc/kernels + cp "${KERNEL_OUTPUTDIR}/.config" "/etc/kernels/kernel-config-${ARCH}-${KV}" || \ + print_warning "Unable to copy the kernel configuration file." + # Just a warning because ordinary users are not allowed to write in /etc + fi fi if isTrue "${CMD_INSTALL}" then - if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ] - then - gen_kerncache_extract_kernel - fi + if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ] + then + gen_kerncache_extract_kernel + fi fi if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ] then - [ "${BUILD_STATIC}" = '0' ] && gen_kerncache_extract_modules - gen_kerncache_extract_config + [ "${BUILD_STATIC}" = '0' ] && gen_kerncache_extract_modules + gen_kerncache_extract_config fi # Run callback if [ "${CMD_CALLBACK}" != "" ] then - print_info 1 "" 1 0 - print_info 1 "Preparing to run callback: \"${CMD_CALLBACK}\"" 0 - - CALLBACK_ESCAPE=0 - CALLBACK_COUNT=0 - - trap "CALLBACK_ESCAPE=1" TERM KILL INT QUIT ABRT - while [[ "${CALLBACK_ESCAPE}" = '0' && ${CALLBACK_COUNT} -lt 5 ]] - do - sleep 1; echo -n '.'; - let CALLBACK_COUNT=${CALLBACK_COUNT}+1 - done - - if [ "${CALLBACK_ESCAPE}" = '0' ] - then - echo - echo - eval ${CMD_CALLBACK} | tee -a ${LOGFILE} - CMD_STATUS="${PIPESTATUS[0]}" - echo - print_info 1 "<<< Callback exit status: ${CMD_STATUS}" - [ "${CMD_STATUS}" != '0' ] && gen_die '--callback failed!' - else - echo - print_info 1 ">>> Callback cancelled..." - fi - trap - TERM KILL INT QUIT ABRT - print_info 1 "" 1 0 + print_info 1 "" 1 0 + print_info 1 "Preparing to run callback: \"${CMD_CALLBACK}\"" 0 + + CALLBACK_ESCAPE=0 + CALLBACK_COUNT=0 + + trap "CALLBACK_ESCAPE=1" TERM KILL INT QUIT ABRT + while [[ "${CALLBACK_ESCAPE}" = '0' && ${CALLBACK_COUNT} -lt 5 ]] + do + sleep 1; echo -n '.'; + let CALLBACK_COUNT=${CALLBACK_COUNT}+1 + done + + if [ "${CALLBACK_ESCAPE}" = '0' ] + then + echo + echo + eval ${CMD_CALLBACK} | tee -a ${LOGFILE} + CMD_STATUS="${PIPESTATUS[0]}" + echo + print_info 1 "<<< Callback exit status: ${CMD_STATUS}" + [ "${CMD_STATUS}" != '0' ] && gen_die '--callback failed!' + else + echo + print_info 1 ">>> Callback cancelled..." + fi + trap - TERM KILL INT QUIT ABRT + print_info 1 "" 1 0 fi if [ "${BUILD_RAMDISK}" = '1' ] then - if [ "${BUSYBOX}" = '1' ] - then - # Compile Busybox - compile_busybox - fi - - # Compile initramfs - create_initramfs + if [ "${BUSYBOX}" = '1' ] + then + # Compile Busybox + compile_busybox + fi + + # Compile initramfs + create_initramfs else - print_info 1 'initrd: Not building since only the kernel was requested...' + print_info 1 'initrd: Not building since only the kernel was requested...' fi if isTrue "${INTEGRATED_INITRAMFS}" #|| [ "${BUILD_KERNEL}" = '1' -a "${KERNCACHE_IS_VALID}" == "0" ] then - # We build the kernel a second time to include the initramfs - compile_kernel + # We build the kernel a second time to include the initramfs + compile_kernel fi [ "${KERNCACHE}" != "" ] && gen_kerncache @@ -318,58 +318,58 @@ fi if [ "${BUILD_KERNEL}" = '1' ] then - if isTrue "${CMD_INSTALL}" - then - set_bootloader - fi - print_info 1 '' - print_info 1 "Kernel compiled successfully!" - print_info 1 '' - print_info 1 'Required Kernel Parameters:' - print_info 1 ' root=/dev/$ROOT' - if [ "${BUILD_RAMDISK}" = '0' ] - then - print_info 1 ' [ And "vga=0x317 splash=verbose" if you use a framebuffer ]' - print_info 1 '' - print_info 1 ' Where $ROOT is the device node for your root partition as the' - print_info 1 ' one specified in /etc/fstab' - else - print_info 1 '' - print_info 1 ' Where $ROOT is the device node for your root partition as the' - print_info 1 ' one specified in /etc/fstab' - print_info 1 '' - print_info 1 "If you require Genkernel's hardware detection features; you MUST" - print_info 1 'tell your bootloader to use the provided INITRAMFS file.' - fi + if isTrue "${CMD_INSTALL}" + then + set_bootloader + fi + print_info 1 '' + print_info 1 "Kernel compiled successfully!" + print_info 1 '' + print_info 1 'Required Kernel Parameters:' + print_info 1 ' root=/dev/$ROOT' + if [ "${BUILD_RAMDISK}" = '0' ] + then + print_info 1 ' [ And "vga=0x317 splash=verbose" if you use a framebuffer ]' + print_info 1 '' + print_info 1 ' Where $ROOT is the device node for your root partition as the' + print_info 1 ' one specified in /etc/fstab' + else + print_info 1 '' + print_info 1 ' Where $ROOT is the device node for your root partition as the' + print_info 1 ' one specified in /etc/fstab' + print_info 1 '' + print_info 1 "If you require Genkernel's hardware detection features; you MUST" + print_info 1 'tell your bootloader to use the provided INITRAMFS file.' + fi fi if [ "${BUILD_RAMDISK}" = '1' ] then - echo - print_warning 1 'WARNING... WARNING... WARNING...' - print_warning 1 'Additional kernel cmdline arguments that *may* be required to boot properly...' - [ "${SPLASH}" = '1' ] && print_warning 1 "add \"vga=791 splash=silent,theme:${SPLASH_THEME} console=tty1 quiet\" if you use a splash framebuffer ]" - [ "${LVM}" = '1' ] && print_warning 1 'add "dolvm" for lvm support' - [ "${DMRAID}" = '1' ] && print_warning 1 'add "dodmraid" for dmraid support' - [ "${MDADM}" = '1' ] && print_warning 1 'add "domdadm" for RAID support' - [ "${DMRAID}" = '1' ] && print_warning 1 ' or "dodmraid="' - [ "${ZFS}" = '1' ] && print_warning 1 'add "dozfs" for ZFS volume management support' - [ "${ZFS}" = '1' ] && print_warning 1 ' and either "root=ZFS" to use bootfs autodetection or "root=ZFS=" to force booting from a specific dataset' - [ "${ISCSI}" = '1' ] && print_warning 1 'add at least "iscsi_initiatorname= iscsi_target= and iscsi_address=" for iscsi support' - - if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then - # Support --kernel-config=/proc/config.gz, mainly - CONFGREP=zgrep - else - CONFGREP=grep - fi - - if [ `${CONFGREP} 'CONFIG_EXT[0-9]_FS=' "${KERNEL_CONFIG}" | wc -l` -ge 2 ]; then - print_warning 1 'With support for several ext* filesystems available, it may be needed to' - print_warning 1 'add "rootfstype=ext3" or "rootfstype=ext4" to the list of boot parameters.' - fi - - unset CONFGREP + echo + print_warning 1 'WARNING... WARNING... WARNING...' + print_warning 1 'Additional kernel cmdline arguments that *may* be required to boot properly...' + [ "${SPLASH}" = '1' ] && print_warning 1 "add \"vga=791 splash=silent,theme:${SPLASH_THEME} console=tty1 quiet\" if you use a splash framebuffer ]" + [ "${LVM}" = '1' ] && print_warning 1 'add "dolvm" for lvm support' + [ "${DMRAID}" = '1' ] && print_warning 1 'add "dodmraid" for dmraid support' + [ "${MDADM}" = '1' ] && print_warning 1 'add "domdadm" for RAID support' + [ "${DMRAID}" = '1' ] && print_warning 1 ' or "dodmraid="' + [ "${ZFS}" = '1' ] && print_warning 1 'add "dozfs" for ZFS volume management support' + [ "${ZFS}" = '1' ] && print_warning 1 ' and either "root=ZFS" to use bootfs autodetection or "root=ZFS=" to force booting from a specific dataset' + [ "${ISCSI}" = '1' ] && print_warning 1 'add at least "iscsi_initiatorname= iscsi_target= and iscsi_address=" for iscsi support' + + if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then + # Support --kernel-config=/proc/config.gz, mainly + CONFGREP=zgrep + else + CONFGREP=grep + fi + + if [ `${CONFGREP} 'CONFIG_EXT[0-9]_FS=' "${KERNEL_CONFIG}" | wc -l` -ge 2 ]; then + print_warning 1 'With support for several ext* filesystems available, it may be needed to' + print_warning 1 'add "rootfstype=ext3" or "rootfstype=ext4" to the list of boot parameters.' + fi + + unset CONFGREP fi [ "${BOOTRW}" != '' ] && mount -o remount,ro ${BOOTDIR} diff --git a/genkernel.bash b/genkernel.bash index ed6b1c1..8752eac 100644 --- a/genkernel.bash +++ b/genkernel.bash @@ -13,7 +13,7 @@ _genkernel() # extract initial list of params/actions from genkernel --help genkernel_help=$(command genkernel --help) actions=( $(<<<"$genkernel_help" sed -n \ - '/^Available Actions:/,/^$/s/^[[:space:]]\+\([^[:space:]]\+\).*/\1/p') ) + '/^Available Actions:/,/^$/s/^[[:space:]]\+\([^[:space:]]\+\).*/\1/p') ) params=( $(<<<"$genkernel_help" egrep -oe '--[^[:space:]]{2,}') ) # attempt to complete the current parameter based on the list @@ -21,22 +21,22 @@ _genkernel() # if we don't have a rhs to complete if [[ ${#COMPREPLY[@]} -gt 1 ]]; then - return + return elif [[ ${#COMPREPLY[@]} -eq 0 && $cur != --*=* ]]; then - return + return elif [[ ${#COMPREPLY[@]} -eq 1 && $COMPREPLY != --*= ]]; then - # using nospace completion, add an explicit space - COMPREPLY="${COMPREPLY} " - return + # using nospace completion, add an explicit space + COMPREPLY="${COMPREPLY} " + return fi # we have a unique lhs and need to complete the rhs declare args lhs rhs if [[ ${#COMPREPLY[@]} -eq 1 ]]; then - lhs=$COMPREPLY + lhs=$COMPREPLY else - lhs=${cur%%=*}= - rhs=${cur#*=} + lhs=${cur%%=*}= + rhs=${cur#*=} fi # genkernel's help gives clues as to what belongs on the rhs. @@ -48,25 +48,25 @@ _genkernel() # generate a list of completions for the argument; this replaces args with # an array of results args=( $(case $args in - ('<0-5>') compgen -W "$(echo {1..5})" -- "$rhs" ;; - (''|'') compgen -A file -o plusdirs -- "$rhs" ;; - ('') compgen -A directory -S / -- "$rhs" ;; - ('') compgen -G '*.tbz2' -G '*.tar.bz2' -o plusdirs -- "$rhs" ;; - (*) compgen -o bashdefault -- "$rhs" ;; # punt + ('<0-5>') compgen -W "$(echo {1..5})" -- "$rhs" ;; + (''|'') compgen -A file -o plusdirs -- "$rhs" ;; + ('') compgen -A directory -S / -- "$rhs" ;; + ('') compgen -G '*.tbz2' -G '*.tar.bz2' -o plusdirs -- "$rhs" ;; + (*) compgen -o bashdefault -- "$rhs" ;; # punt esac) ) # we're using nospace completion to prevent spaces after paths that aren't # "done" yet. So do some hacking to the args to add spaces after # non-directories. declare slash=/ - args=( "${args[@]/%/ }" ) # add space to all - args=( "${args[@]/%$slash /$slash}" ) # remove space from dirs + args=( "${args[@]/%/ }" ) # add space to all + args=( "${args[@]/%$slash /$slash}" ) # remove space from dirs # recreate COMPREPLY if [[ $cur == "$lhs"* ]]; then - COMPREPLY=( "${args[@]}" ) + COMPREPLY=( "${args[@]}" ) elif [[ ${#args[@]} -gt 0 ]]; then - COMPREPLY=( "${args[@]/#/$lhs}" ) + COMPREPLY=( "${args[@]/#/$lhs}" ) fi } diff --git a/maintenance/docmatcher.py b/maintenance/docmatcher.py index 5a4b0d8..c2773c2 100644 --- a/maintenance/docmatcher.py +++ b/maintenance/docmatcher.py @@ -10,18 +10,18 @@ import os NON_VARIABLES = ('UTF', 'USE', 'TCP', 'SMP', 'PXE', 'PPC', 'MAC', - 'GTK', 'GNU', 'CPU', 'DOS', 'NIC', 'NFS', 'ISO', 'TIMEOUT', - 'TFTP', 'SYSTEM', 'SPARC', 'RAID', 'LABEL', 'PROMPT', 'KERNEL', - 'GRP', 'DOCTYPE', 'DHCP', 'DEFAULT', 'ATARAID', 'APPEND') + 'GTK', 'GNU', 'CPU', 'DOS', 'NIC', 'NFS', 'ISO', 'TIMEOUT', + 'TFTP', 'SYSTEM', 'SPARC', 'RAID', 'LABEL', 'PROMPT', 'KERNEL', + 'GRP', 'DOCTYPE', 'DHCP', 'DEFAULT', 'ATARAID', 'APPEND') NON_CONFIG_VARIABLES = ('BUILD_KERNEL', 'BUILD_MODULES', 'BUILD_RAMDISK', - 'TERM_COLUMNS', 'TERM_LINES', 'SPLASH_RES', 'TEMP') + 'TERM_COLUMNS', 'TERM_LINES', 'SPLASH_RES', 'TEMP') EXTRA_VARIABLES = ['ARCH_OVERRIDE', 'BOOTLOADER', 'CLEAR_CACHE_DIR', 'DEFAULT_KERNEL_SOURCE', 'DISTDIR', 'GK_SHARE', 'BUSYBOX_APPLETS'] for app in ('DEVICE_MAPPER', 'BUSYBOX', 'DMRAID', 'LVM', 'ISCSI', 'GPG', 'MDADM'): - for prop in ('DIR', 'SRCTAR', 'VER'): - EXTRA_VARIABLES.append('%s_%s' % (app, prop)) + for prop in ('DIR', 'SRCTAR', 'VER'): + EXTRA_VARIABLES.append('%s_%s' % (app, prop)) EXTRA_VARIABLES = tuple(EXTRA_VARIABLES) IGNORE_OPTIONS = ('help', 'version') @@ -31,265 +31,265 @@ DEPRECATED_PARAMETERS = ('lvm2', 'gensplash', 'gensplash-res') def exract_gen_cmdline_sh(): - f = open('gen_cmdline.sh', 'r') - gen_cmdline_sh = f.read() - f.close() + f = open('gen_cmdline.sh', 'r') + gen_cmdline_sh = f.read() + f.close() - usage_lines = list() - parsing_lines = list() - dest = None + usage_lines = list() + parsing_lines = list() + dest = None - for line in gen_cmdline_sh.split('\n'): - if line in ('longusage() {', 'usage() {'): - dest = usage_lines - elif line == 'parse_cmdline() {': - dest = parsing_lines + for line in gen_cmdline_sh.split('\n'): + if line in ('longusage() {', 'usage() {'): + dest = usage_lines + elif line == 'parse_cmdline() {': + dest = parsing_lines - if dest is not None: - dest.append(line) + if dest is not None: + dest.append(line) - if line == '}': - dest = None + if line == '}': + dest = None - del gen_cmdline_sh + del gen_cmdline_sh - parsing_code = '\n'.join(parsing_lines) - del parsing_lines + parsing_code = '\n'.join(parsing_lines) + del parsing_lines - gen_cmdline_sh_parsing_long_params = set() - for match in re.finditer('--([a-z][a-z0-9-]+)', parsing_code): - para_name = match.group(1) - if para_name in IGNORE_OPTIONS: - continue - if para_name in DEPRECATED_PARAMETERS: - continue - gen_cmdline_sh_parsing_long_params.add(para_name) + gen_cmdline_sh_parsing_long_params = set() + for match in re.finditer('--([a-z][a-z0-9-]+)', parsing_code): + para_name = match.group(1) + if para_name in IGNORE_OPTIONS: + continue + if para_name in DEPRECATED_PARAMETERS: + continue + gen_cmdline_sh_parsing_long_params.add(para_name) - gen_cmdline_sh_variables = set() - for match in re.finditer('^\s*([A-Z_]+)=', parsing_code, re.MULTILINE): - var_name = match.group(1) - if var_name.startswith('CMD_'): - continue - if var_name in NON_CONFIG_VARIABLES: - continue - gen_cmdline_sh_variables.add(var_name) + gen_cmdline_sh_variables = set() + for match in re.finditer('^\s*([A-Z_]+)=', parsing_code, re.MULTILINE): + var_name = match.group(1) + if var_name.startswith('CMD_'): + continue + if var_name in NON_CONFIG_VARIABLES: + continue + gen_cmdline_sh_variables.add(var_name) - del parsing_code + del parsing_code - gen_cmdline_sh_usage_long_params = set() - for match in re.finditer('--([a-z][a-z0-9-]+)', '\n'.join(usage_lines)): - para_name = match.group(1) - if para_name in IGNORE_OPTIONS: - continue - gen_cmdline_sh_usage_long_params.add(para_name) - del usage_lines + gen_cmdline_sh_usage_long_params = set() + for match in re.finditer('--([a-z][a-z0-9-]+)', '\n'.join(usage_lines)): + para_name = match.group(1) + if para_name in IGNORE_OPTIONS: + continue + gen_cmdline_sh_usage_long_params.add(para_name) + del usage_lines - return gen_cmdline_sh_parsing_long_params, gen_cmdline_sh_usage_long_params, gen_cmdline_sh_variables + return gen_cmdline_sh_parsing_long_params, gen_cmdline_sh_usage_long_params, gen_cmdline_sh_variables def extract_genkernel_8_txt(): - f = open(os.path.join('doc', 'genkernel.8.txt'), 'r') - genkernel_8_txt = f.read() - f.close() + f = open(os.path.join('doc', 'genkernel.8.txt'), 'r') + genkernel_8_txt = f.read() + f.close() - # Preprocess - genkernel_8_txt = genkernel_8_txt.replace('*[*no-*]*','[no-]') + # Preprocess + genkernel_8_txt = genkernel_8_txt.replace('*[*no-*]*','[no-]') - yes_no = re.compile('^\\[(no-)\\]([a-z0-9-]+)$') + yes_no = re.compile('^\\[(no-)\\]([a-z0-9-]+)$') - genkernel_8_txt_long_params = set() - for match in re.finditer('--((?:[a-z]|\\[no-\\])[a-z0-9-]+)', genkernel_8_txt): - para_name = match.group(1) + genkernel_8_txt_long_params = set() + for match in re.finditer('--((?:[a-z]|\\[no-\\])[a-z0-9-]+)', genkernel_8_txt): + para_name = match.group(1) - # Black list - if para_name == 'no-': - continue + # Black list + if para_name == 'no-': + continue - if para_name in IGNORE_PARAMETERS: - continue + if para_name in IGNORE_PARAMETERS: + continue - m = yes_no.match(para_name) - if m: - p_yes = m.group(2) - p_no = m.group(1) + m.group(2) - genkernel_8_txt_long_params.add(p_yes) - genkernel_8_txt_long_params.add(p_no) - else: - genkernel_8_txt_long_params.add(para_name) + m = yes_no.match(para_name) + if m: + p_yes = m.group(2) + p_no = m.group(1) + m.group(2) + genkernel_8_txt_long_params.add(p_yes) + genkernel_8_txt_long_params.add(p_no) + else: + genkernel_8_txt_long_params.add(para_name) - del genkernel_8_txt + del genkernel_8_txt - return genkernel_8_txt_long_params + return genkernel_8_txt_long_params def extract_genkernel_xml(genkernel_xml_path, variables_blacklist): - f = open(genkernel_xml_path, 'r') - genkernel_xml = f.read() - f.close() + f = open(genkernel_xml_path, 'r') + genkernel_xml = f.read() + f.close() - # Preprocess - genkernel_xml = genkernel_xml.replace('','').replace('','').replace('','').replace('','') + # Preprocess + genkernel_xml = genkernel_xml.replace('','').replace('','').replace('','').replace('','') - yes_no = re.compile('^(no-)([a-z0-9-]+)$') + yes_no = re.compile('^(no-)([a-z0-9-]+)$') - genkernel_xml_long_params = set() - for match in re.finditer('--([a-z][a-z0-9-]+)', genkernel_xml): - para_name = match.group(1) + genkernel_xml_long_params = set() + for match in re.finditer('--([a-z][a-z0-9-]+)', genkernel_xml): + para_name = match.group(1) - if para_name in IGNORE_OPTIONS: - continue + if para_name in IGNORE_OPTIONS: + continue - # Fix doc error "--no install" - if para_name == 'no': - para_name = 'no-install' + # Fix doc error "--no install" + if para_name == 'no': + para_name = 'no-install' - m = yes_no.match(para_name) - if m and para_name != 'no-ramdisk-modules': - p_yes = m.group(2) - p_no = m.group(1) + m.group(2) - genkernel_xml_long_params.add(p_yes) - genkernel_xml_long_params.add(p_no) - else: - genkernel_xml_long_params.add(para_name) + m = yes_no.match(para_name) + if m and para_name != 'no-ramdisk-modules': + p_yes = m.group(2) + p_no = m.group(1) + m.group(2) + genkernel_xml_long_params.add(p_yes) + genkernel_xml_long_params.add(p_no) + else: + genkernel_xml_long_params.add(para_name) - genkernel_xml_variables = set() - for match in re.finditer('[A-Z_]{3,}', genkernel_xml): - var_name = match.group(0) - if var_name in variables_blacklist: - continue - genkernel_xml_variables.add(var_name) + genkernel_xml_variables = set() + for match in re.finditer('[A-Z_]{3,}', genkernel_xml): + var_name = match.group(0) + if var_name in variables_blacklist: + continue + genkernel_xml_variables.add(var_name) - del genkernel_xml + del genkernel_xml - return genkernel_xml_long_params, genkernel_xml_variables + return genkernel_xml_long_params, genkernel_xml_variables def extract_gen_determineargs_sh(): - f = open('gen_determineargs.sh', 'r') - gen_determineargs_sh = f.read() - f.close() + f = open('gen_determineargs.sh', 'r') + gen_determineargs_sh = f.read() + f.close() - gen_determineargs_sh_variables = set() - for match in re.finditer('set_config_with_override\s+(?:BOOL|STRING)\s+([A-Z_]+)', gen_determineargs_sh): - var_name = match.group(1) - gen_determineargs_sh_variables.add(var_name) + gen_determineargs_sh_variables = set() + for match in re.finditer('set_config_with_override\s+(?:BOOL|STRING)\s+([A-Z_]+)', gen_determineargs_sh): + var_name = match.group(1) + gen_determineargs_sh_variables.add(var_name) - for match in re.finditer('([A-Z_]+)=`(?:arch|cache)_replace "\\$\\{\\1\\}"`', gen_determineargs_sh): - var_name = match.group(1) - gen_determineargs_sh_variables.add(var_name) + for match in re.finditer('([A-Z_]+)=`(?:arch|cache)_replace "\\$\\{\\1\\}"`', gen_determineargs_sh): + var_name = match.group(1) + gen_determineargs_sh_variables.add(var_name) - del gen_determineargs_sh + del gen_determineargs_sh - return gen_determineargs_sh_variables + return gen_determineargs_sh_variables def extract_genkernel_conf(variables_blacklist): - f = open('genkernel.conf', 'r') - genkernel_conf = f.read() - f.close() + f = open('genkernel.conf', 'r') + genkernel_conf = f.read() + f.close() - genkernel_conf_variables = set() - for match in re.finditer('^#*\\s*([A-Z_]{3,})', genkernel_conf, re.MULTILINE): - var_name = match.group(1) - if var_name in variables_blacklist: - continue - genkernel_conf_variables.add(var_name) + genkernel_conf_variables = set() + for match in re.finditer('^#*\\s*([A-Z_]{3,})', genkernel_conf, re.MULTILINE): + var_name = match.group(1) + if var_name in variables_blacklist: + continue + genkernel_conf_variables.add(var_name) - del genkernel_conf + del genkernel_conf - return genkernel_conf_variables + return genkernel_conf_variables def print_set(s): - if s: - print('\n'.join(('- ' + e) for e in sorted(s))) - else: - print(' NONE') - print() + if s: + print('\n'.join(('- ' + e) for e in sorted(s))) + else: + print(' NONE') + print() def usage(): - print('USAGE: %s GENTOO/xml/htdocs/doc/en/genkernel.xml' % os.path.basename(sys.argv[0])) + print('USAGE: %s GENTOO/xml/htdocs/doc/en/genkernel.xml' % os.path.basename(sys.argv[0])) def main(): - if len(sys.argv) != 2: - usage() - sys.exit(1) + if len(sys.argv) != 2: + usage() + sys.exit(1) - gen_cmdline_sh_parsing_long_params, gen_cmdline_sh_usage_long_params, gen_cmdline_sh_variables = exract_gen_cmdline_sh() - genkernel_8_txt_long_params = extract_genkernel_8_txt() - gen_determineargs_sh_variables = extract_gen_determineargs_sh() + gen_cmdline_sh_parsing_long_params, gen_cmdline_sh_usage_long_params, gen_cmdline_sh_variables = exract_gen_cmdline_sh() + genkernel_8_txt_long_params = extract_genkernel_8_txt() + gen_determineargs_sh_variables = extract_gen_determineargs_sh() - variables_blacklist = set(NON_VARIABLES).difference(gen_determineargs_sh_variables) - known_variales = set(EXTRA_VARIABLES).union(gen_determineargs_sh_variables).union(gen_cmdline_sh_variables) + variables_blacklist = set(NON_VARIABLES).difference(gen_determineargs_sh_variables) + known_variales = set(EXTRA_VARIABLES).union(gen_determineargs_sh_variables).union(gen_cmdline_sh_variables) - genkernel_xml_long_params, genkernel_xml_variables = extract_genkernel_xml(sys.argv[1], variables_blacklist) - genkernel_conf_variables = extract_genkernel_conf(variables_blacklist) + genkernel_xml_long_params, genkernel_xml_variables = extract_genkernel_xml(sys.argv[1], variables_blacklist) + genkernel_conf_variables = extract_genkernel_conf(variables_blacklist) - # Status quo - print('Options used by parser in *gen_cmdline.sh*:') - print_set(gen_cmdline_sh_parsing_long_params) + # Status quo + print('Options used by parser in *gen_cmdline.sh*:') + print_set(gen_cmdline_sh_parsing_long_params) - print('Options mentioned in usage of *gen_cmdline.sh*:') - print_set(gen_cmdline_sh_usage_long_params) + print('Options mentioned in usage of *gen_cmdline.sh*:') + print_set(gen_cmdline_sh_usage_long_params) - print('Options mentioned in *man page*:') - print_set(genkernel_8_txt_long_params) + print('Options mentioned in *man page*:') + print_set(genkernel_8_txt_long_params) - print('Options mentioned in *web page*:') - print_set(genkernel_xml_long_params) + print('Options mentioned in *web page*:') + print_set(genkernel_xml_long_params) - print('Variables set by *gen_cmdline.sh*:') - print_set(gen_cmdline_sh_variables) + print('Variables set by *gen_cmdline.sh*:') + print_set(gen_cmdline_sh_variables) - print('Variables read by *gen_determineargs.sh*:') - print_set(gen_determineargs_sh_variables) + print('Variables read by *gen_determineargs.sh*:') + print_set(gen_determineargs_sh_variables) - print('Variables mentioned in *web page*:') - print_set(genkernel_xml_variables) + print('Variables mentioned in *web page*:') + print_set(genkernel_xml_variables) - print('Variables used in *genkernel.conf*:') - print_set(genkernel_conf_variables) + print('Variables used in *genkernel.conf*:') + print_set(genkernel_conf_variables) - # Future work (due extensions) - print('Variables missing from *web page*:') - print_set(known_variales.difference(genkernel_xml_variables)) + # Future work (due extensions) + print('Variables missing from *web page*:') + print_set(known_variales.difference(genkernel_xml_variables)) - print('Options missing from *web page*:') - print_set(gen_cmdline_sh_parsing_long_params.difference(genkernel_xml_long_params)) + print('Options missing from *web page*:') + print_set(gen_cmdline_sh_parsing_long_params.difference(genkernel_xml_long_params)) - print('Variables missing from *genkernel.conf*:') - print_set(known_variales.difference(genkernel_conf_variables)) + print('Variables missing from *genkernel.conf*:') + print_set(known_variales.difference(genkernel_conf_variables)) - print('Options missing from the *man page*:') - print_set(gen_cmdline_sh_parsing_long_params.difference(genkernel_8_txt_long_params)) + print('Options missing from the *man page*:') + print_set(gen_cmdline_sh_parsing_long_params.difference(genkernel_8_txt_long_params)) - print('Options missing from *--help*:') - print_set(gen_cmdline_sh_parsing_long_params.difference(gen_cmdline_sh_usage_long_params)) + print('Options missing from *--help*:') + print_set(gen_cmdline_sh_parsing_long_params.difference(gen_cmdline_sh_usage_long_params)) - # Future work (due removal and updates) - print('Removed options still mentioned in the *man page*:') - print_set(genkernel_8_txt_long_params.difference(gen_cmdline_sh_parsing_long_params)) + # Future work (due removal and updates) + print('Removed options still mentioned in the *man page*:') + print_set(genkernel_8_txt_long_params.difference(gen_cmdline_sh_parsing_long_params)) - print('Removed options still mentioned in *--help*:') - print_set(gen_cmdline_sh_usage_long_params.difference(gen_cmdline_sh_parsing_long_params)) + print('Removed options still mentioned in *--help*:') + print_set(gen_cmdline_sh_usage_long_params.difference(gen_cmdline_sh_parsing_long_params)) - print('Removed options still mentioned in *web page*:') - print_set(genkernel_xml_long_params.difference(gen_cmdline_sh_parsing_long_params)) + print('Removed options still mentioned in *web page*:') + print_set(genkernel_xml_long_params.difference(gen_cmdline_sh_parsing_long_params)) - print('Removed variables still mentioned in *web page*:') - print_set(genkernel_xml_variables.difference(known_variales)) + print('Removed variables still mentioned in *web page*:') + print_set(genkernel_xml_variables.difference(known_variales)) - print('Removed variables still mentioned in *genkernel.conf*:') - print_set(genkernel_conf_variables.difference(known_variales)) + print('Removed variables still mentioned in *genkernel.conf*:') + print_set(genkernel_conf_variables.difference(known_variales)) if __name__ == '__main__': - main() + main()