Use a main temp directory

This commit is contained in:
Jeremy Gardais 2018-12-26 17:54:17 +01:00
parent 2f01ebdce8
commit 1cfdbfacd0
1 changed files with 11 additions and 11 deletions

View File

@ -13,10 +13,11 @@ DEBIAN_ISO_DVD_URL="https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/d
DEBIAN_ISO_NETINST_URL="https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-${DEBIAN_VERSION_NB}-amd64-netinst.iso" DEBIAN_ISO_NETINST_URL="https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-${DEBIAN_VERSION_NB}-amd64-netinst.iso"
DEBIAN_ISO_MINI_URL="http://ftp.nl.debian.org/debian/dists/${DEBIAN_VERSION_NAME}/main/installer-amd64/current/images/netboot/mini.iso" DEBIAN_ISO_MINI_URL="http://ftp.nl.debian.org/debian/dists/${DEBIAN_VERSION_NAME}/main/installer-amd64/current/images/netboot/mini.iso"
TEMP_DIR_ISO=$(mktemp -d -t debian-iso-XXXXXX.tmp) TEMP_DIR=$(mktemp -d -t new-preseed-debian-iso-XXXXXX.tmp)
TEMP_ISO_DIR="${TEMP_DIR}/extracted-iso"
DEBIAN_DL_ISO_PATH="${TEMP_DIR_ISO}/debian.iso" DEBIAN_DL_ISO_PATH="${TEMP_DIR}/debian.iso"
DEBIAN_PRESEED_ISO_PATH="$(dirname ${TEMP_DIR_ISO})/preseed-debian-${DEBIAN_VERSION_NB}-amd64.iso" DEBIAN_PRESEED_ISO_PATH="$(dirname ${TEMP_DIR})/preseed-debian-${DEBIAN_VERSION_NB}-amd64.iso"
# }}} # }}}
#USE_DEBIAN_ISO="${DEBIAN_ISO_DVD_URL}" #USE_DEBIAN_ISO="${DEBIAN_ISO_DVD_URL}"
@ -55,7 +56,7 @@ case $# in
printf '%b\n' "ERROR: The first argument should be the path to a directory." printf '%b\n' "ERROR: The first argument should be the path to a directory."
exit 1 exit 1
fi fi
TEMP_DIR_ISO=$(mktemp -d -t debian-iso-XXXXXX.tmp -p "${USER_TEMP_DIR}") TEMP_DIR=$(mktemp -d -t debian-iso-XXXXXX.tmp -p "${USER_TEMP_DIR}")
;; ;;
* ) * )
printf '%b\n' "Usage:" printf '%b\n' "Usage:"
@ -80,18 +81,18 @@ fi
# Download and extract ISO {{{ # Download and extract ISO {{{
wget -q "${USE_DEBIAN_ISO}" -O "${DEBIAN_DL_ISO_PATH}" wget -q "${USE_DEBIAN_ISO}" -O "${DEBIAN_DL_ISO_PATH}"
command 7z x -o"${TEMP_DIR_ISO}" -- "${DEBIAN_DL_ISO_PATH}" > /dev/null 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 {{{
## Exclude initrd.gz files from xen and gtk directories ## Exclude initrd.gz files from xen and gtk directories
INITRD_GZ_PATH=$(find "${TEMP_DIR_ISO}" -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 ## Uncompress initrd.gz
gunzip -- "${INITRD_GZ_PATH}" || exit 1 gunzip -- "${INITRD_GZ_PATH}" || exit 1
## Add preseed file to initrd ## Add preseed file to initrd
INITRD_PATH=$(find "${TEMP_DIR_ISO}" -type f \( -path '*xen*' -o -path '*gtk*' \) -prune -o -name "initrd" -print -quit) 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}" echo "${PRESEED_FILE}" | cpio --quiet -H newc -o -A -F "${INITRD_PATH}"
@ -102,7 +103,7 @@ gzip -- "${INITRD_PATH}" || exit 1
chmod -w -R -- $(dirname -- "${INITRD_GZ_PATH}") chmod -w -R -- $(dirname -- "${INITRD_GZ_PATH}")
# }}} # }}}
# Generate new md5sum {{{ # Generate new md5sum {{{
cd -- "${TEMP_DIR_ISO}" || exit 2 cd -- "${TEMP_ISO_DIR}" || 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 - || exit 2
@ -111,12 +112,11 @@ cd - || exit 2
xorriso -as mkisofs -o "${DEBIAN_PRESEED_ISO_PATH}" \ xorriso -as mkisofs -o "${DEBIAN_PRESEED_ISO_PATH}" \
-quiet -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \ -quiet -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot \ -c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot \
-boot-load-size 4 -boot-info-table "${TEMP_DIR_ISO}" -boot-load-size 4 -boot-info-table "${TEMP_ISO_DIR}"
# }}} # }}}
printf '%b\n' "The new ISO image is available: ${DEBIAN_PRESEED_ISO_PATH}" printf '%b\n' "The new ISO image is available: ${DEBIAN_PRESEED_ISO_PATH}"
# If extract image #rm -rf -- "${TEMP_ISO_DIR}"
#rm -rf -- "${TEMP_DIR_ISO}
exit 0 exit 0