2023-09-01 15:41:55 -04:00
|
|
|
#!/usr/bin/env bash
|
2023-09-01 15:41:53 -04:00
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
# Generate a PVC autoinstaller ISO via live-build
|
2023-09-01 15:41:53 -04:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2023-09-01 15:41:54 -04:00
|
|
|
fail() {
|
|
|
|
echo "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
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."
|
2023-09-01 15:41:53 -04:00
|
|
|
|
2023-09-01 15:41:54 -04:00
|
|
|
isofilename="pvc-installer_$(date +%Y-%m-%d).iso"
|
2023-09-01 15:41:55 -04:00
|
|
|
deployusername="deploy"
|
2023-09-01 15:41:53 -04:00
|
|
|
|
|
|
|
show_help() {
|
2023-09-01 15:41:55 -04:00
|
|
|
echo -e "PVC install ISO generator"
|
2023-09-01 15:41:53 -04:00
|
|
|
echo
|
2023-09-01 15:41:56 -04:00
|
|
|
echo -e " Generates a mostly-automated installer ISO for a PVC node base system via lb."
|
2023-09-01 15:41:53 -04:00
|
|
|
echo
|
2023-09-01 15:41:56 -04:00
|
|
|
echo -e "Usage: $0 [-h] [-o <output_filename>] [-u username] [-a]"
|
2023-09-01 15:41:53 -04:00
|
|
|
echo
|
|
|
|
echo -e " -h: Display this help message."
|
|
|
|
echo -e " -o: Create the ISO as <output_filename> instead of the default."
|
2023-09-01 15:41:55 -04:00
|
|
|
echo -e " -u: Change 'deploy' user to a new username."
|
2023-09-01 15:41:56 -04:00
|
|
|
echo -e " -a: Preserve live-build artifacts."
|
|
|
|
echo -e " -k: Preserve live-build config."
|
2023-09-01 15:41:53 -04:00
|
|
|
}
|
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "${1}" in
|
|
|
|
-h|\?)
|
2023-09-01 15:41:53 -04:00
|
|
|
show_help
|
|
|
|
exit 0
|
|
|
|
;;
|
2023-09-01 15:41:56 -04:00
|
|
|
-o)
|
|
|
|
isofilename="${2}"
|
|
|
|
shift 2
|
2023-09-01 15:41:55 -04:00
|
|
|
;;
|
2023-09-01 15:41:56 -04:00
|
|
|
-u)
|
|
|
|
deployusername="${2}"
|
|
|
|
shift 2
|
2023-09-01 15:41:53 -04:00
|
|
|
;;
|
2023-09-01 15:41:56 -04:00
|
|
|
-a)
|
2023-09-01 15:41:56 -04:00
|
|
|
preserve_artifacts='y'
|
2023-09-01 15:41:56 -04:00
|
|
|
shift
|
2023-09-01 15:41:53 -04:00
|
|
|
;;
|
2023-09-01 15:41:56 -04:00
|
|
|
-k)
|
2023-09-01 15:41:56 -04:00
|
|
|
preserve_livebuild='y'
|
2023-09-01 15:41:56 -04:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid option: ${1}"
|
|
|
|
echo
|
|
|
|
show_help
|
|
|
|
exit 1
|
2023-09-01 15:41:55 -04:00
|
|
|
;;
|
2023-09-01 15:41:53 -04:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
mkdir -p artifacts/lb
|
2023-09-01 15:41:56 -04:00
|
|
|
pushd artifacts/lb &>/dev/null
|
2023-09-01 15:41:56 -04:00
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
echo "Pre-cleaning live-build environment..."
|
|
|
|
sudo lb clean
|
2023-09-01 15:41:57 -04:00
|
|
|
echo
|
2023-09-01 15:41:56 -04:00
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
echo "Initializing config..."
|
2023-09-01 15:41:56 -04:00
|
|
|
# Initialize the live-build config
|
2023-09-01 15:41:57 -04:00
|
|
|
lb config --distribution buster --architectures amd64 --archive-areas "main contrib non-free" --apt-recommends false || fail "Failed to initialize live-build config"
|
|
|
|
echo
|
2023-09-01 15:41:56 -04:00
|
|
|
|
2023-09-01 15:41:57 -04:00
|
|
|
# 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."
|
2023-09-01 15:41:56 -04:00
|
|
|
|
|
|
|
# Add root password hook
|
2023-09-01 15:41:57 -04:00
|
|
|
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"
|
2023-09-01 15:41:57 -04: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"
|
2023-09-01 15:41:57 -04:00
|
|
|
echo "done."
|
2023-09-01 15:41:56 -04:00
|
|
|
|
|
|
|
# Set root bashrc
|
2023-09-01 15:41:57 -04:00
|
|
|
echo -n "Copying root bashrc template... "
|
2023-09-01 15:41:56 -04:00
|
|
|
mkdir -p config/includes.chroot/root
|
2023-09-01 15:41:57 -04:00
|
|
|
cp ../../templates/root.bashrc config/includes.chroot/root/.bashrc || fail "Failed to copy critical template file"
|
|
|
|
echo "done."
|
2023-09-01 15:41:56 -04:00
|
|
|
|
|
|
|
# Set hostname and resolv.conf
|
2023-09-01 15:41:57 -04:00
|
|
|
echo -n "Copying networking templates... "
|
2023-09-01 15:41:56 -04:00
|
|
|
mkdir -p config/includes.chroot/etc
|
2023-09-01 15:41:57 -04:00
|
|
|
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."
|
2023-09-01 15:41:56 -04:00
|
|
|
|
2023-09-01 15:41:57 -04:00
|
|
|
# Set single vty and autologin
|
|
|
|
echo -n "Copying getty templates... "
|
2023-09-01 15:41:56 -04:00
|
|
|
mkdir -p config/includes.chroot/etc/systemd/
|
2023-09-01 15:41:57 -04:00
|
|
|
cp ../../templates/logind.conf config/includes.chroot/etc/systemd/logind.conf || fail "Failed to copy critical template file"
|
2023-09-01 15:41:56 -04:00
|
|
|
mkdir -p config/includes.chroot/etc/systemd/system/getty@.service.d
|
2023-09-01 15:41:57 -04:00
|
|
|
cp ../../templates/getty-override.conf config/includes.chroot/etc/systemd/system/getty@.service.d/override.conf || fail "Failed to copy critical template file"
|
2023-09-01 15:41:56 -04:00
|
|
|
mkdir -p config/includes.chroot/etc/systemd/system/serial-getty@.service.d
|
2023-09-01 15:41:57 -04:00
|
|
|
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."
|
2023-09-01 15:41:56 -04:00
|
|
|
|
|
|
|
# Install GRUB config, theme, and splash
|
2023-09-01 15:41:57 -04:00
|
|
|
echo -n "Copying GRUB templates... "
|
2023-09-01 15:41:56 -04:00
|
|
|
mkdir -p config/includes.chroot/boot/grub
|
2023-09-01 15:41:57 -04:00
|
|
|
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."
|
2023-09-01 15:41:56 -04:00
|
|
|
|
2023-09-01 15:41:58 -04:00
|
|
|
# Install module blacklist template
|
|
|
|
echo -n "Copying module blacklist template... "
|
|
|
|
mkdir -p config/includes.chroot/etc/modprobe.d
|
|
|
|
cp ../../templates/blacklist.conf config/includes.chroot/etc/modprobe.d/blacklist.conf || fail "Failed to copy critical template file"
|
|
|
|
echo "done."
|
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
# Install install.sh script
|
2023-09-01 15:41:57 -04:00
|
|
|
echo -n "Copying PVC node installer script template... "
|
|
|
|
cp ../../templates/install.sh config/includes.chroot/install.sh || fail "Failed to copy critical template file"
|
2023-09-01 15:41:56 -04:00
|
|
|
chmod +x config/includes.chroot/install.sh
|
2023-09-01 15:41:57 -04:00
|
|
|
echo "done."
|
2023-09-01 15:41:56 -04:00
|
|
|
|
|
|
|
# Customize install.sh script
|
2023-09-01 15:41:57 -04:00
|
|
|
echo -n "Customizing PVC node installer script... "
|
2023-09-01 15:41:56 -04:00
|
|
|
sed -i "s/XXDATEXX/$(date)/g" config/includes.chroot/install.sh
|
|
|
|
sed -i "s/XXDEPLOYUSERXX/${deployusername}/g" config/includes.chroot/install.sh
|
2023-09-01 15:41:57 -04:00
|
|
|
echo "done."
|
|
|
|
echo
|
2023-09-01 15:41:56 -04:00
|
|
|
|
|
|
|
# Build the live image
|
2023-09-01 15:41:56 -04:00
|
|
|
echo "Building live image..."
|
2023-09-01 15:41:57 -04:00
|
|
|
sudo lb build || fail "Failed to build live image"
|
|
|
|
echo
|
2023-09-01 15:41:56 -04:00
|
|
|
|
|
|
|
# Move the ISO image out
|
2023-09-01 15:41:57 -04:00
|
|
|
echo -n "Copying generated ISO to repository root... "
|
2023-09-01 15:41:56 -04:00
|
|
|
cp live-image-amd64.hybrid.iso ../../${isofilename}
|
2023-09-01 15:41:57 -04:00
|
|
|
echo "done."
|
2023-09-01 15:41:56 -04:00
|
|
|
|
|
|
|
# Clean up the artifacts
|
|
|
|
if [[ -z ${preserve_artifacts} ]]; then
|
2023-09-01 15:41:56 -04:00
|
|
|
echo "Cleaning live-build environment..."
|
2023-09-01 15:41:56 -04:00
|
|
|
sudo lb clean
|
|
|
|
fi
|
2023-09-01 15:41:53 -04:00
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
popd &>/dev/null
|
2023-09-01 15:41:53 -04:00
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
# Clean up the config
|
|
|
|
if [[ -z ${preserve_livebuild} ]]; then
|
2023-09-01 15:41:56 -04:00
|
|
|
echo -n "Removing artifacts... "
|
2023-09-01 15:41:56 -04:00
|
|
|
sudo rm -rf artifacts/lb
|
2023-09-01 15:41:56 -04:00
|
|
|
echo "done."
|
2023-09-01 15:41:56 -04:00
|
|
|
fi
|
2023-09-01 15:41:53 -04:00
|
|
|
|
2023-09-01 15:41:56 -04:00
|
|
|
echo
|
|
|
|
echo "Build completed. ISO file: ${isofilename}"
|