Fix user temp dir with mktemp

This commit is contained in:
Jeremy Gardais 2019-01-03 14:19:59 +01:00
parent b697b42f07
commit 725936597f
1 changed files with 38 additions and 37 deletions

View File

@ -5,6 +5,44 @@
# mount require root permissions, so i choose to extract the iso. # 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 {{{ # Vars {{{
DEBIAN_VERSION_NAME="stretch" DEBIAN_VERSION_NAME="stretch"
DEBIAN_VERSION_NB="9.6.0" 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_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=$(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" TEMP_INITRD_DIR="${TEMP_DIR}/initrd"
@ -44,42 +81,6 @@ if [ ! -f /usr/lib/ISOLINUX/isohdpfx.bin ]; then
fi 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 {{{ # 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_ISO_DIR}" -- "${DEBIAN_DL_ISO_PATH}" > /dev/null command 7z x -o"${TEMP_ISO_DIR}" -- "${DEBIAN_DL_ISO_PATH}" > /dev/null