Create debian version of update-iso.sh and common funcs

The current update-iso.sh tool and its common functions
file stx-iso-utils.sh does not support updating the debian ISO.

This update moves the existing centOS version of these files
to centos specific names and replacesm those original files
with content that support updating a Debian ISO with the same
update features.

Test Plan:

PASS: Verify adding addon file to iso
PASS: Verify handling single parameter value change
PASS: Verify handling multiple parameter value change
PASS: Verify handling instdev change as parameter value
PASS: Verify handling adding new parameter value
PASS: Verify grub menu timeout change for BIOS
PASS: Verify grub menu select change for BIOS
PASS: Verify grub menu timeout change for UEFI
PASS: Verify grub menu select change for UEFI
PASS: Verify clear default menu selection
      - for BIOS and UEFI
      - confirm no timeout
      - confirm default to Controller Install

Error Handling:

PASS: Verify bad input file error handling
PASS: Verify bad output file error handling
PASS: Verify bad or missing addon file
PASS: Verify bad command line format displays error/help
PASS: Verify handling of failure to write output file

General:

PASS: Verify tool run output
PASS: verify tmp files/dirs cleanup
PASS: Verify bash static analysis of bot scripts (shellcheck)
PASS: Verify handling all short and long command line options
PEND: Verify no sudo method with guestmount

Regression:

PEND: Verify CentOS build and install
PEND: Verify renamed files in CentOS filesystem
PEND: Verify Debian build and install
PEND: Verify updated files in Debian filesystem
PEND: Verify other utilities that use common func (debian only)
PEND: - gen-bootloader-iso.sh
PEND: - gen-prestaged-iso.sh
PEND: - prepare-prestage-packages.sh

Story: 2009968
Task: 46977
Signed-off-by: Eric MacDonald <eric.macdonald@windriver.com>
Change-Id: I369ba85306950a511a605a82cd365824ed103c43
This commit is contained in:
Eric MacDonald 2022-12-01 20:46:40 +00:00
parent 5a653a9e4b
commit 37f8fb1924
5 changed files with 887 additions and 200 deletions

View File

@ -61,10 +61,10 @@ install %{_buildsubdir}/scripts/tc_setup.sh %{buildroot}%{local_bindir}
install %{_buildsubdir}/scripts/remotelogging_tc_setup.sh %{buildroot}%{local_bindir} install %{_buildsubdir}/scripts/remotelogging_tc_setup.sh %{buildroot}%{local_bindir}
install %{_buildsubdir}/scripts/connectivity_test %{buildroot}%{local_bindir} install %{_buildsubdir}/scripts/connectivity_test %{buildroot}%{local_bindir}
install -m 555 %{_buildsubdir}/scripts/is-rootdisk-device.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/is-rootdisk-device.sh %{buildroot}%{local_bindir}
install -m 555 %{_buildsubdir}/scripts/update-iso.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/update-iso-centos.sh %{buildroot}%{local_bindir}/update-iso.sh
install -m 555 %{_buildsubdir}/scripts/gen-bootloader-iso-centos.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/gen-bootloader-iso-centos.sh %{buildroot}%{local_bindir}
install -m 555 %{_buildsubdir}/scripts/prepare-prestage-packages.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/prepare-prestage-packages.sh %{buildroot}%{local_bindir}
install -m 555 %{_buildsubdir}/scripts/stx-iso-utils.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/stx-iso-utils-centos.sh %{buildroot}%{local_bindir}/stx-iso-utils.sh
install -m 555 %{_buildsubdir}/scripts/show-certs.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/show-certs.sh %{buildroot}%{local_bindir}
install -m 555 %{_buildsubdir}/scripts/update_docker_registry_auth.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/update_docker_registry_auth.sh %{buildroot}%{local_bindir}
install -m 555 %{_buildsubdir}/scripts/change_system_private_registry.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/change_system_private_registry.sh %{buildroot}%{local_bindir}

View File

@ -0,0 +1,290 @@
#!/bin/bash
#
# Copyright (c) 2020 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Common bash utility functions for StarlingX ISO tools
#
declare BUILDDIR=
declare EFIBOOT_IMG_LOOP=
declare EFI_MOUNT=
declare MNTDIR=
declare WORKDIR=
function common_cleanup {
unmount_efiboot_img
if [ -n "$MNTDIR" -a -d "$MNTDIR" ]; then
unmount_iso
fi
if [ -n "$BUILDDIR" -a -d "$BUILDDIR" ]; then
\rm -rf $BUILDDIR
fi
if [ -n "$WORKDIR" -a -d "$WORKDIR" ]; then
\rm -rf $WORKDIR
fi
}
function common_check_requirements {
local -a required_utils=(
awk
grep
implantisomd5
isohybrid
mkisofs
mktemp
rm
rmdir
rsync
sed
)
if [ $UID -eq 0 ]; then
required_utils+=(
losetup
mount
mountpoint
umount
)
else
# If running as non-root user, additional utils are required
required_utils+=(
guestmount
guestunmount
udisksctl
)
fi
required_utils+=( $@ )
local -i missing=0
which which >&/dev/null
if [ $? -ne 0 ]; then
log_error "Unable to find 'which' utility. Aborting..."
exit 1
fi
for req in ${required_utils[@]}; do
which ${req} >&/dev/null
if [ $? -ne 0 ]; then
log_error "Unable to find required utility: ${req}"
let -i missing++
fi
done
if [ ${missing} -gt 0 ]; then
log_error "One or more required utilities are missing. Aborting..."
exit 1
fi
}
function check_required_param {
local param="${1}"
local value="${2}"
if [ -z "${value}" ]; then
log_error "Required parameter ${param} is not set"
exit 1
fi
}
function check_files_exist {
for value in "$@"; do
if [ ! -f "${value}" ]; then
log_error "file path '${value}' is invalid"
exit 1
fi
done
}
function check_files_size {
local file_size
# Aprox 4 GB file size limit for iso file systems.
local file_size_limit=4000000000
for value in "$@"; do
file_size=$(stat --printf="%s" ${value})
if [ ${file_size} -gt ${file_size_limit} ]; then
log_error "file size of '${value}' exceeds 4 GB limit"
exit 1
fi
done
}
function mount_iso {
local input_iso=$1
local basedir=${2:-$PWD}
MNTDIR=$(mktemp -d -p "$basedir" stx-iso-utils_mnt_XXXXXX)
if [ -z "${MNTDIR}" -o ! -d ${MNTDIR} ]; then
log_error "Failed to create mntdir $MNTDIR. Aborting..."
exit 1
fi
if [ $UID -eq 0 ]; then
# Mount the ISO
mount -o loop ${input_iso} ${MNTDIR}
if [ $? -ne 0 ]; then
echo "Failed to mount ${input_iso}" >&2
exit 1
fi
else
# As non-root user, mount the ISO using guestmount
guestmount -a ${input_iso} -m /dev/sda1 --ro ${MNTDIR}
rc=$?
if [ $rc -ne 0 ]; then
# Add a retry
echo "Call to guestmount failed with rc=$rc. Retrying once..."
guestmount -a ${input_iso} -m /dev/sda1 --ro ${MNTDIR}
rc=$?
if [ $rc -ne 0 ]; then
echo "Call to guestmount failed with rc=$rc. Aborting..."
exit $rc
fi
fi
fi
}
function unmount_iso {
if [ $UID -eq 0 ]; then
umount ${MNTDIR}
else
guestunmount ${MNTDIR}
fi
rmdir ${MNTDIR}
}
function mount_efiboot_img {
local isodir=$1
if [ -e ${isodir}/images/efiboot.img ]; then
local efiboot_img=${isodir}/images/efiboot.img
else
local efiboot_img=${isodir}/efi.img
fi
local loop_setup_output=
if [ $UID -eq 0 ]; then
# As root, setup a writeable loop device for the
# efiboot.img file and mount it
loop_setup_output=$(losetup --show -f ${efiboot_img})
if [ $? -ne 0 ]; then
echo "Failed losetup" >&2
exit 1
fi
EFIBOOT_IMG_LOOP=${loop_setup_output}
EFI_MOUNT=$(mktemp -d -p /mnt -t EFI-noudev.XXXXXX)
mount ${EFIBOOT_IMG_LOOP} ${EFI_MOUNT}
if [ $? -ne 0 ]; then
echo "Failed to mount loop device ${EFIBOOT_IMG_LOOP}" >&2
exit 1
fi
else
# As non-root user, we can use the udisksctl to setup a loop device
# and mount the efiboot.img, with read/write access.
loop_setup_output=$(udisksctl loop-setup -f ${efiboot_img} --no-user-interaction)
if [ $? -ne 0 ]; then
echo "Failed udisksctl loop-setup" >&2
exit 1
fi
EFIBOOT_IMG_LOOP=$(echo ${loop_setup_output} | awk '{print $5;}' | sed -e 's/\.$//g')
if [ -z "${EFIBOOT_IMG_LOOP}" ]; then
echo "Failed to determine loop device from command output:" >&2
echo "${loop_setup_output}" >&2
exit 1
fi
udisksctl mount -b ${EFIBOOT_IMG_LOOP}
if [ $? -ne 0 ]; then
echo "Failed udisksctl mount" >&2
exit 1
fi
EFI_MOUNT=$(udisksctl info -b ${EFIBOOT_IMG_LOOP} | grep MountPoints | awk '{print $2;}')
if [ -z "${EFI_MOUNT}" ]; then
echo "Failed to determine mount point from udisksctl info command" >&2
exit 1
fi
fi
}
function unmount_efiboot_img {
if [ $UID -eq 0 ]; then
if [ -n "${EFI_MOUNT}" ]; then
mountpoint -q ${EFI_MOUNT} && umount ${EFI_MOUNT}
rmdir ${EFI_MOUNT}
EFI_MOUNT=
fi
if [ -n "${EFIBOOT_IMG_LOOP}" ]; then
losetup -d ${EFIBOOT_IMG_LOOP}
EFIBOOT_IMG_LOOP=
fi
else
if [ -n "${EFIBOOT_IMG_LOOP}" ]; then
udisksctl unmount -b ${EFIBOOT_IMG_LOOP}
udisksctl loop-delete -b ${EFIBOOT_IMG_LOOP}
EFI_MOUNT=
EFIBOOT_IMG_LOOP=
fi
fi
}
function update_parameter {
local isodir=$1
local param=$2
local value=$3
if [ -z "${EFI_MOUNT}" ]; then
mount_efiboot_img ${isodir}
fi
for f in ${isodir}/isolinux.cfg ${isodir}/syslinux.cfg; do
grep -q "^[[:space:]]*append\>.*[[:space:]]${param}=" ${f}
if [ $? -eq 0 ]; then
# Parameter already exists. Update the value
sed -i -e "s#^\([[:space:]]*append\>.*${param}\)=[^[:space:]]*#\1=${value}#" ${f}
if [ $? -ne 0 ]; then
log_error "Failed to update parameter ($param)"
exit 1
fi
else
# Parameter doesn't exist. Add it to the cmdline
sed -i -e "s|^\([[:space:]]*append\>.*\)|\1 ${param}=${value}|" ${f}
if [ $? -ne 0 ]; then
log_error "Failed to add parameter ($param)"
exit 1
fi
fi
done
for f in ${isodir}/EFI/BOOT/grub.cfg ${EFI_MOUNT}/EFI/BOOT/grub.cfg; do
grep -q "^[[:space:]]*linuxefi\>.*[[:space:]]${param}=" ${f}
if [ $? -eq 0 ]; then
# Parameter already exists. Update the value
sed -i -e "s#^\([[:space:]]*linuxefi\>.*${param}\)=[^[:space:]]*#\1=${value}#" ${f}
if [ $? -ne 0 ]; then
log_error "Failed to update parameter ($param)"
exit 1
fi
else
# Parameter doesn't exist. Add it to the cmdline
sed -i -e "s|^\([[:space:]]*linuxefi\>.*\)|\1 ${param}=${value}|" ${f}
if [ $? -ne 0 ]; then
log_error "Failed to add parameter ($param)"
exit 1
fi
fi
done
}

View File

@ -13,19 +13,28 @@ declare EFI_MOUNT=
declare MNTDIR= declare MNTDIR=
declare WORKDIR= declare WORKDIR=
function ilog {
echo "$(date "+%F %H-%M-%S"): $*" >&2
}
function elog {
echo "$(date "+%F %H-%M-%S") Error: $*" >&2
exit 1
}
function common_cleanup { function common_cleanup {
unmount_efiboot_img unmount_efiboot_img
if [ -n "$MNTDIR" -a -d "$MNTDIR" ]; then if [ -n "${MNTDIR}" ] && [ -d "${MNTDIR}" ]; then
unmount_iso unmount_iso
fi fi
if [ -n "$BUILDDIR" -a -d "$BUILDDIR" ]; then if [ -n "${BUILDDIR}" ] && [ -d "${BUILDDIR}" ]; then
\rm -rf $BUILDDIR \rm -rf "${BUILDDIR}"
fi fi
if [ -n "$WORKDIR" -a -d "$WORKDIR" ]; then if [ -n "${WORKDIR}" ] && [ -d "${WORKDIR}" ]; then
\rm -rf $WORKDIR \rm -rf "${WORKDIR}"
fi fi
} }
@ -58,27 +67,26 @@ function common_check_requirements {
) )
fi fi
required_utils+=( $@ ) required_utils+=( "$@" )
local -i missing=0 local -i missing=0
which which >&/dev/null if which which >&/dev/null -ne 0 ; then
if [ $? -ne 0 ]; then elog "Unable to find 'which' utility. Aborting..."
log_error "Unable to find 'which' utility. Aborting..."
exit 1
fi fi
for req in ${required_utils[@]}; do for req in "${required_utils[@]}"; do
which ${req} >&/dev/null which "${req}" >&/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ] ; then
log_error "Unable to find required utility: ${req}" ilog "Unable to find required utility: ${req}"
let -i missing++ (( missing++ ))
fi fi
done done
if [ ${missing} -gt 0 ]; then if [ "${missing}" -gt 0 ]; then
log_error "One or more required utilities are missing. Aborting..." elog "One or more required utilities are missing. Aborting..."
exit 1 else
ilog "all required iso utilities present"
fi fi
} }
@ -87,16 +95,14 @@ function check_required_param {
local value="${2}" local value="${2}"
if [ -z "${value}" ]; then if [ -z "${value}" ]; then
log_error "Required parameter ${param} is not set" elog "Required parameter ${param} is not set"
exit 1
fi fi
} }
function check_files_exist { function check_files_exist {
for value in "$@"; do for value in "$@"; do
if [ ! -f "${value}" ]; then if [ ! -f "${value}" ]; then
log_error "file path '${value}' is invalid" elog "file path '${value}' is invalid"
exit 1
fi fi
done done
} }
@ -108,10 +114,9 @@ function check_files_size {
local file_size_limit=4000000000 local file_size_limit=4000000000
for value in "$@"; do for value in "$@"; do
file_size=$(stat --printf="%s" ${value}) file_size=$(stat --printf="%s" "${value}")
if [ ${file_size} -gt ${file_size_limit} ]; then if [ "${file_size}" -gt "${file_size_limit}" ]; then
log_error "file size of '${value}' exceeds 4 GB limit" elog "file size of '${value}' exceeds 4 GB limit"
exit 1
fi fi
done done
} }
@ -121,52 +126,51 @@ function mount_iso {
local basedir=${2:-$PWD} local basedir=${2:-$PWD}
MNTDIR=$(mktemp -d -p "$basedir" stx-iso-utils_mnt_XXXXXX) MNTDIR=$(mktemp -d -p "$basedir" stx-iso-utils_mnt_XXXXXX)
if [ -z "${MNTDIR}" -o ! -d ${MNTDIR} ]; then if [ -z "${MNTDIR}" ] || [ ! -d "${MNTDIR}" ]; then
log_error "Failed to create mntdir $MNTDIR. Aborting..." elog "Failed to create mntdir $MNTDIR. Aborting..."
exit 1
fi fi
if [ $UID -eq 0 ]; then if [ $UID -eq 0 ]; then
# Mount the ISO # Mount the ISO
mount -o loop ${input_iso} ${MNTDIR} ilog "mounting ${input_iso} to ${MNTDIR}"
mount -o loop "${input_iso}" "${MNTDIR}" >&/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to mount ${input_iso}" >&2 elog "Failed to mount ${input_iso}" >&2
exit 1
fi fi
else else
# As non-root user, mount the ISO using guestmount # As non-root user, mount the ISO using guestmount
guestmount -a ${input_iso} -m /dev/sda1 --ro ${MNTDIR} guestmount -a "${input_iso}" -m /dev/sda1 --ro "${MNTDIR}"
rc=$? rc=$?
if [ $rc -ne 0 ]; then if [ "${rc}" -ne 0 ]; then
# Add a retry # Add a retry
echo "Call to guestmount failed with rc=$rc. Retrying once..." ilog "Call to guestmount failed with rc=$rc. Retrying once..."
guestmount -a ${input_iso} -m /dev/sda1 --ro ${MNTDIR} guestmount -a "${input_iso}" -m /dev/sda1 --ro "${MNTDIR}" >&/dev/null
rc=$? rc=$?
if [ $rc -ne 0 ]; then if [ ${rc} -ne 0 ]; then
echo "Call to guestmount failed with rc=$rc. Aborting..." elog "Call to guestmount failed with rc=$rc. Aborting..."
exit $rc
fi fi
fi fi
fi fi
} }
function unmount_iso { function unmount_iso {
if [ $UID -eq 0 ]; then if [ "${UID}" -eq 0 ]; then
umount ${MNTDIR} ilog "unmounting ${MNTDIR}"
umount "${MNTDIR}" >&/dev/null
else else
guestunmount ${MNTDIR} guestunmount "${MNTDIR}" >&/dev/null
fi fi
rmdir ${MNTDIR} rmdir "${MNTDIR}"
} }
function mount_efiboot_img { function mount_efiboot_img {
local isodir=$1 local isodir=$1
if [ -e ${isodir}/images/efiboot.img ]; then if [ -e "${isodir}/images/efiboot.img" ]; then
local efiboot_img=${isodir}/images/efiboot.img local efiboot_img="${isodir}/images/efiboot.img"
else else
local efiboot_img=${isodir}/efi.img local efiboot_img="${isodir}/efi.img"
fi fi
local loop_setup_output= local loop_setup_output=
@ -174,45 +178,42 @@ function mount_efiboot_img {
if [ $UID -eq 0 ]; then if [ $UID -eq 0 ]; then
# As root, setup a writeable loop device for the # As root, setup a writeable loop device for the
# efiboot.img file and mount it # efiboot.img file and mount it
loop_setup_output=$(losetup --show -f ${efiboot_img}) loop_setup_output=$(losetup --show -f "${efiboot_img}")
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed losetup" >&2 elog "Failed losetup" >&2
exit 1
fi fi
EFIBOOT_IMG_LOOP=${loop_setup_output} EFIBOOT_IMG_LOOP=${loop_setup_output}
EFI_MOUNT=$(mktemp -d -p /mnt -t EFI-noudev.XXXXXX) EFI_MOUNT=$(mktemp -d -p /mnt -t EFI-noudev.XXXXXX)
mount ${EFIBOOT_IMG_LOOP} ${EFI_MOUNT} mount "${EFIBOOT_IMG_LOOP}" "${EFI_MOUNT}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to mount loop device ${EFIBOOT_IMG_LOOP}" >&2 elog "Failed to mount loop device ${EFIBOOT_IMG_LOOP}" >&2
exit 1
fi fi
else else
# As non-root user, we can use the udisksctl to setup a loop device # As non-root user, we can use the udisksctl to setup a loop device
# and mount the efiboot.img, with read/write access. # and mount the efiboot.img, with read/write access.
loop_setup_output=$(udisksctl loop-setup -f ${efiboot_img} --no-user-interaction) loop_setup_output=$(udisksctl loop-setup -f "${efiboot_img}" --no-user-interaction)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed udisksctl loop-setup" >&2 elog "Failed udisksctl loop-setup" >&2
exit 1
fi fi
EFIBOOT_IMG_LOOP=$(echo ${loop_setup_output} | awk '{print $5;}' | sed -e 's/\.$//g') EFIBOOT_IMG_LOOP=$(echo "${loop_setup_output}" | awk '{print $5;}' | sed -e 's/\.$//g')
if [ -z "${EFIBOOT_IMG_LOOP}" ]; then if [ -z "${EFIBOOT_IMG_LOOP}" ]; then
echo "Failed to determine loop device from command output:" >&2 echo "Error: Failed to determine loop device from command output:" >&2
echo "${loop_setup_output}" >&2 echo "${loop_setup_output}" >&2
exit 1 exit 1
fi fi
udisksctl mount -b ${EFIBOOT_IMG_LOOP} udisksctl mount -b "${EFIBOOT_IMG_LOOP}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed udisksctl mount" >&2 echo "Error: Failed udisksctl mount" >&2
exit 1 exit 1
fi fi
EFI_MOUNT=$(udisksctl info -b ${EFIBOOT_IMG_LOOP} | grep MountPoints | awk '{print $2;}') EFI_MOUNT=$(udisksctl info -b "${EFIBOOT_IMG_LOOP}" | grep MountPoints | awk '{print $2;}')
if [ -z "${EFI_MOUNT}" ]; then if [ -z "${EFI_MOUNT}" ]; then
echo "Failed to determine mount point from udisksctl info command" >&2 echo "Error: Failed to determine mount point from udisksctl info command" >&2
exit 1 exit 1
fi fi
fi fi
@ -221,19 +222,19 @@ function mount_efiboot_img {
function unmount_efiboot_img { function unmount_efiboot_img {
if [ $UID -eq 0 ]; then if [ $UID -eq 0 ]; then
if [ -n "${EFI_MOUNT}" ]; then if [ -n "${EFI_MOUNT}" ]; then
mountpoint -q ${EFI_MOUNT} && umount ${EFI_MOUNT} mountpoint -q "${EFI_MOUNT}" && umount "${EFI_MOUNT}"
rmdir ${EFI_MOUNT} rmdir "${EFI_MOUNT}"
EFI_MOUNT= EFI_MOUNT=
fi fi
if [ -n "${EFIBOOT_IMG_LOOP}" ]; then if [ -n "${EFIBOOT_IMG_LOOP}" ]; then
losetup -d ${EFIBOOT_IMG_LOOP} losetup -d "${EFIBOOT_IMG_LOOP}"
EFIBOOT_IMG_LOOP= EFIBOOT_IMG_LOOP=
fi fi
else else
if [ -n "${EFIBOOT_IMG_LOOP}" ]; then if [ -n "${EFIBOOT_IMG_LOOP}" ]; then
udisksctl unmount -b ${EFIBOOT_IMG_LOOP} udisksctl unmount -b "${EFIBOOT_IMG_LOOP}"
udisksctl loop-delete -b ${EFIBOOT_IMG_LOOP} udisksctl loop-delete -b "${EFIBOOT_IMG_LOOP}"
EFI_MOUNT= EFI_MOUNT=
EFIBOOT_IMG_LOOP= EFIBOOT_IMG_LOOP=
fi fi
@ -245,44 +246,41 @@ function update_parameter {
local param=$2 local param=$2
local value=$3 local value=$3
ilog "updating parameter ${param} to ${param}=${value}"
if [ -z "${EFI_MOUNT}" ]; then if [ -z "${EFI_MOUNT}" ]; then
mount_efiboot_img ${isodir} mount_efiboot_img "${isodir}"
fi fi
for f in ${isodir}/isolinux.cfg ${isodir}/syslinux.cfg; do for f in "${isodir}"/isolinux/isolinux.cfg ; do
grep -q "^[[:space:]]*append\>.*[[:space:]]${param}=" ${f} grep -q "^[[:space:]]*append\>.*[[:space:]]${param}=" "${f}"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# Parameter already exists. Update the value # Parameter already exists. Update the value
sed -i -e "s#^\([[:space:]]*append\>.*${param}\)=[^[:space:]]*#\1=${value}#" ${f} sed -i -e "s#^\([[:space:]]*append\>.*${param}\)=[^[:space:]]*#\1=${value}#" "${f}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
log_error "Failed to update parameter ($param)" elog "Failed to update parameter ($param)"
exit 1
fi fi
else else
# Parameter doesn't exist. Add it to the cmdline # Parameter doesn't exist. Add it to the cmdline
sed -i -e "s|^\([[:space:]]*append\>.*\)|\1 ${param}=${value}|" ${f} sed -i -e "s|^\([[:space:]]*append\>.*\)|\1 ${param}=${value}|" "${f}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
log_error "Failed to add parameter ($param)" elog "Failed to add parameter ($param)"
exit 1
fi fi
fi fi
done done
for f in ${isodir}/EFI/BOOT/grub.cfg ${EFI_MOUNT}/EFI/BOOT/grub.cfg; do for f in ${isodir}/EFI/BOOT/grub.cfg ${EFI_MOUNT}/EFI/BOOT/grub.cfg ; do
grep -q "^[[:space:]]*linuxefi\>.*[[:space:]]${param}=" ${f} grep -q "^[[:space:]]*linux\>.*[[:space:]]${param}=" "${f}"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# Parameter already exists. Update the value # Parameter already exists. Update the value
sed -i -e "s#^\([[:space:]]*linuxefi\>.*${param}\)=[^[:space:]]*#\1=${value}#" ${f} sed -i -e "s#^\([[:space:]]*linux\>.*${param}\)=[^[:space:]]*#\1=${value}#" "${f}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
log_error "Failed to update parameter ($param)" elog "Failed to update parameter ($param)"
exit 1
fi fi
else else
# Parameter doesn't exist. Add it to the cmdline # Parameter doesn't exist. Add it to the cmdline
sed -i -e "s|^\([[:space:]]*linuxefi\>.*\)|\1 ${param}=${value}|" ${f} sed -i -e "s|^\([[:space:]]*linux\>.*\)|\1 ${param}=${value}|" "${f}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
log_error "Failed to add parameter ($param)" elog "Failed to add parameter ($param)"
exit 1
fi fi
fi fi
done done

View File

@ -0,0 +1,310 @@
#!/bin/bash
#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Utility for updating an ISO
#
# This utility supports the following:
# 1. Provide a custom kickstart post addon, allowing the user
# to add some custom configuration, such as custom network
# interface config
# 2. Add or modify installation boot parameters, such as changing
# the default boot_device and rootfs_device disks
#
# Source shared utility functions
source $(dirname $0)/stx-iso-utils.sh
function log_error {
echo "$@" >&2
}
function usage {
cat <<ENDUSAGE
Usage:
$(basename $0) -i <input bootimage.iso> -o <output bootimage.iso>
[ -a <ks-addon.cfg> ] [ -p param=value ]
[ -d <default menu option> ] [ -t <menu timeout> ]
-i <file>: Specify input ISO file
-o <file>: Specify output ISO file
-a <file>: Specify ks-addon.cfg file
-p <p=v>: Specify boot parameter
Examples:
-p rootfs_device=nvme0n1 -p boot_device=nvme0n1
-p rootfs_device=/dev/disk/by-path/pci-0000:00:0d.0-ata-1.0
-p boot_device=/dev/disk/by-path/pci-0000:00:0d.0-ata-1.0
-d <default menu option>:
Specify default boot menu option:
0 - Standard Controller, Serial Console
1 - Standard Controller, Graphical Console
2 - AIO, Serial Console
3 - AIO, Graphical Console
4 - AIO Low-latency, Serial Console
5 - AIO Low-latency, Graphical Console
NULL - Clear default selection
-t <menu timeout>:
Specify boot menu timeout, in seconds
Example ks-addon.cfg, to define a VLAN on initial OAM interface setup:
#### start ks-addon.cfg
OAM_DEV=enp0s3
OAM_VLAN=1234
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-\$OAM_DEV
DEVICE=\$OAM_DEV
BOOTPROTO=none
ONBOOT=yes
LINKDELAY=20
EOF
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-\$OAM_DEV.\$OAM_VLAN
DEVICE=\$OAM_DEV.\$OAM_VLAN
BOOTPROTO=dhcp
ONBOOT=yes
VLAN=yes
LINKDELAY=20
EOF
#### end ks-addon.cfg
ENDUSAGE
}
function cleanup {
common_cleanup
}
function check_requirements {
common_check_requirements
}
function set_default_label {
local isodir=$1
if [ -z "${EFI_MOUNT}" ]; then
mount_efiboot_img ${isodir}
fi
for f in ${isodir}/isolinux.cfg ${isodir}/syslinux.cfg; do
if [ "${DEFAULT_LABEL}" = "NULL" ]; then
# Remove default, if set
grep -q '^default' ${f}
if [ $? -eq 0 ]; then
sed -i '/^default/d' ${f}
fi
else
grep -q '^default' ${f}
if [ $? -ne 0 ]; then
cat <<EOF >> ${f}
default ${DEFAULT_LABEL}
EOF
else
sed -i "s/^default.*/default ${DEFAULT_LABEL}/" ${f}
fi
fi
done
for f in ${isodir}/EFI/BOOT/grub.cfg ${EFI_MOUNT}/EFI/BOOT/grub.cfg; do
sed -i "s/^default=.*/default=\"${DEFAULT_GRUB_ENTRY}\"/" ${f}
done
}
function set_timeout {
local isodir=$1
if [ -z "${EFI_MOUNT}" ]; then
mount_efiboot_img ${isodir}
fi
for f in ${isodir}/isolinux.cfg ${isodir}/syslinux.cfg; do
sed -i "s/^timeout.*/timeout ${TIMEOUT}/" ${f}
done
for f in ${isodir}/EFI/BOOT/grub.cfg ${EFI_MOUNT}/EFI/BOOT/grub.cfg; do
sed -i "s/^timeout=.*/timeout=${GRUB_TIMEOUT}/" ${f}
grep -q "^ set timeout=" ${f}
if [ $? -eq 0 ]; then
# Submenu timeout is already added. Update the value
sed -i -e "s#^ set timeout=.*# set timeout=${GRUB_TIMEOUT}#" ${f}
if [ $? -ne 0 ]; then
echo "Failed to update grub timeout"
exit 1
fi
else
# Parameter doesn't exist. Add it to the cmdline
sed -i -e "/^submenu/a \ \ set timeout=${GRUB_TIMEOUT}" ${f}
if [ $? -ne 0 ]; then
echo "Failed to add grub timeout"
exit 1
fi
fi
done
}
declare INPUT_ISO=
declare OUTPUT_ISO=
declare ORIG_PWD=$PWD
declare ADDON=
declare -a PARAMS
declare DEFAULT_LABEL=
declare DEFAULT_GRUB_ENTRY=
declare UPDATE_TIMEOUT="no"
declare -i TIMEOUT=0
declare GRUB_TIMEOUT=-1
while getopts "hi:o:a:p:d:t:" opt; do
case $opt in
i)
INPUT_ISO=$OPTARG
;;
o)
OUTPUT_ISO=$OPTARG
;;
a)
ADDON=$OPTARG
;;
p)
PARAMS+=(${OPTARG})
;;
d)
DEFAULT_LABEL=${OPTARG}
case ${DEFAULT_LABEL} in
0)
DEFAULT_GRUB_ENTRY="standard>serial"
;;
1)
DEFAULT_GRUB_ENTRY="standard>graphical"
;;
2)
DEFAULT_GRUB_ENTRY="aio>serial"
;;
3)
DEFAULT_GRUB_ENTRY="aio>graphical"
;;
4)
DEFAULT_GRUB_ENTRY="aio-lowlat>serial"
;;
5)
DEFAULT_GRUB_ENTRY="aio-lowlat>graphical"
;;
'NULL')
DEFAULT_GRUB_ENTRY=2
;;
*)
echo "Invalid default boot menu option: ${DEFAULT_LABEL}" >&2
usage
exit 1
;;
esac
;;
t)
let -i timeout_arg=${OPTARG}
if [ ${timeout_arg} -gt 0 ]; then
let -i TIMEOUT=${timeout_arg}*10
GRUB_TIMEOUT=${timeout_arg}
elif [ ${timeout_arg} -eq 0 ]; then
GRUB_TIMEOUT=0.001
fi
UPDATE_TIMEOUT="yes"
;;
*)
usage
exit 1
;;
esac
done
if [ "${DEFAULT_LABEL}" = "NULL" ]; then
# Reset timeouts to default
TIMEOUT=0
GRUB_TIMEOUT=-1
UPDATE_TIMEOUT="yes"
fi
check_requirements
check_required_param "-i" "${INPUT_ISO}"
check_required_param "-o" "${OUTPUT_ISO}"
if [ ! -f ${INPUT_ISO} ]; then
echo "Input file does not exist: ${INPUT_ISO}"
exit 1
fi
if [ -f ${OUTPUT_ISO} ]; then
echo "Output file already exists: ${OUTPUT_ISO}"
exit 1
fi
shift $((OPTIND-1))
trap cleanup EXIT
BUILDDIR=$(mktemp -d -p $PWD updateiso_build_XXXXXX)
if [ -z "${BUILDDIR}" -o ! -d ${BUILDDIR} ]; then
echo "Failed to create builddir. Aborting..."
exit $rc
fi
mount_iso ${INPUT_ISO}
rsync -a ${MNTDIR}/ ${BUILDDIR}/
rc=$?
if [ $rc -ne 0 ]; then
echo "Call to rsync ISO content. Aborting..."
exit $rc
fi
unmount_iso
if [ ${#PARAMS[@]} -gt 0 ]; then
for p in ${PARAMS[@]}; do
param=${p%%=*} # Strip from the first '=' on
value=${p#*=} # Strip to the first '='
update_parameter ${BUILDDIR} "${param}" "${value}"
done
fi
if [ -n "${DEFAULT_LABEL}" ]; then
set_default_label ${BUILDDIR}
fi
if [ "${UPDATE_TIMEOUT}" = "yes" ]; then
set_timeout ${BUILDDIR}
fi
if [ -n "${ADDON}" ]; then
\rm -f ${BUILDDIR}/ks-addon.cfg
\cp ${ADDON} ${BUILDDIR}/ks-addon.cfg
if [ $? -ne 0 ]; then
echo "Error: Failed to copy ${ADDON}"
exit 1
fi
fi
unmount_efiboot_img
# Rebuild the ISO
mkisofs -o ${OUTPUT_ISO} \
-R -D -A 'oe_iso_boot' -V 'oe_iso_boot' \
-quiet \
-b isolinux.bin -c boot.cat -no-emul-boot \
-boot-load-size 4 -boot-info-table \
-eltorito-alt-boot \
-e images/efiboot.img \
-no-emul-boot \
${BUILDDIR}
isohybrid --uefi ${OUTPUT_ISO}
implantisomd5 ${OUTPUT_ISO}
echo "Updated ISO: ${OUTPUT_ISO}"

View File

@ -1,41 +1,61 @@
#!/bin/bash #!/bin/bash
# #
# Copyright (c) 2019 Wind River Systems, Inc. # Copyright (c) 2019-2022 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
# Utility for updating an ISO #############################################################################
#
# Utility for updating a starlingX Debian ISO
#
# This utility supports the following update options:
#
# 1. Add a custom kickstart post addon script to the root directory
# of the ISO, allowing the user to add some custom configuration,
# such as custom network interface config.
# #
# This utility supports the following:
# 1. Provide a custom kickstart post addon, allowing the user
# to add some custom configuration, such as custom network
# interface config
# 2. Add or modify installation boot parameters, such as changing # 2. Add or modify installation boot parameters, such as changing
# the default boot_device and rootfs_device disks # the default install storage device.
# Note: Recommend using by-path notation for storage device names.
# Note: Added or modified boot parameters must be delimited by '='
# For example: <some_boot_parm>=<some_boot_value>
# #
# 3. Modify the default USB install type ; Standard Controller or
# either standard or realtime All-In-One graphical or serial modes.
#
# 4. Clear the default USB install type with -d|--default NULL.
# Note: This will clear the default timeout ; set to no timeout.
#
#############################################################################
# Source shared utility functions # Source shared utility functions
source $(dirname $0)/stx-iso-utils.sh source "$(dirname "$0")/stx-iso-utils.sh"
function log_error { # add new line before tool output
echo "$@" >&2 echo ""
}
function usage { function usage {
cat <<ENDUSAGE cat <<ENDUSAGE
Usage: Usage:
$(basename $0) -i <input bootimage.iso> -o <output bootimage.iso> $(basename "$0") \
[ -a <ks-addon.cfg> ] [ -p param=value ] -i|--input '/path/to/input/<bootimage>.iso'
[ -d <default menu option> ] [ -t <menu timeout> ] -o|--output '/path/to/output/<bootimage>.iso'
-i <file>: Specify input ISO file [ -a|--addon '/path/to/<ks-addon>.cfg ]
-o <file>: Specify output ISO file [ -p|--param param=value ]
-a <file>: Specify ks-addon.cfg file [ -d|--default <default menu option> ]
-p <p=v>: Specify boot parameter [ -t|--timeout <menu timeout> ]
Examples: [ -v|--verbose ]
-p rootfs_device=nvme0n1 -p boot_device=nvme0n1 [ -h|--help ]
-p rootfs_device=/dev/disk/by-path/pci-0000:00:0d.0-ata-1.0 Options Descriptions:
-p boot_device=/dev/disk/by-path/pci-0000:00:0d.0-ata-1.0
-i <path/file>: Specify input ISO file
-o <path/file>: Specify output ISO file
-a <path/file>: Specify ks-addon.cfg file
-p <p=v>: Specify boot parameter
Example:
-p instdev=/dev/disk/by-path/pci-0000:00:0d.0-ata-1.0
-d <default menu option>: -d <default menu option>:
Specify default boot menu option: Specify default boot menu option:
@ -46,22 +66,30 @@ Usage:
4 - AIO Low-latency, Serial Console 4 - AIO Low-latency, Serial Console
5 - AIO Low-latency, Graphical Console 5 - AIO Low-latency, Graphical Console
NULL - Clear default selection NULL - Clear default selection
-t <menu timeout>: -t <menu timeout>:
Specify boot menu timeout, in seconds Specify boot menu timeout, in seconds
Example ks-addon.cfg, to define a VLAN on initial OAM interface setup: -v Verbose mode
-h Display this help
Kickstart Addon Example:
What: Define a VLAN on initial OAM interface setup:
How : Create and pass a file containing the following
kind of code using the -a <filename> option.
#### start ks-addon.cfg #### start ks-addon.cfg
OAM_DEV=enp0s3 OAM_DEV=enp0s3
OAM_VLAN=1234 OAM_VLAN=1234
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-\$OAM_DEV cat << EOF > /etc/sysconfig/network-scripts/ifcfg-\$OAM_DEV
DEVICE=\$OAM_DEV DEVICE=\$OAM_DEV
BOOTPROTO=none BOOTPROTO=none
ONBOOT=yes ONBOOT=yes
LINKDELAY=20 LINKDELAY=20
EOF EOF
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-\$OAM_DEV.\$OAM_VLAN cat << EOF > /etc/sysconfig/network-scripts/ifcfg-\$OAM_DEV.\$OAM_VLAN
DEVICE=\$OAM_DEV.\$OAM_VLAN DEVICE=\$OAM_DEV.\$OAM_VLAN
BOOTPROTO=dhcp BOOTPROTO=dhcp
ONBOOT=yes ONBOOT=yes
@ -71,6 +99,7 @@ EOF
#### end ks-addon.cfg #### end ks-addon.cfg
ENDUSAGE ENDUSAGE
exit 0
} }
function cleanup { function cleanup {
@ -82,73 +111,95 @@ function check_requirements {
} }
function set_default_label { function set_default_label {
local isodir=$1 local isodir="$1"
ilog "updating default menu selection to ${DEFAULT_GRUB_ENTRY}"
if [ -z "${EFI_MOUNT}" ]; then if [ -z "${EFI_MOUNT}" ]; then
mount_efiboot_img ${isodir} mount_efiboot_img "${isodir}"
fi fi
for f in ${isodir}/isolinux.cfg ${isodir}/syslinux.cfg; do for f in "${isodir}"/isolinux/isolinux.cfg; do
if [ "${DEFAULT_LABEL}" = "NULL" ]; then if [ "${DEFAULT_LABEL}" = "NULL" ]; then
# Remove default, if set # Remove default, if set
grep -q '^default' ${f} grep -q '^default' "${f}"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
sed -i '/^default/d' ${f} sed -i '/^default/d' "${f}"
fi fi
else else
grep -q '^default' ${f} # Need to increment this value by 1 for the isolinux (BIOS) case.
# This is because LAT starts the isolinux grub menu at 1 rather than 0.
# Doing this avoids a customer visable menu selection numbering change.
DEFAULT_LABEL=$((DEFAULT_LABEL+1))
grep -q '^default' "${f}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
cat <<EOF >> ${f} cat <<EOF >> "${f}"
default ${DEFAULT_LABEL} default ${DEFAULT_LABEL}
EOF EOF
else else
sed -i "s/^default.*/default ${DEFAULT_LABEL}/" ${f} sed -i "s/^default.*/default ${DEFAULT_LABEL}/" "${f}"
fi
# The Debian isolinux grub menus from LAT have a 'ontimoeout
# setting that gets defaulted to 1=Controller Install. This
# setting needs to be updated as well.
grep -q '^ontimeout' "${f}"
if [ $? -eq 0 ]; then
ilog "updating ontimeout label to ${DEFAULT_LABEL}"
sed -i "s/^ontimeout.*/ontimeout ${DEFAULT_LABEL}/" "${f}"
fi fi
fi fi
done done
for f in ${isodir}/EFI/BOOT/grub.cfg ${EFI_MOUNT}/EFI/BOOT/grub.cfg; do for f in ${isodir}/EFI/BOOT/grub.cfg ${EFI_MOUNT}/EFI/BOOT/grub.cfg; do
sed -i "s/^default=.*/default=\"${DEFAULT_GRUB_ENTRY}\"/" ${f} sed -i "s/^set default=.*/set default=\"${DEFAULT_GRUB_ENTRY}\"/" "${f}"
# Now update the other cases that LAT adds to the grub file that
# will override the above case if not dealt with similarly
sed -i "s/^ set default=.*/ set default=\"${DEFAULT_GRUB_ENTRY}\"/" "${f}"
sed -i "s/^ set default=.*/ set default=\"${DEFAULT_GRUB_ENTRY}\"/" "${f}"
done done
} }
function set_timeout { function set_timeout {
local isodir=$1 local isodir="$1"
ilog "updating default menu timeout to ${GRUB_TIMEOUT} secs"
if [ -z "${EFI_MOUNT}" ]; then if [ -z "${EFI_MOUNT}" ]; then
mount_efiboot_img ${isodir} mount_efiboot_img "${isodir}"
fi fi
for f in ${isodir}/isolinux.cfg ${isodir}/syslinux.cfg; do for f in "${isodir}"/isolinux/isolinux.cfg; do
sed -i "s/^timeout.*/timeout ${TIMEOUT}/" ${f} sed -i "s/^TIMEOUT.*/TIMEOUT ${TIMEOUT}/" "${f}"
done done
for f in ${isodir}/EFI/BOOT/grub.cfg ${EFI_MOUNT}/EFI/BOOT/grub.cfg; do for f in ${isodir}/EFI/BOOT/grub.cfg ${EFI_MOUNT}/EFI/BOOT/grub.cfg; do
sed -i "s/^timeout=.*/timeout=${GRUB_TIMEOUT}/" ${f} sed -i "s/^set timeout=.*/set timeout=${GRUB_TIMEOUT}/" "${f}"
grep -q "^ set timeout=" ${f} grep -q "^ set timeout=" "${f}"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# Submenu timeout is already added. Update the value # Submenu timeout is already added. Update the value
sed -i -e "s#^ set timeout=.*# set timeout=${GRUB_TIMEOUT}#" ${f} sed -i -e "s#^ set timeout=.*# set timeout=${GRUB_TIMEOUT}#" "${f}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to update grub timeout" elog "Failed to update grub timeout"
exit 1
fi fi
else else
# Parameter doesn't exist. Add it to the cmdline # Parameter doesn't exist. Add it to the cmdline
sed -i -e "/^submenu/a \ \ set timeout=${GRUB_TIMEOUT}" ${f} sed -i -e "/^submenu/a \ \ set timeout=${GRUB_TIMEOUT}" "${f}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to add grub timeout" elog "Failed to add grub timeout"
exit 1
fi fi
fi fi
done done
} }
# print usage when there are no arguements provided
[ "${*}" == "" ] && usage
declare INPUT_ISO= declare INPUT_ISO=
declare OUTPUT_ISO= declare OUTPUT_ISO=
declare ORIG_PWD=$PWD
declare ADDON= declare ADDON=
declare -a PARAMS declare -a PARAMS
declare DEFAULT_LABEL= declare DEFAULT_LABEL=
@ -156,27 +207,53 @@ declare DEFAULT_GRUB_ENTRY=
declare UPDATE_TIMEOUT="no" declare UPDATE_TIMEOUT="no"
declare -i TIMEOUT=0 declare -i TIMEOUT=0
declare GRUB_TIMEOUT=-1 declare GRUB_TIMEOUT=-1
declare VERBOSE=false
while getopts "hi:o:a:p:d:t:" opt; do script=$(basename "$0")
case $opt in OPTS=$(getopt -o a:d:hi:o:p:t:v \
i) --long addon:,default:,help,input:,output:,param:,timeout:,verbose \
INPUT_ISO=$OPTARG -n "${script}" -- "$@")
;; if [ $? != 0 ]; then
o) echo "Failed parsing options." >&2
OUTPUT_ISO=$OPTARG usage
;; fi
a)
ADDON=$OPTARG
;;
p)
PARAMS+=(${OPTARG})
;;
d)
DEFAULT_LABEL=${OPTARG}
eval set -- "$OPTS"
while true; do
[ ${VERBOSE} = true ] && ilog "Parsing Option: $1 $2"
case "$1" in
-v|--verbose)
VERBOSE=true
shift 1
;;
-h|--help)
usage
shift 1
;;
-i|--input)
INPUT_ISO="${2}"
shift 2
;;
-o|--output)
OUTPUT_ISO="${2}"
rm -rf "${OUTPUT_ISO}"
shift 2
;;
-a|--addon)
ADDON="${2}"
shift 2
;;
-p|--param)
PARAMS+=( "${2}" )
shift 2
;;
-d|--default)
DEFAULT_LABEL=${2}
case ${DEFAULT_LABEL} in case ${DEFAULT_LABEL} in
0) 0)
DEFAULT_GRUB_ENTRY="standard>serial" DEFAULT_GRUB_ENTRY="standard>serial"
;; ;;
1) 1)
DEFAULT_GRUB_ENTRY="standard>graphical" DEFAULT_GRUB_ENTRY="standard>graphical"
@ -194,29 +271,30 @@ while getopts "hi:o:a:p:d:t:" opt; do
DEFAULT_GRUB_ENTRY="aio-lowlat>graphical" DEFAULT_GRUB_ENTRY="aio-lowlat>graphical"
;; ;;
'NULL') 'NULL')
DEFAULT_GRUB_ENTRY=2 DEFAULT_GRUB_ENTRY="standard>serial"
;; ;;
*) *)
echo "Invalid default boot menu option: ${DEFAULT_LABEL}" >&2 msg_info="Invalid default boot menu option"
usage msg_help="needs to be value from 0..5 ; see --help screen"
exit 1 elog "${msg_info}: ${DEFAULT_LABEL} ; ${msg_help}" >&2
;; ;;
esac esac
shift 2
;; ;;
t) -t|--timeout)
let -i timeout_arg=${OPTARG} declare -i timeout_arg=${2}
if [ ${timeout_arg} -gt 0 ]; then if [ "${timeout_arg}" -gt 0 ]; then
let -i TIMEOUT=${timeout_arg}*10 (( TIMEOUT=timeout_arg*10 ))
GRUB_TIMEOUT=${timeout_arg} GRUB_TIMEOUT=${timeout_arg}
elif [ ${timeout_arg} -eq 0 ]; then elif [ "${timeout_arg}" -eq 0 ]; then
GRUB_TIMEOUT=0.001 GRUB_TIMEOUT=0.001
fi fi
UPDATE_TIMEOUT="yes" UPDATE_TIMEOUT="yes"
shift 2
;; ;;
*) --)
usage break
exit 1
;; ;;
esac esac
done done
@ -233,78 +311,89 @@ check_requirements
check_required_param "-i" "${INPUT_ISO}" check_required_param "-i" "${INPUT_ISO}"
check_required_param "-o" "${OUTPUT_ISO}" check_required_param "-o" "${OUTPUT_ISO}"
if [ ! -f ${INPUT_ISO} ]; then if [ ! -f "${INPUT_ISO}" ]; then
echo "Input file does not exist: ${INPUT_ISO}" elog "Input file does not exist: ${INPUT_ISO}"
exit 1
fi fi
if [ -f ${OUTPUT_ISO} ]; then if [ -f "${OUTPUT_ISO}" ]; then
echo "Output file already exists: ${OUTPUT_ISO}" elog "Output file already exists: ${OUTPUT_ISO}"
exit 1
fi fi
shift $((OPTIND-1))
trap cleanup EXIT trap cleanup EXIT
BUILDDIR=$(mktemp -d -p $PWD updateiso_build_XXXXXX) BUILDDIR=$(mktemp -d -p "$PWD" updateiso_build_XXXXXX)
if [ -z "${BUILDDIR}" -o ! -d ${BUILDDIR} ]; then if [ -z "${BUILDDIR}" ] || [ ! -d "${BUILDDIR}" ]; then
echo "Failed to create builddir. Aborting..." elog "Failed to create mount temp dir. Aborting..."
exit $rc
fi fi
mount_iso ${INPUT_ISO} mount_iso "${INPUT_ISO}"
rsync -a ${MNTDIR}/ ${BUILDDIR}/ ilog "rsync mounted content to ${BUILDDIR}"
rsync -a "${MNTDIR}/" "${BUILDDIR}/"
rc=$? rc=$?
if [ $rc -ne 0 ]; then [ ${rc} -ne 0 ] && elog "rsync ISO content failed rc=${rc}. Aborting..."
echo "Call to rsync ISO content. Aborting..."
exit $rc
fi
unmount_iso unmount_iso
if [ ${#PARAMS[@]} -gt 0 ]; then if [ ${#PARAMS[@]} -gt 0 ]; then
for p in ${PARAMS[@]}; do for p in "${PARAMS[@]}"; do
param=${p%%=*} # Strip from the first '=' on param=${p%%=*} # Strip from the first '=' on
value=${p#*=} # Strip to the first '=' value=${p#*=} # Strip to the first '='
update_parameter ${BUILDDIR} "${param}" "${value}" update_parameter "${BUILDDIR}" "${param}" "${value}"
done done
fi fi
if [ -n "${DEFAULT_LABEL}" ]; then if [ -n "${DEFAULT_LABEL}" ]; then
set_default_label ${BUILDDIR} set_default_label "${BUILDDIR}"
fi fi
if [ "${UPDATE_TIMEOUT}" = "yes" ]; then if [ "${UPDATE_TIMEOUT}" = "yes" ]; then
set_timeout ${BUILDDIR} set_timeout "${BUILDDIR}"
fi fi
# TODO: Remove before merge
# cp "${BUILDDIR}"/EFI/BOOT/grub.cfg /localdisk/$(basename "$0")_iso_grub.cfg
# cp "${BUILDDIR}"/isolinux/isolinux.cfg /localdisk/$(basename "$0")_isolinux.cfg
# if [ -n "${EFI_MOUNT}" ] ; then
# cp "${EFI_MOUNT}"/EFI/BOOT/grub.cfg /localdisk/$(basename "$0")_efi_grub.cfg
# fi
if [ -n "${ADDON}" ]; then if [ -n "${ADDON}" ]; then
\rm -f ${BUILDDIR}/ks-addon.cfg ilog "adding ${ADDON} to ${BUILDDIR}/ks-addon.cfg"
\cp ${ADDON} ${BUILDDIR}/ks-addon.cfg \rm -f "${BUILDDIR}"/ks-addon.cfg
\cp "${ADDON}" "${BUILDDIR}"/ks-addon.cfg
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Error: Failed to copy ${ADDON}" elog "Failed to copy ${ADDON}"
exit 1
fi fi
fi fi
unmount_efiboot_img unmount_efiboot_img
# Rebuild the ISO ilog "making iso filesystem with mkisofs in ${OUTPUT_ISO}"
mkisofs -o ${OUTPUT_ISO} \ mkisofs -o "${OUTPUT_ISO}" \
-R -D -A 'oe_iso_boot' -V 'oe_iso_boot' \ -A 'instboot' -V 'instboot' \
-quiet \ -quiet -U -J -joliet-long -r -iso-level 2 \
-b isolinux.bin -c boot.cat -no-emul-boot \ -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
-boot-load-size 4 -boot-info-table \ -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot \ -eltorito-alt-boot -e efi.img -no-emul-boot \
-e images/efiboot.img \ "${BUILDDIR}"
-no-emul-boot \
${BUILDDIR}
isohybrid --uefi ${OUTPUT_ISO} if [ -e "${OUTPUT_ISO}" ] ; then
implantisomd5 ${OUTPUT_ISO} if [ "${VERBOSE}" = true ] ; then
isohybrid --uefi "${OUTPUT_ISO}"
echo "Updated ISO: ${OUTPUT_ISO}" else
isohybrid --uefi "${OUTPUT_ISO}" >&/dev/null
fi
if [ "${VERBOSE}" = true ] ; then
implantisomd5 "${OUTPUT_ISO}"
else
implantisomd5 "${OUTPUT_ISO}" >&/dev/null
fi
rc=$?
ilog "updated ISO: ${OUTPUT_ISO}"
exit ${rc}
else
elog "the ${OUTPUT_ISO} file was not created"
fi