20-syslinux_detect_cpu 2.1 KB
Newer Older
1 2
#!/bin/bash

3 4
set -e

5 6 7 8 9 10 11 12 13 14 15 16 17
# Including common functions
. "${LB_BASE:-/usr/share/live/build}"/scripts/build.sh

# Setting static variables
DESCRIPTION="$(Echo 'adding CPU autodetection to the syslinux menu')"
HELP=""
USAGE="${PROGRAM}"

# Reading configuration files
Read_conffiles config/all config/bootstrap config/common config/binary
Set_defaults

# Safeguards
18 19
[ "${LB_BOOTLOADER}"   = "syslinux" ] || exit 0
[ "${LB_ARCHITECTURE}" = "amd64"    ] || exit 0
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

# Seems like we'll have work to do
Echo_message "adding CPU autodetection to the syslinux menu"

# Setting boot method specific variables
case "${LB_BINARY_IMAGES}" in
	iso|iso-hybrid)
		SYSLINUX_PATH="binary/isolinux"
		SYSLINUX_CFG="${SYSLINUX_PATH}/isolinux.cfg"
		;;
	usb-hdd)
		SYSLINUX_PATH="binary/syslinux"
		SYSLINUX_CFG="${SYSLINUX_PATH}/syslinux.cfg"
		;;
esac

# Setting variables
SYSLINUX_LIVE_CFG="${SYSLINUX_PATH}/live.cfg"
SYSLINUX_MENU_CFG="${SYSLINUX_PATH}/menu.cfg"

40 41 42 43 44 45 46 47 48
# Checking depends
Check_package chroot/usr/bin/syslinux syslinux

# Restoring cache
Restore_cache cache/packages_binary

# Installing depends
Install_package

49
# Copy necessary syslinux modules
50
for module in cat.c32 ifcpu64.c32
51
do
52
	cp "chroot/usr/lib/syslinux/modules/bios/${module}" "${SYSLINUX_PATH}/"
53 54
done

55 56 57 58 59 60
# Saving cache
Save_cache cache/packages_binary

# Removing depends
Remove_package

61 62 63 64
# Replace syslinux.cfg with autodetection "code"
cat > "${SYSLINUX_CFG}" <<EOF
label select_menu
       com32 ifcpu64.c32
65 66
       append menu_64 -- menu_32 -- menu_32
label menu_64
67
       kernel vesamenu.c32
68 69
       append live64.cfg
label menu_32
70 71
       com32 cat.c32
       append sorry32.txt
72 73 74 75 76 77 78 79
default select_menu
prompt 0
EOF

# Set a few variables in menu.cfg as loading vesamenu.c32 resets its
# state to the defaults
sed -i -e "1i prompt 0\ntimeout 40\n" "${SYSLINUX_MENU_CFG}"

80
# Generate a live$arch.cfg for each architecture
intrigeri's avatar
intrigeri committed
81 82 83
(
	echo "include menu.cfg"
	sed -n -e '/^label live-amd64.*/ { q } ; p' "${SYSLINUX_LIVE_CFG}"
84
) > "${SYSLINUX_PATH}/live64.cfg"
intrigeri's avatar
intrigeri committed
85

86 87 88
# Don't load live.cfg from menu.cfg:
# syslinux_cfg automatically loads arch-specific menus
sed -i -e '/^include live\.cfg/d' "${SYSLINUX_MENU_CFG}"