Merge branch 'stable' into devel
[tails/pzajda.git] / config / binary_local-hooks / 20-syslinux_detect_cpu
blob3e0f703200bc3e5a22777f76cb3fb7d72554fce9
1 #!/bin/bash
3 set -e
5 # Including common functions
6 . "${LB_BASE:-/usr/share/live/build}"/scripts/build.sh
8 # Setting static variables
9 DESCRIPTION="$(Echo 'adding CPU autodetection to the syslinux menu')"
10 HELP=""
11 USAGE="${PROGRAM}"
13 # Reading configuration files
14 Read_conffiles config/all config/bootstrap config/common config/binary
15 Set_defaults
17 # Safeguards
18 if [ "${LB_BOOTLOADER}" != "syslinux" ]
19 then
20 exit 0
22 if [ "${LB_ARCHITECTURE}" != "i386" ]
23 then
24 exit 0
27 # Seems like we'll have work to do
28 Echo_message "adding CPU autodetection to the syslinux menu"
30 # Setting boot method specific variables
31 case "${LB_BINARY_IMAGES}" in
32 iso|iso-hybrid)
33 SYSLINUX_PATH="binary/isolinux"
34 SYSLINUX_CFG="${SYSLINUX_PATH}/isolinux.cfg"
36 usb-hdd)
37 SYSLINUX_PATH="binary/syslinux"
38 SYSLINUX_CFG="${SYSLINUX_PATH}/syslinux.cfg"
40 esac
42 # Setting variables
43 SYSLINUX_LIVE_CFG="${SYSLINUX_PATH}/live.cfg"
44 SYSLINUX_MENU_CFG="${SYSLINUX_PATH}/menu.cfg"
46 # Checking depends
47 Check_package chroot/usr/bin/syslinux syslinux
49 # Restoring cache
50 Restore_cache cache/packages_binary
52 # Installing depends
53 Install_package
55 # Copy necessary syslinux modules
56 for module in ifcpu64.c32
58 cp "chroot/usr/lib/syslinux/${module}" "${SYSLINUX_PATH}/"
59 done
61 # Saving cache
62 Save_cache cache/packages_binary
64 # Removing depends
65 Remove_package
67 # Replace syslinux.cfg with autodetection "code"
68 cat > "${SYSLINUX_CFG}" <<EOF
69 label select_menu
70 com32 ifcpu64.c32
71 append menu_amd64 -- menu_486 -- menu_486
72 label menu_amd64
73 kernel vesamenu.c32
74 append liveamd64.cfg
75 label menu_486
76 kernel vesamenu.c32
77 append live486.cfg
78 default select_menu
79 prompt 0
80 EOF
82 # Set a few variables in menu.cfg as loading vesamenu.c32 resets its
83 # state to the defaults
84 sed -i -e "1i prompt 0\ntimeout 40\n" "${SYSLINUX_MENU_CFG}"
86 # Copy and adapt live.cfg for each kernel
87 for arch in 486 amd64
90 echo "include menu.cfg"
92 if [ $arch = 486 ]; then
93 append=""
94 else
95 append=2
97 sed -e "s,/vmlinuz$,/vmlinuz${append}, ; s,initrd\.img,initrd${append}.img," "${SYSLINUX_LIVE_CFG}"
98 ) | sed -n -e '/^label live-amd64.*/ { q } ; p' \
99 > "${SYSLINUX_PATH}/live${arch}.cfg"
100 done
102 # Don't load live.cfg from menu.cfg:
103 # syslinux_cfg automatically loads arch-specific menus
104 sed -i -e '/^include live\.cfg/d' "${SYSLINUX_MENU_CFG}"