2019-06-13 16:18:24 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Generate a PVC autoinstaller ISO
|
|
|
|
|
|
|
|
# This ISO makes a number of assumptions about the system and asks
|
|
|
|
# minimal questions in order to streamline the install process versus
|
|
|
|
# using a standard Debian intaller ISO. The end system is suitable
|
|
|
|
# for immediate bootstrapping with the PVC Ansible roles.
|
|
|
|
|
|
|
|
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."
|
|
|
|
|
2019-06-14 13:54:00 -04:00
|
|
|
isofilename="pvc-installer.iso"
|
|
|
|
srcliveisourl="https://cdimage.debian.org/mirror/cdimage/buster_di_rc1-live/amd64/iso-hybrid/debian-live-buster-DI-rc1-amd64-standard.iso"
|
|
|
|
|
|
|
|
show_help() {
|
|
|
|
echo -e "PVC install ISO generator"
|
|
|
|
echo
|
|
|
|
echo -e " Generates a mostly-automated installer ISO for a PVC node base system. The ISO"
|
|
|
|
echo -e " boots, then runs 'install.sh' to perform the installation to a target server."
|
|
|
|
echo -e " This script prompts for a few questions on startup to configure the system, then"
|
|
|
|
echo -e " performs the remaining installation to PVC node specifications unattended,"
|
|
|
|
echo -e " including configuring networking on the selected interface, wiping the selected"
|
|
|
|
echo -e " disk, partitioning, installing the base OS, and performing some initial"
|
|
|
|
echo -e " configuration to allow the PVC Ansible role to take over after completion."
|
|
|
|
echo
|
2019-06-15 14:27:19 -04:00
|
|
|
echo -e "Usage: $0 [-h] [-o <output_filename>] [-s <liveiso_source_url>] [-a]"
|
2019-06-14 13:54:00 -04:00
|
|
|
echo
|
|
|
|
echo -e " -h: Display this help message."
|
|
|
|
echo -e " -o: Create the ISO as <output_filename> instead of the default."
|
|
|
|
echo -e " -s: Obtain the source Debian Live ISO from <liveiso_source_url> instead of"
|
|
|
|
echo -e " the default."
|
2019-06-15 14:27:19 -04:00
|
|
|
echo -e " -a: Use cached squashfs artifact during rebuild (cached ISO and debootstrap"
|
|
|
|
echo -e " artifacts are always used)."
|
2019-06-14 13:54:00 -04:00
|
|
|
}
|
|
|
|
|
2019-06-15 14:27:19 -04:00
|
|
|
while getopts "h?o:s:a" opt; do
|
2019-06-14 13:54:00 -04:00
|
|
|
case "$opt" in
|
|
|
|
h|\?)
|
|
|
|
show_help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
o)
|
|
|
|
isofilename=$OPTARG
|
|
|
|
;;
|
|
|
|
s)
|
|
|
|
srcliveisourl=$OPTARG
|
|
|
|
;;
|
2019-06-15 14:27:19 -04:00
|
|
|
a)
|
|
|
|
usecachedsquashfs='y'
|
2019-06-14 18:19:23 -04:00
|
|
|
;;
|
2019-06-14 13:54:00 -04:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
srcliveisofile="$( basename ${srcliveisourl} )"
|
|
|
|
|
2019-06-13 16:18:24 -04:00
|
|
|
tempdir=$( mktemp -d )
|
|
|
|
|
2019-06-14 11:27:45 -04:00
|
|
|
cleanup() {
|
|
|
|
echo -n "Cleaning up... "
|
|
|
|
sudo rm -rf ${tempdir} &>/dev/null
|
|
|
|
echo "done."
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
fail() {
|
|
|
|
echo $@
|
|
|
|
cleanup
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2019-06-13 16:18:24 -04:00
|
|
|
prepare_iso() {
|
2019-06-14 13:08:43 -04:00
|
|
|
echo -n "Creating temporary directories... "
|
2019-06-14 14:31:14 -04:00
|
|
|
if [[ ! -d artifacts ]]; then
|
|
|
|
mkdir artifacts &>/dev/null || fail "Error creating artifacts directory."
|
|
|
|
fi
|
2019-06-14 13:54:00 -04:00
|
|
|
mkdir ${tempdir}/rootfs/ ${tempdir}/installer/ &>/dev/null || fail "Error creating temporary directories."
|
2019-06-13 16:18:24 -04:00
|
|
|
echo "done."
|
|
|
|
|
2019-06-14 15:02:03 -04:00
|
|
|
if [[ ! -f artifacts/${srcliveisofile} ]]; then
|
2019-06-14 13:54:00 -04:00
|
|
|
echo -n "Downloading Debian Live ISO... "
|
2019-06-14 14:31:14 -04:00
|
|
|
wget -O artifacts/${srcliveisofile} ${srcliveisourl} &>/dev/null || fail "Error downloading source ISO."
|
2019-06-14 13:08:43 -04:00
|
|
|
echo "done."
|
|
|
|
fi
|
|
|
|
|
2019-06-14 13:54:00 -04:00
|
|
|
echo -n "Extracting Debian Live ISO files... "
|
2019-06-13 16:18:24 -04:00
|
|
|
iso_tempdir=$( mktemp -d )
|
2019-06-14 14:31:14 -04:00
|
|
|
sudo mount artifacts/${srcliveisofile} ${iso_tempdir} &>/dev/null || fail "Error mounting Live ISO file."
|
2019-06-14 13:54:00 -04:00
|
|
|
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."
|
2019-06-13 16:18:24 -04:00
|
|
|
rmdir ${iso_tempdir} &>/dev/null
|
|
|
|
echo "done."
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare_rootfs() {
|
|
|
|
echo -n "Preparing Debian live installation via debootstrap... "
|
2019-06-15 14:59:19 -04:00
|
|
|
SQUASHFS_PKGLIST="mdadm,lvm2,parted,gdisk,debootstrap,grub-pc,grub-efi-amd64,linux-image-amd64,sipcalc,live-boot,dosfstools"
|
2019-06-14 14:31:14 -04:00
|
|
|
if [[ ! -d artifacts/debootstrap ]]; then
|
|
|
|
sudo /usr/sbin/debootstrap \
|
|
|
|
--include=${SQUASHFS_PKGLIST} \
|
|
|
|
buster \
|
|
|
|
artifacts/debootstrap/ \
|
2019-06-15 14:59:19 -04:00
|
|
|
http://localhost:3142/ftp.ca.debian.org/debian &>debootstrap.log || fail "Error performing debootstrap."
|
2019-06-14 14:31:14 -04:00
|
|
|
sudo chroot artifacts/debootstrap/ apt clean &>/dev/null || fail "Error cleaning apt cache in debootstrap."
|
|
|
|
fi
|
|
|
|
sudo rsync -au artifacts/debootstrap/ ${tempdir}/rootfs/ &>/dev/null || fail "Error copying debootstrap to tempdir."
|
2019-06-13 16:18:24 -04:00
|
|
|
echo "done."
|
|
|
|
|
|
|
|
echo -n "Configuring Debian live installation... "
|
2019-06-14 14:31:14 -04:00
|
|
|
sudo cp -a artifacts/debootstrap/boot/vmlinuz* ${tempdir}/installer/live/vmlinuz &>/dev/null || fail "Error copying kernel."
|
|
|
|
sudo cp -a artifacts/debootstrap/boot/initrd.img* ${tempdir}/installer/live/initrd.img &>/dev/null || fail "Error copying initrd."
|
2019-06-13 18:32:22 -04:00
|
|
|
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."
|
2019-06-14 14:31:14 -04:00
|
|
|
sudo sed -i 's|/sbin/agetty|/sbin/agetty --autologin root|g' \
|
2019-06-13 18:32:22 -04:00
|
|
|
${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."
|
2019-06-13 16:18:24 -04:00
|
|
|
echo "done."
|
|
|
|
|
|
|
|
echo -n "Generating squashfs image of live installation... "
|
2019-06-15 14:27:19 -04:00
|
|
|
if [[ ! -f artifacts/filesystem.squashfs && -z ${usecachedsquashfs} ]]; then
|
2019-06-14 14:31:14 -04:00
|
|
|
sudo nice mksquashfs ${tempdir}/rootfs/ artifacts/filesystem.squashfs -e boot &>/dev/null || fail "Error generating squashfs."
|
2019-06-14 11:27:45 -04:00
|
|
|
fi
|
2019-06-14 14:31:14 -04:00
|
|
|
sudo cp artifacts/filesystem.squashfs ${tempdir}/installer/live/filesystem.squashfs &>/dev/null || fail "Error copying squashfs to tempdir."
|
2019-06-13 16:18:24 -04:00
|
|
|
echo "done."
|
|
|
|
}
|
|
|
|
|
|
|
|
build_iso() {
|
2019-06-14 11:27:45 -04:00
|
|
|
echo -n "Copying live boot configurations... "
|
|
|
|
sudo cp -a grub.cfg ${tempdir}/installer/boot/grub/grub.cfg &>/dev/null || fail "Error copying grub.cfg file."
|
2019-06-15 17:24:14 -04:00
|
|
|
sudo cp -a theme.txt ${tempdir}/installer/boot/grub/theme.txt &>/dev/null || fail "Error copying theme.txt file."
|
2019-06-14 13:01:22 -04:00
|
|
|
sudo cp -a isolinux.cfg ${tempdir}/installer/isolinux/isolinux.cfg &>/dev/null || fail "Error copying isolinux.cfg file."
|
2019-06-15 17:24:14 -04:00
|
|
|
sudo cp -a splash.png ${tempdir}/installer/splash.png &>/dev/null || fail "Error copying splash.png file."
|
2019-06-14 11:27:45 -04:00
|
|
|
echo "done."
|
|
|
|
|
2019-06-13 16:18:24 -04:00
|
|
|
echo -n "Creating LiveCD ISO... "
|
2019-06-13 18:32:22 -04:00
|
|
|
pushd ${tempdir}/installer &>/dev/null
|
2019-06-13 16:18:24 -04:00
|
|
|
xorriso -as mkisofs \
|
|
|
|
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
|
|
|
|
-c isolinux/boot.cat \
|
|
|
|
-b isolinux/isolinux.bin \
|
|
|
|
-no-emul-boot \
|
|
|
|
-boot-load-size 4 \
|
|
|
|
-boot-info-table \
|
|
|
|
-eltorito-alt-boot \
|
|
|
|
-e boot/grub/efi.img \
|
|
|
|
-no-emul-boot \
|
|
|
|
-isohybrid-gpt-basdat \
|
2019-06-14 13:34:15 -04:00
|
|
|
-o ../${isofilename} \
|
2019-06-13 18:32:22 -04:00
|
|
|
. &>/dev/null || fail "Error creating ISO file."
|
2019-06-13 16:18:24 -04:00
|
|
|
popd &>/dev/null
|
|
|
|
echo "done."
|
2019-06-13 18:32:22 -04:00
|
|
|
|
2019-06-14 13:34:15 -04:00
|
|
|
echo -n "Moving generated ISO to './${isofilename}'... "
|
2019-06-14 14:31:14 -04:00
|
|
|
mv ${tempdir}/${isofilename} ${isofilename} &>/dev/null || fail "Error moving ISO file."
|
2019-06-13 16:18:24 -04:00
|
|
|
echo "done."
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare_iso
|
|
|
|
prepare_rootfs
|
|
|
|
build_iso
|
2019-06-14 11:27:45 -04:00
|
|
|
cleanup
|
2019-06-13 18:32:22 -04:00
|
|
|
|
2019-06-13 16:18:24 -04:00
|
|
|
echo "PVC Live Installer ISO generation complete."
|