From 725936597f65adb12e3633440c498eb7da6e9e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Thu, 3 Jan 2019 14:19:59 +0100 Subject: [PATCH] Fix user temp dir with mktemp --- make.iso.preseed.sh | 75 +++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/make.iso.preseed.sh b/make.iso.preseed.sh index 43a419c..b8881d9 100755 --- a/make.iso.preseed.sh +++ b/make.iso.preseed.sh @@ -5,6 +5,44 @@ # mount require root permissions, so i choose to extract the iso. # }}} +# Test args {{{ +case $# in + 1 ) + PRESEED_FILE="${1}" + TEMP_DIR=$(mktemp --directory -t -- new-preseed-debian-iso-XXXXXX.tmp) + ;; + 2 ) + PRESEED_FILE="${1}" + USER_TEMP_DIR="${2}" + ## Check user temp dir argument + if [ ! -d "${USER_TEMP_DIR}" ]; then + printf '%b\n' "ERROR : The second argument should be the path to a directory." + exit 1 + fi + TEMP_DIR=$(mktemp --directory --tmpdir="${USER_TEMP_DIR}" -- new-preseed-debian-iso-XXXXXX.tmp) + ;; + * ) + printf '%b\n' "Usage :" + printf '%b\n' "$(basename ${0}) PRESEED_FILE_PATH [TEMP_DIR]" + printf '%b\n' "-------" + printf '%b\n' "PRESEED_FILE_PATH : Required" + printf '%b\n' "Should be the absolut path to the preseed file you want to add to the ISO." + printf '%b\n' "-------" + printf '%b\n' "TEMP_DIR : Optionnal" + printf '%b\n' "If you want to store temporary files and final ISO in a specific directory." + printf '%b\n' "Note : This script require ISO size × 2 (eg for DVD. 3.4GB × 2)." + printf '%b\n' "Otherwise \$TMPDIR will be used." + exit 1 + ;; +esac + +## Check preseed argument +if [ ! -f "${PRESEED_FILE}" ]; then + printf '%b\n' "ERROR : The first argument should be the path to preseed file to add." + exit 1 +fi +# }}} + # Vars {{{ DEBIAN_VERSION_NAME="stretch" DEBIAN_VERSION_NB="9.6.0" @@ -13,7 +51,6 @@ 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_MINI_URL="http://ftp.nl.debian.org/debian/dists/${DEBIAN_VERSION_NAME}/main/installer-amd64/current/images/netboot/mini.iso" -TEMP_DIR=$(mktemp -d -t new-preseed-debian-iso-XXXXXX.tmp) TEMP_ISO_DIR="${TEMP_DIR}/extracted-iso" TEMP_INITRD_DIR="${TEMP_DIR}/initrd" @@ -44,42 +81,6 @@ if [ ! -f /usr/lib/ISOLINUX/isohdpfx.bin ]; then fi # }}} -# Test vars {{{ -case $# in - 1 ) - PRESEED_FILE="${1}" - ;; - 2 ) - PRESEED_FILE="${1}" - USER_TEMP_DIR="${2}" - ## Check user temp dir argument - if [ ! -d "${USER_TEMP_DIR}" ]; then - printf '%b\n' "ERROR : The first argument should be the path to a directory." - exit 1 - fi - TEMP_DIR=$(mktemp -d -t debian-iso-XXXXXX.tmp -p "${USER_TEMP_DIR}") - ;; - * ) - printf '%b\n' "Usage :" - printf '%b\n' "$(basename ${0}) PRESEED_FILE_PATH [TEMP_DIR]" - printf '%b\n' "-------" - printf '%b\n' "PRESEED_FILE_PATH : Required" - printf '%b\n' "Should be the absolut path to the preseed file you want to add to the ISO." - printf '%b\n' "-------" - printf '%b\n' "TEMP_DIR : Optionnal" - printf '%b\n' "If you want to store temporary files and final ISO in a specific directory." - printf '%b\n' "Note : This script require ISO size × 2 (eg for DVD. 3.4GB × 2)." - printf '%b\n' "Otherwise \$TMPDIR will be used." - ;; -esac - -## Check preseed argument -if [ ! -f "${PRESEED_FILE}" ]; then - printf '%b\n' "ERROR : The first argument should be the path to preseed file to add." - exit 1 -fi -# }}} - # Download and extract ISO {{{ wget -q "${USE_DEBIAN_ISO}" -O "${DEBIAN_DL_ISO_PATH}" command 7z x -o"${TEMP_ISO_DIR}" -- "${DEBIAN_DL_ISO_PATH}" > /dev/null