debian-unattended/unattended.sh

40 lines
1.5 KiB
Bash
Raw Normal View History

2022-08-15 02:31:03 +02:00
#!/usr/bin/env bash
# Get password from user prompt and set it in preseed
read -sp "Enter the root password: " ROOT_PASSWORD
cp -f template.cfg preseed.cfg
sed -i "s/ROOT_PASSWORD/${ROOT_PASSWORD}/" preseed.cfg
2024-03-19 11:16:31 +01:00
# Get the file name
2023-01-28 15:35:35 +01:00
ISONAME=$(ls | grep "netinst.iso" | sort | tail -n1)
2024-03-19 11:16:31 +01:00
# Remove an already existing unattended iso of this same version, if existing
2023-01-28 15:45:39 +01:00
rm -f $(echo ${ISONAME} | sed 's/netinst/unattended/')
2024-03-19 11:16:31 +01:00
# Extract iso files
2023-01-28 15:35:35 +01:00
xorriso -osirrox on -indev ${ISONAME} -extract / isofiles
2024-03-19 11:16:31 +01:00
# Remove the grub menu
2022-08-15 02:31:03 +02:00
sudo sed -i '/vesamenu.c32/d' isofiles/isolinux/isolinux.cfg
2024-03-19 11:16:31 +01:00
# Fix the grub menu
2022-08-15 02:34:06 +02:00
if [[ $(grep timeout_style isofiles/boot/grub/grub.cfg) == "" ]]; then
sudo sed -i 's/insmod play/set timeout_style=hidden\nset timeout=0\nset default=1\n\ninsmod play/' isofiles/boot/grub/grub.cfg;
fi
2022-08-15 02:31:03 +02:00
2024-03-19 11:16:31 +01:00
# Extract the initrd image, put the preseed file in int, and re-compress
2022-08-15 02:31:03 +02:00
chmod +w -R isofiles/install.amd/
gunzip isofiles/install.amd/initrd.gz
echo preseed.cfg | cpio -H newc -o -A -F isofiles/install.amd/initrd
gzip isofiles/install.amd/initrd
chmod -w -R isofiles/install.amd/
2024-03-19 11:16:31 +01:00
# Recreate the md5sum check file
2022-08-15 02:31:03 +02:00
cd isofiles/
chmod a+w md5sum.txt
md5sum $(find -follow -type f) > md5sum.txt
chmod a-w md5sum.txt
cd ..
2024-03-19 11:16:31 +01:00
# Repackage all the iso files
2022-08-15 02:31:03 +02:00
chmod a+w isofiles/isolinux/isolinux.bin
docker run --interactive --tty --rm --volume $(pwd):/root/unattended debian:buster /root/unattended/docker.sh
# Remove the extracted (temporary) files and the preseed with the plaintext password
sudo rm -rf isofiles preseed.cfg