Cleanup a bit more

This commit is contained in:
Joshua Boniface 2023-09-01 15:41:53 -04:00
parent 6c389f7413
commit 9fd1359bc9
1 changed files with 21 additions and 23 deletions

View File

@ -67,18 +67,21 @@ fail() {
prepare_iso() { prepare_iso() {
echo -n "Creating temporary directories... " echo -n "Creating temporary directories... "
if [[ ! -d artifacts ]]; then
mkdir artifacts &>/dev/null || fail "Error creating artifacts directory."
fi
mkdir ${tempdir}/rootfs/ ${tempdir}/installer/ &>/dev/null || fail "Error creating temporary directories." mkdir ${tempdir}/rootfs/ ${tempdir}/installer/ &>/dev/null || fail "Error creating temporary directories."
echo "done." echo "done."
if [[ ! -f ${srcliveisofile} ]]; then if [[ ! -f ${srcliveisofile} ]]; then
echo -n "Downloading Debian Live ISO... " echo -n "Downloading Debian Live ISO... "
wget -O ${srcliveisofile} ${srcliveisourl} &>/dev/null || fail "Error downloading source ISO." wget -O artifacts/${srcliveisofile} ${srcliveisourl} &>/dev/null || fail "Error downloading source ISO."
echo "done." echo "done."
fi fi
echo -n "Extracting Debian Live ISO files... " echo -n "Extracting Debian Live ISO files... "
iso_tempdir=$( mktemp -d ) iso_tempdir=$( mktemp -d )
sudo mount ${srcliveisofile} ${iso_tempdir} &>/dev/null || fail "Error mounting Live ISO file." sudo mount artifacts/${srcliveisofile} ${iso_tempdir} &>/dev/null || fail "Error mounting Live ISO file."
sudo rsync -au --exclude live/filesystem.squashfs ${iso_tempdir}/ ${tempdir}/installer/ &>/dev/null || fail "Error extracting Live ISO files." sudo rsync -au --exclude live/filesystem.squashfs ${iso_tempdir}/ ${tempdir}/installer/ &>/dev/null || fail "Error extracting Live ISO files."
sudo umount ${iso_tempdir} &>/dev/null || fail "Error unmounting Live ISO file." sudo umount ${iso_tempdir} &>/dev/null || fail "Error unmounting Live ISO file."
rmdir ${iso_tempdir} &>/dev/null rmdir ${iso_tempdir} &>/dev/null
@ -88,22 +91,22 @@ prepare_iso() {
prepare_rootfs() { prepare_rootfs() {
echo -n "Preparing Debian live installation via debootstrap... " echo -n "Preparing Debian live installation via debootstrap... "
SQUASHFS_PKGLIST="mdadm,lvm2,parted,gdisk,debootstrap,grub-pc,linux-image-amd64,sipcalc,live-boot,dosfstools" SQUASHFS_PKGLIST="mdadm,lvm2,parted,gdisk,debootstrap,grub-pc,linux-image-amd64,sipcalc,live-boot,dosfstools"
test -d debootstrap/ || \ if [[ ! -d artifacts/debootstrap ]]; then
sudo /usr/sbin/debootstrap \ sudo /usr/sbin/debootstrap \
--include=${SQUASHFS_PKGLIST} \ --include=${SQUASHFS_PKGLIST} \
buster \ buster \
debootstrap/ \ artifacts/debootstrap/ \
http://localhost:3142/ftp.ca.debian.org/debian &>/dev/null || fail "Error performing debootstrap." 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 chroot artifacts/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." fi
sudo rsync -au artifacts/debootstrap/ ${tempdir}/rootfs/ &>/dev/null || fail "Error copying debootstrap to tempdir."
echo "done." echo "done."
echo -n "Configuring Debian live installation... " echo -n "Configuring Debian live installation... "
sudo cp -a debootstrap/boot/vmlinuz* ${tempdir}/installer/live/vmlinuz &>/dev/null || fail "Error copying kernel." sudo cp -a artifacts/debootstrap/boot/vmlinuz* ${tempdir}/installer/live/vmlinuz &>/dev/null || fail "Error copying kernel."
sudo cp -a debootstrap/boot/initrd.img* ${tempdir}/installer/live/initrd.img &>/dev/null || fail "Error copying initrd." sudo cp -a artifacts/debootstrap/boot/initrd.img* ${tempdir}/installer/live/initrd.img &>/dev/null || fail "Error copying initrd."
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 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 \ sudo sed -i 's|/sbin/agetty|/sbin/agetty --autologin root|g' \
's|/sbin/agetty|/sbin/agetty --autologin root|g' \
${tempdir}/rootfs/etc/systemd/system/getty@tty1.service &>/dev/null || fail "Error setting autologin in getty override." ${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 ${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 tee -a ${tempdir}/rootfs/root/.bashrc <<<"/install.sh" &>/dev/null || fail "Error setting bashrc."
@ -112,10 +115,10 @@ prepare_rootfs() {
echo "done." echo "done."
echo -n "Generating squashfs image of live installation... " echo -n "Generating squashfs image of live installation... "
if [[ ! -f filesystem.squashfs ]]; then if [[ ! -f artifacts/filesystem.squashfs ]]; then
sudo nice mksquashfs ${tempdir}/rootfs/ filesystem.squashfs -e boot &>/dev/null || fail "Error generating squashfs." sudo nice mksquashfs ${tempdir}/rootfs/ artifacts/filesystem.squashfs -e boot &>/dev/null || fail "Error generating squashfs."
fi fi
sudo cp filesystem.squashfs ${tempdir}/installer/live/filesystem.squashfs &>/dev/null || fail "Error copying squashfs to tempdir." sudo cp artifacts/filesystem.squashfs ${tempdir}/installer/live/filesystem.squashfs &>/dev/null || fail "Error copying squashfs to tempdir."
echo "done." echo "done."
} }
@ -145,18 +148,13 @@ build_iso() {
echo "done." echo "done."
echo -n "Moving generated ISO to './${isofilename}'... " echo -n "Moving generated ISO to './${isofilename}'... "
mv ${tempdir}/${isofilename} ../${isofilename} &>/dev/null || fail "Error moving ISO file." mv ${tempdir}/${isofilename} ${isofilename} &>/dev/null || fail "Error moving ISO file."
echo "done." echo "done."
} }
[[ -d artifacts ]] || mkdir artifacts &>/dev/null | fail "Error creating artifacts directory."
pushd artifacts &>/dev/null
prepare_iso prepare_iso
prepare_rootfs prepare_rootfs
build_iso build_iso
cleanup cleanup
popd &>/dev/null
echo "PVC Live Installer ISO generation complete." echo "PVC Live Installer ISO generation complete."