1
0
mirror of https://github.com/tiny-pilot/tinypilot.git synced 2021-09-19 22:56:27 +03:00
Files
tinypilot-machine-bios-cont…/dev-scripts/enable-mock-scripts
Michael Lynch c799b89c9b Add mock scripts for development (#566)
* Add mock scripts for development

This enables TinyPilot developers to mock out two privileged functions during development:

* Change hostname
* Collect debug logs

Once the developer enables mock scripts on their system, they can use these two features and have it work (sort of) like it works on a real device.

This still leaves a few functions unmocked:

* Shutdown/restart (because we call those by absolute path to system scripts, we can't mock them out)
* Update: The update logic is pretty complex and involves launching a systemd process, so it's non-trivial to mock this out.

Related: #501

* Handle case where /opt/tinypilot-privileged is a real directory
2021-03-10 15:05:39 -05:00

28 lines
778 B
Bash
Executable File

#!/bin/bash
# Creates a symlink from /opt/tinypilot-privileged to dev-scripts/mock-scripts
# to facilitate development on non-TinyPilot systems.
# Exit build script on first failure.
set -e
# Echo commands to stdout.
set -x
# Exit on unset variable.
set -u
readonly PRIVILEGED_SCRIPTS_DIR="/opt/tinypilot-privileged"
readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly MOCK_SCRIPTS_DIR="${SCRIPT_DIR}/mock-scripts"
# If there's an existing symlink, remove it.
if [[ -L "${PRIVILEGED_SCRIPTS_DIR}" ]]; then
rm "${PRIVILEGED_SCRIPTS_DIR}"
elif [[ -d "${PRIVILEGED_SCRIPTS_DIR}" ]]; then
echo "Error: ${PRIVILEGED_SCRIPTS_DIR} exists and is not a symlink" >&2
exit 1
fi
ln -s "${MOCK_SCRIPTS_DIR}" "${PRIVILEGED_SCRIPTS_DIR}"