Repository navigation
Expand file tree
/
Copy pathstart.command
More file actions
66 lines (55 loc) · 2.6 KB
/
Copy pathstart.command
File metadata and controls
66 lines (55 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#
# Author: Om Abhyankar
# License: MIT License
# https://opensource.org/license/mit
# GitHub: https://github.com/sideeffects69
#
# One-click launcher for macOS. Double-click this file in Finder (or run it from
# a terminal). It sets up everything the first time, then opens the control
# panel in your web browser. Safe to run again any time.
# Move into the project folder (this script's own folder).
cd "$(dirname "$0")" || exit 1
echo ""
echo "========================================================"
echo " Magic Apply - Jobs - starting your control panel"
echo "========================================================"
echo ""
# 1) Make sure Python 3 is installed.
if ! command -v python3 >/dev/null 2>&1; then
echo "Python 3 was not found on this computer."
echo "Please install it from https://www.python.org/downloads/ and run this again."
echo ""
read -r -p "Press Return to close..." _
exit 1
fi
VENV_PY=".venv/bin/python"
# A virtual environment is tied to the exact folder (and computer) it was created in. If this project was
# copied or moved, the old .venv looks present but no longer works - rebuild it instead of failing oddly.
if [ -x "$VENV_PY" ] && ! "$VENV_PY" --version >/dev/null 2>&1; then
echo "Found a Python environment from a different computer or folder - rebuilding it..."
rm -rf .venv
fi
# 2) Create a private Python environment the first time.
if [ ! -x "$VENV_PY" ]; then
echo "Setting up for the first time (this can take a minute)..."
python3 -m venv .venv || { echo "Could not create the Python environment."; read -r -p "Press Return to close..." _; exit 1; }
fi
# 3) Install the required packages once (quietly).
if [ ! -f ".venv/.deps_installed" ] || [ requirements.txt -nt ".venv/.deps_installed" ]; then
echo "Installing required packages (first run, or the package list changed)..."
"$VENV_PY" -m pip install --quiet --upgrade pip
"$VENV_PY" -m pip install --quiet -r requirements.txt || { echo "Could not install required packages."; read -r -p "Press Return to close..." _; exit 1; }
touch ".venv/.deps_installed"
fi
# 4) Start the control panel. It chooses a free port (port 5000 is used by
# AirPlay on macOS), prints the address, and opens your browser to it.
export PANEL_OPEN_BROWSER=1
echo ""
echo "Starting the control panel and opening it in your browser..."
echo "Keep this window open while you use the tool. Close it to stop the server."
echo ""
# 5) Start the local control panel (runs until you close this window).
"$VENV_PY" app.py
echo ""
read -r -p "The control panel has stopped. Press Return to close..." _