From b87134190b4f1668d6110da87d572885adf9356b Mon Sep 17 00:00:00 2001 From: Alan Janis Date: Tue, 27 Aug 2024 22:22:02 +0000 Subject: [PATCH] update apollo image creation script to handle harmonic live-installer in-ram ISO builds as well --- .../apollo-customize-and-rebuild.sh | 137 +++++++++++++----- 1 file changed, 104 insertions(+), 33 deletions(-) diff --git a/harmonic/scripts/iso-builders/apollo-customize-and-rebuild.sh b/harmonic/scripts/iso-builders/apollo-customize-and-rebuild.sh index ec859ed..1b612db 100755 --- a/harmonic/scripts/iso-builders/apollo-customize-and-rebuild.sh +++ b/harmonic/scripts/iso-builders/apollo-customize-and-rebuild.sh @@ -7,11 +7,13 @@ # a modified squashfs root filesystem. # ############################################################################## -eexport buildRoot="/opt/harmonic-image-build" +# shellcheck disable=SC2155 +export buildRoot="$(realpath .)" export isoMount="${buildRoot}/iso.mount" export chrootPath="${buildRoot}/filesystem.tmp" -export buildDirs=("build.tmp" "iso.mount" "filesystem.tmp") +export buildDirs=("build.tmp" "iso.mount" "filesystem.tmp" "iso.tmp") export buildTemp="${buildRoot}/build.tmp" +export isoTemp="${buildRoot}/iso.tmp" export bindMounts=("run" "dev") export chrootMounts=('chrootArray["proc"]="/proc"' 'chrootArray["sysfs"]="/sys"' 'chrootArray["devpts"]="/dev/pts"') export buildLog="${buildRoot}/harmonic-iso.log" @@ -20,9 +22,11 @@ export artifactoryPath="artifactory/upload/harmonic" declare -A chrootArray runPrint() { cat << EOF + =========================================================== $@ =========================================================== + EOF } @@ -64,8 +68,7 @@ function createWorkspace() { done return } - -function extractRootfs() { +function mountIso() { if mountpoint "${isoMount}"; then runPrint "Unmounting ${isoMount}" umount -lf "${isoMount}" @@ -73,21 +76,34 @@ function extractRootfs() { runPrint "Mounting ${originalIsoPath} at ${isoMount}" mount -o loop "${originalIsoPath}" "${isoMount}" + return +} + +function extractRootfs() { if [[ ! -f "${isoMount}/${squashfsIsoPath}" ]]; then runPrint "No SquashFS Archive found at ${isoMount}/${squashfsIsoPath}!!" runPrint "Leaving ${isoMount} mounted for debugging" exit 1 fi - - runPrint "Removing old ${chrootPath}" + + if [[ -d "${chrootPath}" ]]; then + runPrint "Removing old files from ${chrootPath}" rm -rf "${chrootPath}" + fi runPrint "Extract ${isoMount}/${squashfsIsoPath} to ${chrootPath}" unsquashfs -d "${chrootPath}" "${isoMount}/${squashfsIsoPath}" - - umount -f "${isoMount}" - + return +} +function extractIso() { + runPrint "Extract ${isoMount} to ${isoTemp}" + if [[ -d "${isoTemp}" ]]; then + runPrint "Removing old files from ${isoTemp}" + rm -rf "${isoTemp:?}/*" + fi + rsync -avp "${isoMount}/" "${isoTemp}/" + return } function setupChroot() { @@ -132,53 +148,103 @@ function resquashRootfs() { exit 1 fi - rm -f "${newSquashfs}" + if [[ -e "${newSquashfs}" ]]; then + runPrint "Removing old squashfile at ${newSquashfs}" + rm -f "${newSquashfs}" + fi runPrint "Creating new squashfs at ${newSquashfs} from ${chrootPath} ..." - mksquashfs "${chrootPath}" "${newSquashfs}" -noappend return } +function updateIsoFiles() { + runPrint "Updating ${isoTemp}/boot/grub/grub.cfg" + + cat << 'EOG' > "${isoTemp}/boot/grub/grub.cfg" +if loadfont /boot/grub/font.pf2 ; then + set gfxmode=auto + insmod efi_gop + insmod efi_uga + insmod gfxterm + terminal_output gfxterm +fi + +set menu_color_normal=white/black +set menu_color_highlight=black/light-gray + +set timeout=5 +menuentry "Ubuntu 20.04 Live-Only" { + rmmod tpm + linux /casper/vmlinuz boot=casper iso-scan/filename=${iso_path} noprompt noeject nopersistent maybe-ubiquity nomodeset quiet splash fsck.mode=skip toram + initrd /casper/initrd +} +EOG + + runPrint "Updating ${isoTemp}/isolinux/txt.cfg" + + cat << 'EOI' > "${isoTemp}/isolinux/txt.cfg" +default ubuntu2004live +label ubuntu2004live + menu label ^Ubuntu 20.04 Live-Only + kernel /casper/vmlinuz + append initrd=/casper/initrd quiet splash fsck.mode=skip toram +EOI + + runPrint "Updating ${isoTemp}/${squashfsIsoPath}" + cp "${newSquashfs}" "${isoTemp}/${squashfsIsoPath}" + return +} + function buildIso() { if [[ ! -f ${newSquashfs} ]]; then runPrint "No squashFS found!!" return 1 fi - export newIso="${buildTemp}/${isoFile}" - rm -f "${newIso}" + if [[ -e "${newIso}" ]]; then + runPrint "Removing existing file ${newIso}" + rm -f "${newIso}" + fi + cat <(tee -a "${buildLog}" >&2) > >(tee -a "${buildLog}") # shellcheck disable=SC2312 extractRootfs >(tee -a "${buildLog}" >&2) > >(tee -a "${buildLog}") fi @@ -284,7 +352,9 @@ if [[ "${doBuildIso}" == 1 ]]; then buildIso >(tee -a "${buildLog}">&2) > >(tee -a "${buildLog}") cat <