#!/usr/bin/env dash
# based on <https://wiki.debian.org/DebianInstaller/WritableUSBStick>
-set -eu
+set -e
PARENT_DIR=$(dirname "$0")
cd "${PARENT_DIR}"
. lib/INSTALLER_VERSION.sh
. lib/expect_n_args.sh
. lib/get_mountable_device_path.sh
. lib/path_tmp_timestamped.sh
+. lib/prefixed_msg.sh
. lib/trapp.sh
+prefixed_msg_init make_writable_installer
+
FILENAME_ISO="debian-${INSTALLER_VERSION}-amd64-netinst.iso"
URL_ISO="https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/${FILENAME_ISO}"
PATH_MNT_ISO=/mnt/iso
abort_if_command_unknown wget
if [ -z "$2" ]; then
- echo "No file path set, so will try to retrieve image online from ${URL_ISO}."
+ prefixed_msg "No file path set, so will try to retrieve image online from ${URL_ISO}."
abort_if_offline
else
- echo "With file path set, checking if we can use file at ${PATH_FILE_ISO}."
PATH_FILE_ISO=$(realpath "$2")
+ prefixed_msg "With file path set, checking if we can use file at ${PATH_FILE_ISO}."
BASENAME_FILE_ISO=$(basename "${PATH_FILE_ISO}")
if [ ! "${FILENAME_ISO}" = "${BASENAME_FILE_ISO}" ]; then
abort "basename of PATH_FILE_ISO != expected ${FILENAME_ISO}"
PATH_DEV=$(get_mountable_device_path "$1")
PATH_PROCESSING="$(path_tmp_timestamped make_writable_installer)"
-echo "Setting up processing directory at ${PATH_PROCESSING} …"
+prefixed_msg "Setting up processing directory at ${PATH_PROCESSING} …"
RM_PROCESSING="rm -rf ${PATH_PROCESSING}"
mkdir "${PATH_PROCESSING}"
trapp "${RM_PROCESSING}"
ln -s "${PATH_FILE_ISO}" .
fi
-echo "Preparing partition/filesystem on ${PATH_DEV} …"
+prefixed_msg "Preparing partition/filesystem on ${PATH_DEV} …"
parted --script "${PATH_DEV}" mklabel msdos
parted --script "${PATH_DEV}" mkpart primary fat32 0% 100%
PATH_PARTITION="${PATH_DEV}1"
mkfs.vfat "${PATH_PARTITION}" > /dev/null
PATH_MNT_DEV='/mnt/'$(basename "${PATH_PARTITION}")
-echo -n "Mounting ${PATH_MNT_ISO} and ${PATH_MNT_DEV} …"
+prefixed_msg "Mounting ${PATH_MNT_ISO} and ${PATH_MNT_DEV} …"
mkdir -p "${PATH_MNT_ISO}" "${PATH_MNT_DEV}"
do_umount() {
- echo "Unmounting $1 …"
+ prefixed_msg "Unmounting $1 …"
set +e
umount "$1"
set -e
mount -o loop "${FILENAME_ISO}" "${PATH_MNT_ISO}" 2>&1 | sed 's|mount: /mnt/iso: WARNING: source write-protected, mounted read-only.||'
trapp "${RM_PROCESSING}; do_umount ${PATH_MNT_DEV}; do_umount ${PATH_MNT_ISO}"
-echo "Copying contents of ${PATH_MNT_ISO} to ${PATH_MNT_DEV}/ …"
+prefixed_msg "Copying contents of ${PATH_MNT_ISO} to ${PATH_MNT_DEV}/ …"
FILENAME_RSYNC_ERRORS="rsync_errors"
set +e
rsync -a "${PATH_MNT_ISO}/" "${PATH_MNT_DEV}/" 2> "${FILENAME_RSYNC_ERRORS}"
RESULT=$?
set -e
if [ "${RESULT}" != "0" ]; then
- echo 'RSYNC ERRORS:'
+ prefixed_msg 'RSYNC ERRORS:'
cat "${FILENAME_RSYNC_ERRORS}"
- echo '\nrsync encountered errors, see above – continue? (Y/N)'
+ prefixed_msg '\nrsync encountered errors, see above – continue? (Y/N)'
read -r ANSWER
FIRST_CHAR=$(echo "${ANSWER}" | cut -c1)
if ! [ "${FIRST_CHAR}" = 'y' ] || [ "${FIRST_CHAR}" = 'Y' ]; then
fi
fi
-echo "Installing preseed file …"
+prefixed_msg "Installing preseed file …"
cp "${PATH_PRESEED_CFG}" "${PATH_MNT_DEV}/"
sed --in-place 's/ --- / --- preseed\/file=\/cdrom\/'"${FILENAME_PRESEED_CFG}"' /g' "${PATH_MNT_DEV}/boot/grub/grub.cfg"
-echo "Done!"
+prefixed_msg "Done!"
+
+prefixed_msg_exit