mirror of
https://github.com/tiny-pilot/tinypilot.git
synced 2023-10-01 22:58:29 +03:00
Place temporary install files within RAMdisk (#1464)
Resolves https://github.com/tiny-pilot/tinypilot/issues/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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 \
|
||||
|
||||
Reference in New Issue
Block a user