Skip to content

Commit

Permalink
update iso rebuild script to create livefs with harmonic
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanis committed Aug 27, 2024
1 parent 6a1e46e commit 2e827ab
Show file tree
Hide file tree
Showing 3 changed files with 364 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
107 changes: 73 additions & 34 deletions harmonic/scripts/iso-builders/apollo-customize-and-rebuild.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -30,21 +29,21 @@ EOF
# Script Help Function
showHelp() {
cat << EOH
Usage: $0 -i <source iso> [-x -c -r -b -d] [-h]
Usage: $0 -i <source iso> -f <squashfs path in source iso | default('/rootfs.squashfs')> [-x -c -r -b -d] [-h]
Rebuild Apollo ISO
-i <path to source iso> |
Create working directories
Mount source iso and extract rootfs.squashfs
-i | [REQUIRED] <path to source iso> | ISO image to rebuild (will be used as source and destination filenames)
-x | Extract rootfs from original ISO image
-f | [REQUIRED] <path to squashfs in source iso> | 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
Expand All @@ -54,6 +53,8 @@ EOH

}



function createWorkspace() {
for dir in "${buildDirs[@]}"; do
if [[ ! -d "${buildRoot}/${dir}" ]]; then
Expand All @@ -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}"

Expand All @@ -100,7 +111,7 @@ function setupChroot() {
}

function cleanupChroot() {

for cmount in "${!chrootArray[@]}"; do
runPrint "Unounting ${cmount} at ${chrootArray[${cmount}]}"
umount "${chrootPath}${chrootArray[${cmount}]}"
Expand All @@ -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
Expand All @@ -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 <<EOG
=====================================================================================
Would you like to add Ubuntu Live Image files? (live iso ONLY!)
======================================================================================
EOG
read -r -p "Add Live Image Files? [y/n] : " yesno || return 1

if [[ ${yesno} =~ (y|Y|es?) ]]; then
xorriso -overwrite on -indev "${originalIsoPath}" -outdev "${newIso}" -pathspecs on -add "${squashfsIsoPath}=${newSquashfs}" "boot/grub/grub.cfg=${buildTemp}/grub.cfg" "isolinux/txt.cfg=${buildTemp}/txt.cfg"
return
else
xorriso -overwrite on -indev "${originalIsoPath}" -outdev "${newIso}" -pathspecs on -add "${squashfsIsoPath}=${newSquashfs}"
return
fi

}

function deployIso() {

export newIso="${buildTemp}/${isoFile}"

if [[ ! -f ${newIso} ]]; then
runPrint "No ISO found at ${newIso} to deploy !!"
return 1
Expand All @@ -155,16 +182,15 @@ cat <<EOD
=====================================================================================
Would you like to deploy ${newIso} to Artifactory?
Would you like to deploy ${newIso} to Artifactory? [y/n]
(You will be prompted for your JFrog username and password)
======================================================================================
EOD

read -rp "Press [Enter/Return] to deploy new ISO : ";echo || return 1
read -r -p "Enter Jfrog Username : " artifactUser || return 1
read -r -p "Enter Jfrog Username : " artifactUser || return 1
# shellcheck disable=SC2162
read -s -p "Enter JFrog Password : " artifactPassword || return 1

Expand All @@ -173,18 +199,33 @@ curl -u "${artifactUser}:${artifactPassword}" -T "${newIso}" "${artifactoryURL}/
return
}

while getopts ":hxcrbdi:" o; do
while getopts ":hxcrbdi:f:" o; do
case "${o}" in
h)
showHelp
exit 0
;;
i)
originalIsoPath=${OPTARG}
isoFile=$(basename "${originalIsoPath}")
if [[ -z "${originalIsoPath}" ]]; then
echo "Error: Must define -i <original iso path>"
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 <squashfs path>"
exit 1
fi
squashfsFilename=$(basename "${squashfsIsoPath}")
newSquashfs="${buildTemp}/${squashfsFilename}"
;;
x)
export doSetup=1
Expand Down Expand Up @@ -250,7 +291,7 @@ Generated ${newIso} from:
iso: ${originalIsoPath}
squashfs: ${newSquashfs}
Activity log can be viewed at ${buildLog} ...
======================================================================================
Expand All @@ -268,6 +309,4 @@ if [[ "${doDeployIso}" == 1 ]]; then
echo -e "\n\nFailed - Check ${buildLog}\n\n"

fi
fi


fi
Loading

0 comments on commit 2e827ab

Please sign in to comment.