Last active
June 8, 2019 11:34
-
-
Save debxp/a10f23116c7938778da7f3c8872b688c to your computer and use it in GitHub Desktop.
Append preseed.cfg to Debian installer iso and generates a new iso.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Usage: | |
# sudo ediso.sh patho_to/isofile.iso path_to/new_isofile.iso path_to/preseed_file | |
# | |
# Requires: | |
# - bsdtar | |
# - genisoimage | |
# - syslinux-utils | |
# Check if user is root... | |
if [[ $EUID -ne 0 ]]; then | |
echo -e "Use 'sudo' to run this script!\n" 1>&2 | |
exit 1 | |
fi | |
# Check if requirements are installed... | |
if [[ "$(command -v bsdtar)" == "" ]]; then | |
echo "'bsdtar' not installed!" | |
exit 1 | |
fi | |
if [[ "$(command -v genisoimage)" == "" ]]; then | |
echo "'genisoimage' not installed!" | |
exit 1 | |
fi | |
if [[ "$(command -v isohybrid)" == "" ]]; then | |
echo "'syslinux-utils' not installed!" | |
exit 1 | |
fi | |
# Default extraction path... | |
tmp_dir="tmpiso" | |
# Extract original iso to temp dir... | |
echo -e "\n-- Extracting ISO to $tmp_dir..." | |
mkdir $tmp_dir | |
bsdtar -C "$tmp_dir/" -xf $1 | |
# Detect iso archtecture - TODO: improve this! | |
[ -d "$tmp_dir/install.amd" ] && arch="amd" | |
[ -d "$tmp_dir/install.386" ] && arch="386" | |
echo "-- Detected achtecture: $arch" | |
# Unzip initrd.gz... | |
chmod -R +w "$tmp_dir/install.$arch" | |
echo "-- Extracting $tmp_dir/install.$arch/initrd.gz..." | |
gunzip "$tmp_dir/install.$arch/initrd.gz" | |
# Append preseed_file to initrd... | |
echo -e "-- Appending $3 to initrd... \c" | |
echo $3 | cpio -H newc -o -A -F "$tmp_dir/install.$arch/initrd" | |
# Zip initrd... | |
echo "-- Compressing initrd..." | |
gzip "$tmp_dir/install.$arch/initrd" | |
chmod -R -w "$tmp_dir/install.$arch" | |
# Fix md5sum.txt... | |
echo "-- Fixing md5sum.txt..." | |
cd $tmp_dir | |
md5sum $(find -follow -type f 2>/dev/null) > md5sum.txt | |
cd .. | |
# Generate new iso file... | |
echo -e "-- Generating iso file $2..." | |
rm $2 &> /dev/null | |
genisoimage -quiet -r -J -b isolinux/isolinux.bin \ | |
-c isolinux/boot.cat -no-emul-boot \ | |
-boot-load-size 4 -boot-info-table \ | |
-o $2 $tmp_dir | |
real_usr="$(logname)" | |
chown $real_usr:$real_usr $2 | |
# Make iso bootable... | |
echo -e "-- Making $2 bootable..." | |
isohybrid $2 | |
# Cleaning... | |
rm -fr $tmp_dir | |
echo -e "\nDone!\n" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment