pvc-installer/buildiso.sh

165 lines
5.9 KiB
Bash
Raw Normal View History

2021-04-13 11:38:46 -04:00
#!/usr/bin/env bash
# Generate a PVC autoinstaller ISO via live-build
# 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.
2019-06-17 22:09:31 -04:00
fail() {
echo "$@"
exit 1
}
which lb &>/dev/null || fail "This script requires live-build"
sudo -n true &>/dev/null || fail "The user running this script must have sudo privileges."
2019-06-17 13:26:18 -04:00
isofilename="pvc-installer_$(date +%Y-%m-%d).iso"
deployusername="deploy"
2019-06-14 13:54:00 -04:00
show_help() {
2020-08-16 21:29:18 -04:00
echo -e "PVC install ISO generator"
2019-06-14 13:54:00 -04:00
echo
echo -e " Generates a mostly-automated installer ISO for a PVC node base system via lb."
2019-06-14 13:54:00 -04:00
echo
echo -e "Usage: $0 [-h] [-o <output_filename>] [-u username] [-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 " -u: Change 'deploy' user to a new username."
echo -e " -a: Preserve live-build artifacts."
echo -e " -k: Preserve live-build config."
2019-06-14 13:54:00 -04:00
}
while [ $# -gt 0 ]; do
case "${1}" in
-h|\?)
2019-06-14 13:54:00 -04:00
show_help
exit 0
;;
-o)
isofilename="${2}"
shift 2
2020-08-16 21:29:18 -04:00
;;
-u)
deployusername="${2}"
shift 2
2019-06-14 13:54:00 -04:00
;;
-a)
preserve_artifacts='y'
shift
2019-06-14 18:19:23 -04:00
;;
-k)
preserve_livebuild='y'
shift
;;
*)
echo "Invalid option: ${1}"
echo
show_help
exit 1
;;
2019-06-14 13:54:00 -04:00
esac
done
mkdir -p artifacts/lb
2021-12-04 02:47:55 -05:00
pushd artifacts/lb &>/dev/null
2021-12-04 02:47:55 -05:00
echo "Pre-cleaning live-build environment..."
sudo lb clean
echo
2021-12-04 02:47:55 -05:00
echo "Initializing config..."
# Initialize the live-build config
lb config --distribution buster --architectures amd64 --archive-areas "main contrib non-free" --apt-recommends false || fail "Failed to initialize live-build config"
echo
# Configure the package lists
echo -n "Copying package lists... "
cp ../../templates/installer.list.chroot config/package-lists/installer.list.chroot || fail "Failed to copy critical template file"
cp ../../templates/firmware.list.chroot config/package-lists/firmware.list.chroot || fail "Failed to copy critical template file"
echo "done."
# Add root password hook
echo -n "Copying live-boot templates... "
mkdir -p config/includes.chroot/lib/live/boot/
cp ../../templates/9990-initramfs-tools.sh config/includes.chroot/lib/live/boot/9990-initramfs-tools.sh || fail "Failed to copy critical template file"
chmod +x config/includes.chroot/lib/live/boot/9990-initramfs-tools.sh || fail "Failed to copy critical template file"
2021-12-12 18:36:10 -05:00
mkdir -p config/includes.chroot/lib/live/config/
cp ../../templates/2000-remove-root-pw.sh config/includes.chroot/lib/live/config/2000-remove-root-pw.sh || fail "Failed to copy critical template file"
chmod +x config/includes.chroot/lib/live/config/2000-remove-root-pw.sh || fail "Failed to copy critical template file"
echo "done."
# Set root bashrc
echo -n "Copying root bashrc template... "
mkdir -p config/includes.chroot/root
cp ../../templates/root.bashrc config/includes.chroot/root/.bashrc || fail "Failed to copy critical template file"
echo "done."
# Set hostname and resolv.conf
echo -n "Copying networking templates... "
mkdir -p config/includes.chroot/etc
cp ../../templates/hostname config/includes.chroot/etc/hostname || fail "Failed to copy critical template file"
cp ../../templates/resolv.conf config/includes.chroot/etc/resolv.conf || fail "Failed to copy critical template file"
echo "done."
# Set single vty and autologin
echo -n "Copying getty templates... "
mkdir -p config/includes.chroot/etc/systemd/
cp ../../templates/logind.conf config/includes.chroot/etc/systemd/logind.conf || fail "Failed to copy critical template file"
mkdir -p config/includes.chroot/etc/systemd/system/getty@.service.d
cp ../../templates/getty-override.conf config/includes.chroot/etc/systemd/system/getty@.service.d/override.conf || fail "Failed to copy critical template file"
mkdir -p config/includes.chroot/etc/systemd/system/serial-getty@.service.d
cp ../../templates/serial-getty-override.conf config/includes.chroot/etc/systemd/system/serial-getty@.service.d/override.conf || fail "Failed to copy critical template file"
echo "done."
# Install GRUB config, theme, and splash
echo -n "Copying GRUB templates... "
mkdir -p config/includes.chroot/boot/grub
cp ../../templates/grub.cfg config/includes.chroot/boot/grub/grub.cfg || fail "Failed to copy critical template file"
cp ../../templates/theme.txt config/includes.chroot/boot/grub/theme.txt || fail "Failed to copy critical template file"
cp ../../templates/splash.png config/includes.chroot/splash.png || fail "Failed to copy critical template file"
echo "done."
# Install install.sh script
echo -n "Copying PVC node installer script template... "
cp ../../templates/install.sh config/includes.chroot/install.sh || fail "Failed to copy critical template file"
chmod +x config/includes.chroot/install.sh
echo "done."
# Customize install.sh script
echo -n "Customizing PVC node installer script... "
sed -i "s/XXDATEXX/$(date)/g" config/includes.chroot/install.sh
sed -i "s/XXDEPLOYUSERXX/${deployusername}/g" config/includes.chroot/install.sh
echo "done."
echo
# Build the live image
2021-12-04 02:47:55 -05:00
echo "Building live image..."
sudo lb build || fail "Failed to build live image"
echo
# Move the ISO image out
echo -n "Copying generated ISO to repository root... "
cp live-image-amd64.hybrid.iso ../../${isofilename}
echo "done."
# Clean up the artifacts
if [[ -z ${preserve_artifacts} ]]; then
2021-12-04 02:47:55 -05:00
echo "Cleaning live-build environment..."
sudo lb clean
fi
2021-12-04 02:47:55 -05:00
popd &>/dev/null
# Clean up the config
if [[ -z ${preserve_livebuild} ]]; then
2021-12-04 02:47:55 -05:00
echo -n "Removing artifacts... "
sudo rm -rf artifacts/lb
2021-12-04 02:47:55 -05:00
echo "done."
fi
2019-06-13 18:32:22 -04:00
2021-12-04 02:47:55 -05:00
echo
echo "Build completed. ISO file: ${isofilename}"