diff --git a/bundler/bundle/install b/bundler/bundle/install index cf268db83..618855700 100755 --- a/bundler/bundle/install +++ b/bundler/bundle/install @@ -14,13 +14,8 @@ set -x # shellcheck disable=SC1091 # Don’t follow sourced script. . lib.sh -# HACK: If we let mktemp use the default /tmp directory, the system purges the -# file before the end of the script for some reason. We use /var/tmp as a -# workaround. -readonly TEMP_DIR='/var/tmp' - # Temporary file for installation settings. -INSTALL_SETTINGS_FILE="$(mktemp --tmpdir="${TEMP_DIR}" --suffix .yml)" +INSTALL_SETTINGS_FILE="$(mktemp --suffix .yml)" readonly INSTALL_SETTINGS_FILE # The eventual, permanent settings files. Note, that these might not exist diff --git a/get-tinypilot.sh b/get-tinypilot.sh index 58db4d47d..b1a2d7671 100755 --- a/get-tinypilot.sh +++ b/get-tinypilot.sh @@ -66,10 +66,11 @@ readonly LEGACY_INSTALLER_DIR='/opt/tinypilot-updater' # - The TinyPilot bundle archive # - The unpacked TinyPilot bundle archive, after running the bundle's `install` # script +# - About 50 MiB of temporary files # - At least a 20% safety margin # Use the following command to help you estimate a sensible size allocation: # du --summarize --total --bytes "${INSTALLER_DIR}" "${BUNDLE_FILE}" -readonly RAMDISK_SIZE_MIB=500 +readonly RAMDISK_SIZE_MIB=560 AVAILABLE_MEMORY_MIB="$(free --mebi | grep --fixed-strings 'Mem:' | @@ -111,10 +112,21 @@ if (( "${AVAILABLE_MEMORY_MIB}" >= "${RAMDISK_SIZE_MIB}" )); then --verbose else # Fall back to installing from disk. - INSTALLER_DIR="$(mktemp --directory)" + # HACK: If we let mktemp use the default /tmp directory, the system begins + # purging files before the end of the script for some reason. We use /var/tmp + # as a workaround. + INSTALLER_DIR="$(mktemp \ + --tmpdir='/var/tmp' \ + --directory)" fi readonly INSTALLER_DIR +# Use a temporary directory within the installer directory so that we take +# advantage of RAMdisk if we're using one. +readonly TMPDIR="${INSTALLER_DIR}/tmp" +export TMPDIR +sudo mkdir "${TMPDIR}" + readonly BUNDLE_FILE="${INSTALLER_DIR}/bundle.tgz" # Download tarball to RAMdisk. @@ -147,6 +159,8 @@ fi # Run install. pushd "${INSTALLER_DIR}" -sudo ./install +sudo \ + TMPDIR="${TMPDIR}" \ + ./install } # Prevent the script from executing until the client downloads the full file. diff --git a/scripts/install-bundle b/scripts/install-bundle index e38d239f8..cd8a7561a 100755 --- a/scripts/install-bundle +++ b/scripts/install-bundle @@ -81,10 +81,11 @@ readonly LEGACY_INSTALLER_DIR='/opt/tinypilot-updater' # - The TinyPilot bundle archive # - The unpacked TinyPilot bundle archive, after running the bundle's `install` # script +# - About 50 MiB of temporary files # - At least a 20% safety margin # Use the following command to help you estimate a sensible size allocation: # du --summarize --total --bytes "${INSTALLER_DIR}" "${BUNDLE_FILE}" -readonly RAMDISK_SIZE_MIB=500 +readonly RAMDISK_SIZE_MIB=560 AVAILABLE_MEMORY_MIB="$(free --mebi | grep --fixed-strings 'Mem:' | @@ -126,10 +127,21 @@ if (( "${AVAILABLE_MEMORY_MIB}" >= "${RAMDISK_SIZE_MIB}" )); then --verbose else # Fall back to installing from disk. - INSTALLER_DIR="$(mktemp --directory)" + # HACK: If we let mktemp use the default /tmp directory, the system begins + # purging files before the end of the script for some reason. We use /var/tmp + # as a workaround. + INSTALLER_DIR="$(mktemp \ + --tmpdir='/var/tmp' \ + --directory)" fi readonly INSTALLER_DIR +# Use a temporary directory within the installer directory so that we take +# advantage of RAMdisk if we're using one. +readonly TMPDIR="${INSTALLER_DIR}/tmp" +export TMPDIR +mkdir "${TMPDIR}" + # Extract tarball to installer directory. tar \ --gunzip \