summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorLyndon Brown <jnqnfe@gmail.com>2020-03-26 04:59:15 +0000
committerRaphaƫl Hertzog <hertzog@debian.org>2020-05-01 09:40:40 +0000
commitfd18d46e0eb6abfe757f8764c65ac4c472fcdeef (patch)
treebc1806728fdce98c0f7d7198c781ed6b95aec342 /scripts
parent2c1af527fdd4e97d79267f8afb7696fe96331982 (diff)
downloadvyos-live-build-fd18d46e0eb6abfe757f8764c65ac4c472fcdeef.tar.gz
vyos-live-build-fd18d46e0eb6abfe757f8764c65ac4c472fcdeef.zip
grub2|loopback: avoid perl for live entry creation, use temp file
instead of cramming the live entries into a string via a layer of functions for terminating entries with newlines, which we then have to run through perl to tweak the newlines for correct use with sed... let's write the entries to a temp file, then use that file in the sed replacement. the helper functions injecting newlines to the end of entries as they were built into a long string have obviously become unnecessary and so were removed. one function was renamed for reasons of consistency and clarity. the file is initially deleted before use for reasons of wanting to bullet proof the codebase to work properly under conditions of recovering from failure/cancellation, `--force` re-running and such. this removes the last use of perl. Gbp-Dch: Short
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build/binary_loopback_cfg50
1 files changed, 20 insertions, 30 deletions
diff --git a/scripts/build/binary_loopback_cfg b/scripts/build/binary_loopback_cfg
index 58fa854e3..09f94aca5 100755
--- a/scripts/build/binary_loopback_cfg
+++ b/scripts/build/binary_loopback_cfg
@@ -42,19 +42,15 @@ Check_crossarchitectures
_TARGET="binary/boot/grub"
-# Variable used to embed newlines
-NL="
-"
-
# Local functions
-Grub_menu_entry() {
+Grub_live_menu_entry() {
local LABEL="$1"
local KERNEL="$2"
local INITRD="$3"
local APPEND="$4"
local HOTKEY="${5:+ --hotkey=$5}"
- cat <<END
+ cat >> "${LIVE_ENTRIES_TMP}" <<END
menuentry "${LABEL}"${HOTKEY} {
linux $KERNEL $APPEND
initrd $INITRD
@@ -62,11 +58,6 @@ menuentry "${LABEL}"${HOTKEY} {
END
}
-Grub_live_entry ()
-{
- LINUX_LIVE="${LINUX_LIVE}$(Grub_menu_entry "$@")$NL"
-}
-
Grub_live_autodetect_menu_entry ()
{
local LABEL="${1}"
@@ -75,7 +66,8 @@ Grub_live_autodetect_menu_entry ()
local _686_KERNEL="${4}"
local _686_INITRD="${5}"
local APPEND="${6}"
- cat <<END
+
+ cat >> "${LIVE_ENTRIES_TMP}" <<END
# Autodetect if amd64 is supported
menuentry "$LABEL" {
if cpuid -l; then
@@ -89,11 +81,6 @@ menuentry "$LABEL" {
END
}
-Grub_live_autodetect_entry ()
-{
- LINUX_LIVE="${LINUX_LIVE}$(Grub_live_autodetect_menu_entry "$@")$NL"
-}
-
# User config replacement/additional files
_SOURCE_USER="config/bootloaders/grub-pc"
@@ -132,7 +119,11 @@ KERNEL_LIVE="/${INITFS}/${DEFAULT_KERNEL}"
INITRD_LIVE="/${INITFS}/${DEFAULT_INITRD}"
APPEND_LIVE="${LB_BOOTAPPEND_LIVE} findiso=\${iso_path}"
-# Assembling kernel configuration
+# Ensure fresh live entries
+LIVE_ENTRIES_TMP="${_TARGET}/live.cfg.tmp"
+rm -f "${LIVE_ENTRIES_TMP}"
+
+# Assemble live menu entries
_AMD64_686_NUMBER="0"
for _FLAVOUR in ${LB_LINUX_FLAVOURS}; do
@@ -148,7 +139,7 @@ if [ "${_AMD64_686_NUMBER}" -ge 2 ] ; then
_686_KERNEL="$(basename chroot/boot/vmlinuz-*686)"
_686_INITRD="initrd.img-$(echo ${_686_KERNEL} | sed -e 's|vmlinuz-||')"
- Grub_live_autodetect_entry "Live system (autodetect)" \
+ Grub_live_autodetect_menu_entry "Live system (autodetect)" \
"/${INITFS}/${AMD64_KERNEL}" \
"/${INITFS}/${AMD64_INITRD}" \
"/${INITFS}/${_686_KERNEL}" \
@@ -156,7 +147,7 @@ if [ "${_AMD64_686_NUMBER}" -ge 2 ] ; then
"${APPEND_LIVE}"
if [ "${LB_BOOTAPPEND_LIVE_FAILSAFE}" != "none" ]; then
- Grub_live_autodetect_entry "Live system (autodetect) (fail-safe mode)" \
+ Grub_live_autodetect_menu_entry "Live system (autodetect) (fail-safe mode)" \
"/${INITFS}/${AMD64_KERNEL}" \
"/${INITFS}/${AMD64_INITRD}" \
"/${INITFS}/${_686_KERNEL}" \
@@ -164,13 +155,13 @@ if [ "${_AMD64_686_NUMBER}" -ge 2 ] ; then
"${LB_BOOTAPPEND_LIVE_FAILSAFE}"
fi
else
- Grub_live_entry "Live system" \
+ Grub_live_menu_entry "Live system" \
"/${INITFS}/${DEFAULT_KERNEL}" \
"/${INITFS}/${DEFAULT_INITRD}" \
"${APPEND_LIVE}" \
"l"
if [ "${LB_BOOTAPPEND_LIVE_FAILSAFE}" != "none" ]; then
- Grub_live_entry "Live system (fail-safe mode)" \
+ Grub_live_menu_entry "Live system (fail-safe mode)" \
"/${INITFS}/${DEFAULT_KERNEL}" \
"/${INITFS}/${DEFAULT_INITRD}" \
"${LB_BOOTAPPEND_LIVE_FAILSAFE}"
@@ -186,13 +177,13 @@ if [ $_COUNT -gt 1 ]; then
for KERNEL in chroot/boot/vmlinuz-*; do
VERSION="$(basename ${KERNEL} | sed -e 's|vmlinuz-||')"
- Grub_live_entry "Live system, kernel ${VERSION}" \
+ Grub_live_menu_entry "Live system, kernel ${VERSION}" \
"/${INITFS}/$(basename ${KERNEL})" \
"/${INITFS}/initrd.img-${VERSION}" \
"${APPEND_LIVE}"
if [ "${LB_BOOTAPPEND_LIVE_FAILSAFE}" != "none" ]; then
- Grub_live_entry "Live system, kernel ${VERSION} (fail-safe mode)" \
+ Grub_live_menu_entry "Live system, kernel ${VERSION} (fail-safe mode)" \
"/${INITFS}/$(basename ${KERNEL})" \
"/${INITFS}/initrd.img-${VERSION}" \
"${LB_BOOTAPPEND_LIVE_FAILSAFE}"
@@ -200,6 +191,11 @@ if [ $_COUNT -gt 1 ]; then
done
fi
+# Replace placeholder with compiled live entries temporarily held in live.cfg.tmp
+sed -i -e "/@LINUX_LIVE@/ r ${LIVE_ENTRIES_TMP}" "${_TARGET}"/*.cfg
+sed -i -e "/LINUX_LIVE/ r ${LIVE_ENTRIES_TMP}" "${_TARGET}"/*.cfg #backwards compatibility
+rm -f "${LIVE_ENTRIES_TMP}"
+
# Assembling debian-installer configuration
if [ "${LB_DEBIAN_INSTALLER}" != "none" ]; then
ENABLE_INSTALL_MENU="true"
@@ -241,17 +237,12 @@ else
rm -f "${_TARGET}"/memtest.cfg
fi
-escape_for_sed() {
- echo -n "$1" | perl -npe 's/\n/\\n/gm'
-}
-
# These must be held in variables to avoid mistake by checkbashisms
LINUX_INSTALL="source /boot/grub/install_start.cfg"
LINUX_ADVANCED_INSTALL="source /boot/grub/install.cfg"
# Those without '@' markers are for backwards compatibility
sed -i \
- -e "s|@LINUX_LIVE@|$(escape_for_sed "${LINUX_LIVE}")|" \
-e "s|@KERNEL_GI@|${KERNEL_GI}|" \
-e "s|@INITRD_GI@|${INITRD_GI}|" \
-e "s|@APPEND_GI@|${APPEND_GI}|" \
@@ -269,7 +260,6 @@ sed -i \
-e "s|@ENABLE_MEMTEST@|${ENABLE_MEMTEST}|" \
-e "s|@MEMTEST_BIN@|${MEMTEST_BIN}|" \
-e "s|@MEMTEST_VERSION@|${LB_MEMTEST}|" \
- -e "s|LINUX_LIVE|$(escape_for_sed "${LINUX_LIVE}")|" \
-e "s|LINUX_INSTALL|${LINUX_INSTALL}|" \
-e "s|LINUX_ADVANCED_INSTALL|${LINUX_ADVANCED_INSTALL}|" \
-e "s|MEMTEST|${MEMTEST}|" \