From 0c624208c73ee3467f11e71f0e93e449b1a356db Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 1 Sep 2023 15:41:53 -0400 Subject: [PATCH] Clean up and add error handling --- buildiso.sh | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/buildiso.sh b/buildiso.sh index 556c518..86c48a7 100755 --- a/buildiso.sh +++ b/buildiso.sh @@ -7,6 +7,7 @@ # using a standard Debian intaller ISO. The end system is suitable # for immediate bootstrapping with the PVC Ansible roles. +liveisofile="$( pwd )/debian-live-buster-DI-rc1-amd64-standard.iso" fail() { echo $@ @@ -17,7 +18,6 @@ which debootstrap &>/dev/null || fail "This script requires debootstrap." which mksquashfs &>/dev/null || fail "This script requires squashfs." which xorriso &>/dev/null || fail "This script requires xorriso." -liveisofile="$( pwd )/debian-live-buster-DI-rc1-amd64-standard.iso" tempdir=$( mktemp -d ) prepare_iso() { @@ -28,11 +28,11 @@ prepare_iso() { echo -n "Extracting Debian LiveISO files... " iso_tempdir=$( mktemp -d ) sudo mount ${liveisofile} ${iso_tempdir} &>/dev/null || fail "Error mounting LiveISO file." - sudo rsync -au --exclude live/filesystem.squashfs ${iso_tempdir}/ ${tempdir}/installer/ || fail "Error extracting LiveISO files." + sudo rsync -au --exclude live/filesystem.squashfs ${iso_tempdir}/ ${tempdir}/installer/ &>/dev/null || fail "Error extracting LiveISO files." sudo umount ${iso_tempdir} &>/dev/null || fail "Error unmounting LiveISO file." rmdir ${iso_tempdir} &>/dev/null - sudo cp -a grub.cfg ${tempdir}/installer/boot/grub/grub.cfg &>/dev/null - sudo cp -a menu.cfg ${tempdir}/installer/isolinux/menu.cfg &>/dev/null + sudo cp -a grub.cfg ${tempdir}/installer/boot/grub/grub.cfg &>/dev/null || fail "Error copying grub.cfg file." + sudo cp -a menu.cfg ${tempdir}/installer/isolinux/menu.cfg &>/dev/null || fail "Error copying menu.cfg file." echo "done." } @@ -44,31 +44,30 @@ prepare_rootfs() { --include=${SQUASHFS_PKGLIST} \ buster \ debootstrap/ \ - http://localhost:3142/ftp.ca.debian.org/debian &>/dev/null - sudo chroot debootstrap/ apt clean - sudo rsync -au debootstrap/ ${tempdir}/rootfs/ + http://localhost:3142/ftp.ca.debian.org/debian &>/dev/null || fail "Error performing debootstrap." + sudo chroot debootstrap/ apt clean &>/dev/null || fail "Error cleaning apt cache in debootstrap." + sudo rsync -au debootstrap/ ${tempdir}/rootfs/ &>/dev/null || fail "Error copying debootstrap to tempdir." echo "done." echo -n "Configuring Debian live installation... " - sudo cp install.sh ${tempdir}/rootfs/ - sudo cp ${tempdir}/rootfs/lib/systemd/system/getty\@.service ${tempdir}/rootfs/etc/systemd/system/getty@tty1.service + sudo cp ${tempdir}/rootfs/lib/systemd/system/getty\@.service ${tempdir}/rootfs/etc/systemd/system/getty@tty1.service &>/dev/null || fail "Error copying getty override to tempdir." sudo sed -i \ 's|/sbin/agetty|/sbin/agetty --autologin root|g' \ - ${tempdir}/rootfs/etc/systemd/system/getty@tty1.service - - sudo tee ${tempdir}/rootfs/etc/hostname <<<"pvc-node-installer" &>/dev/null - sudo tee -a ${tempdir}/rootfs/root/.bashrc <<<"/install.sh" &>/dev/null - sudo chroot ${tempdir}/rootfs/ /usr/bin/passwd -d root &>/dev/null + ${tempdir}/rootfs/etc/systemd/system/getty@tty1.service &>/dev/null || fail "Error setting autologin in getty override." + sudo tee ${tempdir}/rootfs/etc/hostname <<<"pvc-node-installer" &>/dev/null || fail "Error setting hostname." + sudo tee -a ${tempdir}/rootfs/root/.bashrc <<<"/install.sh" &>/dev/null || fail "Error setting bashrc." + sudo chroot ${tempdir}/rootfs/ /usr/bin/passwd -d root &>/dev/null || fail "Error disabling root password." + sudo cp install.sh ${tempdir}/rootfs/ &>/dev/null || fail "Error copying install.sh to tempdir." echo "done." echo -n "Generating squashfs image of live installation... " - sudo nice mksquashfs ${tempdir}/rootfs/ ${tempdir}/installer/live/install.squashfs -e boot &>/dev/null + sudo nice mksquashfs ${tempdir}/rootfs/ ${tempdir}/installer/live/install.squashfs -e boot &>/dev/null || fail "Error generating squashfs." echo "done." } build_iso() { - pushd ${tempdir}/installer &>/dev/null echo -n "Creating LiveCD ISO... " + pushd ${tempdir}/installer &>/dev/null xorriso -as mkisofs \ -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \ -c isolinux/boot.cat \ @@ -81,17 +80,19 @@ build_iso() { -no-emul-boot \ -isohybrid-gpt-basdat \ -o ../pvc-installer.iso \ - . &>/dev/null + . &>/dev/null || fail "Error creating ISO file." popd &>/dev/null echo "done." + echo -n "Moving generated ISO to '$(pwd)/pvc-installer.iso'... " - mv ${tempdir}/pvc-installer.iso . &>/dev/null + mv ${tempdir}/pvc-installer.iso . &>/dev/null || fail "Error moving ISO file." echo "done." } prepare_iso prepare_rootfs build_iso + echo -n "Cleaning up... " sudo rm -rf ${tempdir} &>/dev/null echo "done."