Skip to content

Commit

Permalink
Place temporary install files within RAMdisk (#1464)
Browse files Browse the repository at this point in the history
Resolves #1462

You can test this PR's install script and bundle via:
```bash
curl \
  --silent \
  --show-error \
  https://raw.githubusercontent.com/tiny-pilot/tinypilot/aca37b26108c7fc7fc24fad48890734859fe9221/get-tinypilot.sh | \
    bash -
```


<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1464"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>

---------

Co-authored-by: Michael Lynch <git@mtlynch.io>
  • Loading branch information
jdeanwallace and mtlynch committed Jun 23, 2023
1 parent 7498b9a commit d94ff9a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
7 changes: 1 addition & 6 deletions bundler/bundle/install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 17 additions & 3 deletions get-tinypilot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:' |
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
16 changes: 14 additions & 2 deletions scripts/install-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -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:' |
Expand Down Expand Up @@ -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 \
Expand Down

0 comments on commit d94ff9a

Please sign in to comment.