From 7f91de7399730c483f11d7f0e42e267f6b328001 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Fri, 19 Nov 2021 20:30:13 -0700 Subject: [PATCH] Allow executing run script w/o prior setup This change allows a bit quicker and simpler setup on new servers. Rather than setting up dependencies, virtual environment, etc, a systemd daemon, for example, can just ExecStart the script from any location without having to perform any preliminary setup. The only prerequisite step now is having Python3+ installed. --- run | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/run b/run index 9593201..371e65f 100755 --- a/run +++ b/run @@ -7,6 +7,19 @@ set -euo pipefail SCRIPT_DIR="$(builtin cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" +if [[ ! -x "$(command -v python3)" ]]; then + echo "Python3 required -- please install first" + exit 1 +fi + +if [[ ! -d "$SCRIPT_DIR/venv" ]]; then + python3 -m venv venv + "$SCRIPT_DIR"/venv/bin/pip install --upgrade pip + "$SCRIPT_DIR"/venv/bin/pip install -r requirements.txt +fi + +cd "$SCRIPT_DIR" + # Set directory to serve static content from SUBDIR="${1:-app}" export APP_ROOT="$SCRIPT_DIR/$SUBDIR" @@ -24,7 +37,7 @@ if [[ "$SUBDIR" == "test" ]]; then pytest -sv else mkdir -p "$STATIC_FOLDER" - python3 -um app \ + "$SCRIPT_DIR"/venv/bin/python -um app \ --host "${ADDRESS:-0.0.0.0}" \ --port "${PORT:-"${EXPOSE_PORT:-5000}"}" fi