Truly add preseed file to initrd…

Also extract initrd to a specific directory before compress it again.
This commit is contained in:
Jeremy Gardais 2018-12-28 08:17:13 +01:00
parent 1cfdbfacd0
commit 1e51cd1845
1 changed files with 23 additions and 9 deletions

View File

@ -15,6 +15,7 @@ DEBIAN_ISO_MINI_URL="http://ftp.nl.debian.org/debian/dists/${DEBIAN_VERSION_NAME
TEMP_DIR=$(mktemp -d -t new-preseed-debian-iso-XXXXXX.tmp) TEMP_DIR=$(mktemp -d -t new-preseed-debian-iso-XXXXXX.tmp)
TEMP_ISO_DIR="${TEMP_DIR}/extracted-iso" TEMP_ISO_DIR="${TEMP_DIR}/extracted-iso"
TEMP_INITRD_DIR="${TEMP_DIR}/initrd"
DEBIAN_DL_ISO_PATH="${TEMP_DIR}/debian.iso" DEBIAN_DL_ISO_PATH="${TEMP_DIR}/debian.iso"
DEBIAN_PRESEED_ISO_PATH="$(dirname ${TEMP_DIR})/preseed-debian-${DEBIAN_VERSION_NB}-amd64.iso" DEBIAN_PRESEED_ISO_PATH="$(dirname ${TEMP_DIR})/preseed-debian-${DEBIAN_VERSION_NB}-amd64.iso"
@ -85,28 +86,41 @@ command 7z x -o"${TEMP_ISO_DIR}" -- "${DEBIAN_DL_ISO_PATH}" > /dev/null
rm -rf -- "${DEBIAN_DL_ISO_PATH}" rm -rf -- "${DEBIAN_DL_ISO_PATH}"
# }}} # }}}
# Manage initrd.gz file {{{ # Manage initrd.gz file {{{
mkdir -- "${TEMP_INITRD_DIR}"
## Exclude initrd.gz files from xen and gtk directories ## Exclude initrd.gz files from xen and gtk directories
INITRD_GZ_PATH=$(find "${TEMP_ISO_DIR}" -type f \( -path '*xen*' -o -path '*gtk*' \) -prune -o -name "initrd.gz" -print -quit) INITRD_GZ_PATH=$(find "${TEMP_ISO_DIR}" -type f \( -path '*xen*' -o -path '*gtk*' \) -prune -o -name "initrd.gz" -print -quit)
## Uncompress initrd.gz ## Copy it to a directory
gunzip -- "${INITRD_GZ_PATH}" || exit 1 cp -- "${INITRD_GZ_PATH}" "${TEMP_INITRD_DIR}" || exit 2
## Add preseed file to initrd sleep 30
INITRD_PATH=$(find "${TEMP_ISO_DIR}" -type f \( -path '*xen*' -o -path '*gtk*' \) -prune -o -name "initrd" -print -quit)
echo "${PRESEED_FILE}" | cpio --quiet -H newc -o -A -F "${INITRD_PATH}" cd -- "${TEMP_INITRD_DIR}" > /dev/null || exit 2
## Uncompress initrd.gz and delete it
gunzip < initrd.gz | cpio --extract --quiet --make-directories --no-absolute-filenames >> /dev/null
rm -f -- initrd.gz
## Recompress to initrd.gz ## Add preseed file
gzip -- "${INITRD_PATH}" || exit 1 cp -- "${PRESEED_FILE}" preseed.cfg || exit 2
sleep 30
## Recompress to initrd.gz and move it back to the extracted files for ISO
find . -not -name initrd.gz | cpio --format=newc --create --quiet | gzip --best > initrd.gz
cp -- initrd.gz "${INITRD_GZ_PATH}" || exit 2
## Go back to previous directory and remove no longer useful files
cd - > /dev/null || exit 2
rm -rf -- "${TEMP_INITRD_DIR}"
## Fix permissions in install directory ## Fix permissions in install directory
chmod -w -R -- $(dirname -- "${INITRD_GZ_PATH}") chmod -w -R -- $(dirname -- "${INITRD_GZ_PATH}")
# }}} # }}}
# Generate new md5sum {{{ # Generate new md5sum {{{
cd -- "${TEMP_ISO_DIR}" || exit 2 cd -- "${TEMP_ISO_DIR}" > /dev/null || exit 2
## Exclude some unwanted files ## Exclude some unwanted files
find . -follow -type f -not \( -name "md5sum.txt" -o -name 'mkisofs' -o -name 'Bootable_NoEmulation.img' -o -path '*isolinux*' \) -exec md5sum {} \; > ./md5sum.txt find . -follow -type f -not \( -name "md5sum.txt" -o -name 'mkisofs' -o -name 'Bootable_NoEmulation.img' -o -path '*isolinux*' \) -exec md5sum {} \; > ./md5sum.txt
cd - || exit 2 cd - > /dev/null || exit 2
# }}} # }}}
# Generate new bootable iso {{{ # Generate new bootable iso {{{
xorriso -as mkisofs -o "${DEBIAN_PRESEED_ISO_PATH}" \ xorriso -as mkisofs -o "${DEBIAN_PRESEED_ISO_PATH}" \