diff --git a/harmonic/scripts/harmonic-install-scripts/harmonic-installer.sh b/harmonic/scripts/harmonic-install-scripts/harmonic-installer.sh index a908b40..3760b83 100755 --- a/harmonic/scripts/harmonic-install-scripts/harmonic-installer.sh +++ b/harmonic/scripts/harmonic-install-scripts/harmonic-installer.sh @@ -32,7 +32,7 @@ export apolloISO="APOLLO_PLATFORM-${apolloRelease}.iso" export ostreePackages="ostree-upgrade-bootstrap_2.0.41_all.deb ostree-upgrade_2.0.41_all.deb" export proxyURI="http://proxy4.spoc.charterlab.com:8080" export proxyIgnore="localhost,44.10.4.101,44.10.4.200,172.22.31.150,10.41.64.0/24,spoc.charterlab.com,nfv.charterlab.com,.svc,172.22.73.0/24,35.135.192.0/24,10.240.72.0/22,44.0.0.0/8,[2600:6ce6:4410:803/64],[2605:1c00:50f2:2800/64],[2605:1c00:50f3:70/64]" -export workingDir="${PWD}" +export workingDir="/opt" export isoDir="/data" export physicalDisk="/dev/sda" export harmonicPV="${physicalDisk}3" diff --git a/harmonic/scripts/iso-builders/apollo-customize-and-rebuild.sh b/harmonic/scripts/iso-builders/apollo-customize-and-rebuild.sh index 41c4fc4..ec859ed 100755 --- a/harmonic/scripts/iso-builders/apollo-customize-and-rebuild.sh +++ b/harmonic/scripts/iso-builders/apollo-customize-and-rebuild.sh @@ -1,18 +1,17 @@ #!/bin/bash ############################################################################## # -# rebuild-iso.sh +# apollo-customize-and-rebuild.sh # # This script is executed by a user to rebuild the Apollo ISO using # a modified squashfs root filesystem. # ############################################################################## -export buildRoot="/opt/harmonic-image-build" +eexport buildRoot="/opt/harmonic-image-build" export isoMount="${buildRoot}/iso.mount" -export chrootPath="${buildRoot}/squashfs-root" -export buildDirs=("buildtmp" "iso.mount" "squashfs-root") -export buildTemp="${buildRoot}/buildtmp" -export newSquashfs="${buildTemp}/rootfs.squashfs" +export chrootPath="${buildRoot}/filesystem.tmp" +export buildDirs=("build.tmp" "iso.mount" "filesystem.tmp") +export buildTemp="${buildRoot}/build.tmp" export bindMounts=("run" "dev") export chrootMounts=('chrootArray["proc"]="/proc"' 'chrootArray["sysfs"]="/sys"' 'chrootArray["devpts"]="/dev/pts"') export buildLog="${buildRoot}/harmonic-iso.log" @@ -30,21 +29,21 @@ EOF # Script Help Function showHelp() { cat << EOH -Usage: $0 -i [-x -c -r -b -d] [-h] +Usage: $0 -i -f [-x -c -r -b -d] [-h] Rebuild Apollo ISO --i | - Create working directories - Mount source iso and extract rootfs.squashfs +-i | [REQUIRED] | ISO image to rebuild (will be used as source and destination filenames) --x | Extract rootfs from original ISO image +-f | [REQUIRED] | Path to SquashFS archive in source ISO (used for Chroot customizations) --c | Customize rootfs in chroot environment +-x | Extract squashfs filesystem from original ISO image --r | Generate new root.squashfs from modified rootfs files +-c | Customize filesystem in chroot environment --b | Build new iso image from source image and new rootfs.squashfs +-r | Generate new squashfs from modified filesystem + +-b | Build new iso image from source image and new squashfs -d | Deploy iso to Artifactory @@ -54,6 +53,8 @@ EOH } + + function createWorkspace() { for dir in "${buildDirs[@]}"; do if [[ ! -d "${buildRoot}/${dir}" ]]; then @@ -65,15 +66,25 @@ function createWorkspace() { } function extractRootfs() { - + if mountpoint "${isoMount}"; then + runPrint "Unmounting ${isoMount}" + umount -lf "${isoMount}" + fi + runPrint "Mounting ${originalIsoPath} at ${isoMount}" mount -o loop "${originalIsoPath}" "${isoMount}" + 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}" - rm -rf squashfs-root + rm -rf "${chrootPath}" - runPrint "Extract ${isoMount}/rootfs.squashfs to ${chrootPath}" - unsquashfs -d "${chrootPath}" "${isoMount}/rootfs.squashfs" + runPrint "Extract ${isoMount}/${squashfsIsoPath} to ${chrootPath}" + unsquashfs -d "${chrootPath}" "${isoMount}/${squashfsIsoPath}" umount -f "${isoMount}" @@ -100,7 +111,7 @@ function setupChroot() { } function cleanupChroot() { - + for cmount in "${!chrootArray[@]}"; do runPrint "Unounting ${cmount} at ${chrootArray[${cmount}]}" umount "${chrootPath}${chrootArray[${cmount}]}" @@ -115,14 +126,14 @@ function cleanupChroot() { } function resquashRootfs() { - - if [[ ! -d ${chrootPath} ]]; then + + if [[ ! -d ${chrootPath} ]]; then runPrint "No root source found!!" exit 1 fi - + rm -f "${newSquashfs}" - + runPrint "Creating new squashfs at ${newSquashfs} from ${chrootPath} ..." mksquashfs "${chrootPath}" "${newSquashfs}" -noappend @@ -138,14 +149,30 @@ function buildIso() { fi export newIso="${buildTemp}/${isoFile}" rm -f "${newIso}" - xorriso -overwrite on -indev "${originalIsoPath}" -outdev "${newIso}" -pathspecs on -add rootfs.squashfs="${newSquashfs}" +cat <" + exit 1 + fi if [[ ! -f ${originalIsoPath} ]]; then runPrint "No source iso found at ${originalIsoPath} !!" fi + isoFile=$(basename "${originalIsoPath}") + + ;; + f) + squashfsIsoPath=${OPTARG} + + if [[ -z "${squashfsIsoPath}" ]]; then + echo "Error: Must define -f " + exit 1 + fi + squashfsFilename=$(basename "${squashfsIsoPath}") + newSquashfs="${buildTemp}/${squashfsFilename}" ;; x) export doSetup=1 @@ -250,7 +291,7 @@ Generated ${newIso} from: iso: ${originalIsoPath} squashfs: ${newSquashfs} - + Activity log can be viewed at ${buildLog} ... ====================================================================================== @@ -268,6 +309,4 @@ if [[ "${doDeployIso}" == 1 ]]; then echo -e "\n\nFailed - Check ${buildLog}\n\n" fi -fi - - +fi \ No newline at end of file diff --git a/harmonic/scripts/iso-builders/ubuntu-create-liveiso.sh b/harmonic/scripts/iso-builders/ubuntu-create-liveiso.sh index 468476d..0b35d01 100755 --- a/harmonic/scripts/iso-builders/ubuntu-create-liveiso.sh +++ b/harmonic/scripts/iso-builders/ubuntu-create-liveiso.sh @@ -1,99 +1,312 @@ -#!/bin/bash -x +#!/bin/bash +############################################################################## +# +# rebuild-iso.sh +# +# This script is executed by a user to rebuild the Apollo ISO using +# a modified squashfs root filesystem. +# +############################################################################## +export buildRoot="/opt/harmonic-image-build" +export isoMount="${buildRoot}/iso.mount" +export chrootPath="${buildRoot}/filesystem.tmp" +export buildDirs=("build.tmp" "iso.mount" "filesystem.tmp") +export buildTemp="${buildRoot}/build.tmp" +export bindMounts=("run" "dev") +export chrootMounts=('chrootArray["proc"]="/proc"' 'chrootArray["sysfs"]="/sys"' 'chrootArray["devpts"]="/dev/pts"') +export buildLog="${buildRoot}/harmonic-iso.log" +export artifactoryURL="https://artifactory.charterlab.com" +export artifactoryPath="artifactory/upload/harmonic" +declare -A chrootArray +runPrint() { +cat << EOF +=========================================================== + $@ +=========================================================== +EOF +} -set -e +# Script Help Function +showHelp() { +cat << EOH +Usage: $0 -i -f [-x -c -r -b -d] [-h] -# Function to check for required tools -check_tools() { - for tool in xorriso grub-mkstandalone; do - if ! command -v $tool &> /dev/null; then - echo "Error: $tool is not installed. Please install it and try again." - exit 1 - fi - done -} +Rebuild Apollo ISO + +-i | [REQUIRED] | ISO image to rebuild (will be used as source and destination filenames) + +-f | [REQUIRED] | Path to SquashFS archive in source ISO (used for Chroot customizations) + +-x | Extract squashfs filesystem from original ISO image + +-c | Customize filesystem in chroot environment + +-r | Generate new squashfs from modified filesystem + +-b | Build new iso image from source image and new squashfs + +-d | Deploy iso to Artifactory + +-h | Display help + +EOH -# Function to prepare the directory structure -prepare_directories() { - mkdir -p iso/boot/grub - mkdir -p iso/boot/{kernel,initrd} - echo "Directory structure prepared." } -# Function to copy kernel and initrd -copy_kernel_initrd() { - cp "$1" iso/boot/kernel/vmlinuz - cp "$2" iso/boot/initrd/initrd.img - echo "Kernel and initrd copied." + + +function createWorkspace() { + for dir in "${buildDirs[@]}"; do + if [[ ! -d "${buildRoot}/${dir}" ]]; then + runPrint "Creating ${buildRoot}/${dir}" + mkdir -p "${buildRoot}/${dir}" + fi + done + return } -# Function to copy squashfs file -copy_squashfs() { - cp "$1" iso/boot/ - echo "Squashfs file copied." +function extractRootfs() { + if mountpoint "${isoMount}"; then + runPrint "Unmounting ${isoMount}" + umount -lf "${isoMount}" + fi + + runPrint "Mounting ${originalIsoPath} at ${isoMount}" + mount -o loop "${originalIsoPath}" "${isoMount}" + + 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}" + rm -rf "${chrootPath}" + + runPrint "Extract ${isoMount}/${squashfsIsoPath} to ${chrootPath}" + unsquashfs -d "${chrootPath}" "${isoMount}/${squashfsIsoPath}" + + umount -f "${isoMount}" + } -# Function to create grub.cfg -create_grub_cfg() { - cat < iso/boot/grub/grub.cfg -set timeout=10 -set default=0 +function setupChroot() { + + for bmount in "${bindMounts[@]}"; do + runPrint "Bind mounting /${bmount} at ${chrootPath}/${bmount}" + mount --bind "/${bmount}" "${chrootPath}/${bmount}" + done + + for arraymount in "${chrootMounts[@]}"; do + eval "${arraymount}" + done + + runPrint "${!chrootArray[@]}" + for cmount in "${!chrootArray[@]}"; do + runPrint "Mounting ${cmount} at ${chrootPath}${chrootArray[${cmount}]}" + mount -t "${cmount}" none "${chrootPath}${chrootArray[${cmount}]}" + done -menuentry "Custom Linux" { - linux /boot/kernel/vmlinuz boot=live toram - initrd /boot/initrd/initrd.img + return } -EOF - echo "grub.cfg created." + +function cleanupChroot() { + + for cmount in "${!chrootArray[@]}"; do + runPrint "Unounting ${cmount} at ${chrootArray[${cmount}]}" + umount "${chrootPath}${chrootArray[${cmount}]}" + done + + for bmount in "${bindMounts[@]}"; do + runPrint "Unmounting bindmount ${bmount} at ${chrootPath}/${bmount}" + umount "${chrootPath}/${bmount}" + done + + return } -# Function to create BIOS and EFI directory structure -create_bios_efi_structure() { - mkdir -p iso/EFI/BOOT - cp /usr/lib/grub/x86_64-efi/{bootx64.efi,grubx64.efi} iso/EFI/BOOT/ - grub-mkstandalone --format=i386-pc --output=iso/boot/grub/i386-pc/core.img --install-modules="linux normal iso9660 biosdisk memdisk search tar ls" --modules="linux normal iso9660 biosdisk search" --locales="" --fonts="" "boot/grub/grub.cfg=iso/boot/grub/grub.cfg" - cat /usr/lib/grub/i386-pc/cdboot.img iso/boot/grub/i386-pc/core.img > iso/boot/grub/i386-pc/eltorito.img - echo "BIOS and EFI structure created." +function resquashRootfs() { + + if [[ ! -d ${chrootPath} ]]; then + runPrint "No root source found!!" + exit 1 + fi + + rm -f "${newSquashfs}" + + runPrint "Creating new squashfs at ${newSquashfs} from ${chrootPath} ..." + + mksquashfs "${chrootPath}" "${newSquashfs}" -noappend + + return } -# Function to create the ISO -create_iso() { - xorriso -as mkisofs \ - -iso-level 3 \ - -o bootable-uefi-bios.iso \ - -full-iso9660-filenames \ - -volid "CustomISO" \ - -eltorito-boot boot/grub/i386-pc/eltorito.img \ - -no-emul-boot \ - -boot-load-size 4 \ - -boot-info-table \ - -eltorito-alt-boot \ - -e EFI/BOOT/bootx64.efi \ - -no-emul-boot \ - -isohybrid-gpt-basdat \ - -isohybrid-apm-hfsplus \ - -partition_cyl_align on \ - -partition_offset 16 \ - -append_partition 2 0xef iso/EFI/BOOT/bootx64.efi \ - iso - echo "Bootable ISO created." +function buildIso() { + + if [[ ! -f ${newSquashfs} ]]; then + runPrint "No squashFS found!!" + return 1 + fi + export newIso="${buildTemp}/${isoFile}" + rm -f "${newIso}" +cat < " - exit 1 +function deployIso() { + + export newIso="${buildTemp}/${isoFile}" + + if [[ ! -f ${newIso} ]]; then + runPrint "No ISO found at ${newIso} to deploy !!" + return 1 fi - check_tools - prepare_directories - copy_kernel_initrd "$1" "$2" - copy_squashfs "$3" - create_grub_cfg - create_bios_efi_structure - create_iso +cat <" + exit 1 + fi + if [[ ! -f ${originalIsoPath} ]]; then + runPrint "No source iso found at ${originalIsoPath} !!" + fi + isoFile=$(basename "${originalIsoPath}") + + ;; + f) + squashfsIsoPath=${OPTARG} + + if [[ -z "${squashfsIsoPath}" ]]; then + echo "Error: Must define -f " + exit 1 + fi + squashfsFilename=$(basename "${squashfsIsoPath}") + newSquashfs="${buildTemp}/${squashfsFilename}" + ;; + x) + export doSetup=1 + ;; + c) + export doChroot=1 + ;; + r) + export doBuildRootfs=1 + ;; + b) + export doBuildIso=1 + ;; + d) + export doDeployIso=1 + ;; + + :) + runPrint "Invalid option: -${OPTARG} requires an argument" 1>&2 + showHelp + exit 1 + ;; + \?|*) + runPrint "Invalid option: -${OPTARG}" 1>&2 + showHelp + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + + +# Main Runners + +createWorkspace + +if [[ ${doSetup} == 1 ]]; then + # shellcheck disable=SC2312 + extractRootfs >(tee -a "${buildLog}" >&2) > >(tee -a "${buildLog}") +fi + +if [[ ${doChroot} == 1 ]]; then + # shellcheck disable=SC2312 + setupChroot >(tee -a "${buildLog}" >&2) > >(tee -a "${buildLog}") + trap cleanupChroot EXIT + chroot "${chrootPath}" +fi + +if [[ "${doBuildRootfs}" == 1 ]]; then + # shellcheck disable=SC2312 + resquashRootfs >(tee -a "${buildLog}" >&2) > >(tee -a "${buildLog}") +fi + +if [[ "${doBuildIso}" == 1 ]]; then + # shellcheck disable=SC2312 + buildIso >(tee -a "${buildLog}">&2) > >(tee -a "${buildLog}") + +cat <(tee -a "${buildLog}">&2) > >(tee -a "${buildLog}") + # shellcheck disable=SC2181 + if [[ $? == 0 ]]; then + echo -e "\n\nDone!\n\n" + else + echo -e "\n\nFailed - Check ${buildLog}\n\n" + + fi +fi \ No newline at end of file