Commit 02eacaa4 authored by Luc Didry's avatar Luc Didry
Browse files

Add script

parent 3dfd64d8
#!/bin/bash
function usage {
cat <<EOF
Preseed Creator (c) Luc Didry 2017, WTFPL
./preseed_creator.sh [options]
Options:
-i <image.iso> ISO image to preseed. If not provided, the script will download and use the latest Debian amd64 netinst ISO image
-o <preseeded_image.iso> output preseeded ISO image. Default to preseed_creator/debian-netinst-latest-preseed.ISO
-p <preseed_file.cfg> preseed file. If not provided, the script will put "d-i debian-installer/locale string fr_BE" in the preseed.cfg file
-h print this help and exit
EOF
exit
}
INPUT=""
PRESEED=""
MYPWD=$(pwd)
OUTPUT=""
while getopts ":i:o:p:h" opt; do
case $opt in
i)
INPUT=$OPTARG
;;
o)
OUTPUT=$OPTARG
;;
p)
PRESEED=$OPTARG
;;
h)
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done
mkdir preseed_creator -p
cd preseed_creator
if [[ ! -z $PRESEED ]]
then
if [ ${PRESEED:0:1} != / ]
then
PRESEED="${MYPWD}/${PRESEED}"
fi
if [[ ! -e $PRESEED ]]
then
echo "$PRESEED does not exists. Aborting"
exit 1
fi
if [[ ! -r $PRESEED ]]
then
echo "$PRESEED is not readable. Aborting"
exit 1
fi
fi
if [[ ! -z $OUTPUT ]]
then
if [ ${OUTPUT:0:1} != / ]
then
OUTPUT="${MYPWD}/${OUTPUT}"
fi
else
OUTPUT="debian-netinst-latest-preseed.iso"
fi
if [[ -z $INPUT ]]
then
echo "No ISO image provided, will download the latest Debian amd64 netinst ISO image"
echo -ne 'Getting Debian GPG keys [> ](0%)\r'
for i in F41D30342F3546695F65C66942468F4009EA8AC3 DF9B9C49EAA9298432589D76DA87E80D6294BE9B 10460DAD76165AD81FBC0CE9988021A964E6EA7D
do
gpg --list-keys $i > /dev/null 2>&1
if [ $? != 0 ]
then
gpg --keyserver keyring.debian.org --recv-keys 0x$i > /dev/null 2>&1
fi
done
echo -ne 'Downloading latest Debian amd64 netinst ISO [===> ](10%)\r'
wget -q -O - https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/ | grep "netinst.iso" | grep -v "debian-mac" | sed -e 's@.*a href="\(.*\)".*@wget -q https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/\1 -O debian-netinst-latest.iso@' | bash
wget -q https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/SHA512SUMS https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/SHA512SUMS.sign
echo -ne 'Verifying GPG signature [======> ](20%)\r'
gpg --verify SHA512SUMS.sign SHA512SUMS > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Bad SHA512SUMS GPG signature. Aborting"
exit 1
fi
echo -ne 'Veryfying sha512sum [=========> ](30%)\r'
sed -i -e "/.*\(debian-mac\|xfce\).*/d" -e "s@debian-.*-amd64-netinst.iso@debian-netinst-latest.iso@" SHA512SUMS
sha512sum -c SHA512SUMS > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Bad ISO checksum. Aborting"
exit 1
fi
$INPUT="debian-netinst-latest.iso"
else
if [ ${INPUT:0:1} != / ]
then
INPUT="${MYPWD}/${INPUT}"
fi
if [[ ! -e $INPUT ]]
then
echo "$INPUT does not exists. Aborting"
exit 1
fi
if [[ ! -r $INPUT ]]
then
echo "$INPUT is not readable. Aborting"
exit 1
fi
fi
echo -ne 'Mounting ISO image [===========> ](40%)\r'
mkdir loopdir -p
mount -o loop $INPUT loopdir > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Error while mounting the ISO image. Aborting"
exit 1
fi
mkdir cd
echo -ne 'Extracting ISO image [==============> ](50%)\r'
rsync -a -H --exclude=TRANS.TBL loopdir/ cd
echo -ne 'Umounting ISO image [=================> ](60%)\r'
umount loopdir
echo -ne 'Hacking initrd [====================> ](70%)\r'
mkdir irmod -p
cd irmod
gzip -d < ../cd/install.amd/initrd.gz | cpio --extract --make-directories --no-absolute-filenames 2>/dev/null
if [ $? -ne 0 ]
then
echo "Error while getting ../cd/install.amd/initrd.gz content. Aborting"
exit 1
fi
echo "d-i debian-installer/locale string fr_BE" > preseed.cfg
find . | cpio -H newc --create 2>/dev/null | gzip -9 > ../cd/install.amd/initrd.gz 2>/dev/null
if [ $? -ne 0 ]
then
echo "Error while putting new content into ../cd/install.amd/initrd.gz. Aborting"
exit 1
fi
cd ../
rm -rf irmod/
echo -ne 'Fixing md5sums [=======================> ](80%)\r'
cd cd
md5sum `find -follow -type f 2>/dev/null` > md5sum.txt 2>/dev/null
if [ $? -ne 0 ]
then
echo "Error while fixing md5sums. Aborting"
exit 1
fi
cd ..
echo -ne 'Creating preseeded ISO image [==========================> ](90%)\r'
genisoimage -quiet -o $OUTPUT -r -J -no-emul-boot -boot-load-size 4 -boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat ./cd > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Error while creating the preseeded ISO image. Aborting"
exit 1
fi
echo -ne 'Preseeded ISO image created [==============================](100%)\r'
echo -e "\nYour preseeded ISO image is located at $OUTPUT"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment