116 lines
3.4 KiB
Bash
Executable File
116 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
VENV_DIR="$REPO_DIR/venv"
|
|
PYTHON_BIN="${PYTHON:-python3}"
|
|
PRUSA_URL="https://github.com/davidk/PrusaSlicer-ARM.AppImage/releases/download/version_2.9.4/PrusaSlicer-2.9.4-aarch64-full.AppImage"
|
|
PRUSA_DIR="$REPO_DIR/prusaslicer"
|
|
PRUSA_FILE="$PRUSA_DIR/$(basename "$PRUSA_URL")"
|
|
|
|
echo "Installing AIO_3D_Print_Web_Platform into: $REPO_DIR"
|
|
echo "Using python: $PYTHON_BIN"
|
|
|
|
echo "Stopping services if running (may require sudo)"
|
|
sudo systemctl stop aio-3d-main.service 2>/dev/null || true
|
|
sudo systemctl stop aio-3d-huey.service 2>/dev/null || true
|
|
|
|
echo "Creating virtual environment at $VENV_DIR (if missing)"
|
|
if [ ! -d "$VENV_DIR" ]; then
|
|
$PYTHON_BIN -m venv "$VENV_DIR"
|
|
fi
|
|
|
|
echo "Activating virtualenv and installing Python requirements"
|
|
# shellcheck disable=SC1091
|
|
source "$VENV_DIR/bin/activate"
|
|
# Detect http(s) proxy (respect both lowercase and uppercase env vars)
|
|
PROXY=""
|
|
if [ -n "${HTTPS_PROXY:-}" ]; then
|
|
PROXY="$HTTPS_PROXY"
|
|
elif [ -n "${https_proxy:-}" ]; then
|
|
PROXY="$https_proxy"
|
|
elif [ -n "${HTTP_PROXY:-}" ]; then
|
|
PROXY="$HTTP_PROXY"
|
|
elif [ -n "${http_proxy:-}" ]; then
|
|
PROXY="$http_proxy"
|
|
fi
|
|
|
|
pip_with_proxy() {
|
|
# Usage: pip_with_proxy install [args...]
|
|
if [ -n "$PROXY" ] && [ "$1" = "install" ]; then
|
|
shift
|
|
pip install --proxy "$PROXY" "$@"
|
|
else
|
|
pip "$@"
|
|
fi
|
|
}
|
|
|
|
pip_with_proxy install --upgrade pip setuptools wheel
|
|
if [ -f "$REPO_DIR/requirements.txt" ]; then
|
|
pip_with_proxy install -r "$REPO_DIR/requirements.txt"
|
|
else
|
|
echo "Warning: requirements.txt not found in $REPO_DIR"
|
|
fi
|
|
|
|
echo "Ensure run scripts are executable"
|
|
chmod +x "$REPO_DIR/run_main.sh" "$REPO_DIR/run_huey.sh"
|
|
|
|
echo "Checking PrusaSlicer AppImage (optional)"
|
|
mkdir -p "$PRUSA_DIR"
|
|
if [ ! -f "$PRUSA_FILE" ]; then
|
|
echo "Downloading PrusaSlicer AppImage to $PRUSA_FILE"
|
|
if command -v curl >/dev/null 2>&1; then
|
|
if [ -n "$PROXY" ]; then
|
|
curl -x "$PROXY" -L -o "$PRUSA_FILE" "$PRUSA_URL"
|
|
else
|
|
curl -L -o "$PRUSA_FILE" "$PRUSA_URL"
|
|
fi
|
|
elif command -v wget >/dev/null 2>&1; then
|
|
if [ -n "$PROXY" ]; then
|
|
env HTTP_PROXY="$PROXY" HTTPS_PROXY="$PROXY" wget -O "$PRUSA_FILE" "$PRUSA_URL"
|
|
else
|
|
wget -O "$PRUSA_FILE" "$PRUSA_URL"
|
|
fi
|
|
else
|
|
echo "Warning: neither curl nor wget found; cannot download PrusaSlicer AppImage automatically."
|
|
fi
|
|
if [ -f "$PRUSA_FILE" ]; then
|
|
chmod +x "$PRUSA_FILE"
|
|
fi
|
|
else
|
|
echo "PrusaSlicer AppImage already present: $PRUSA_FILE"
|
|
fi
|
|
|
|
echo "Prepare and install systemd service files (requires sudo)"
|
|
for svc in "aio-3d-main.service" "aio-3d-huey.service"; do
|
|
SRC="$REPO_DIR/$svc"
|
|
if [ ! -f "$SRC" ]; then
|
|
echo "Warning: $SRC not found, skipping"
|
|
continue
|
|
fi
|
|
|
|
if [ "$svc" = "aio-3d-main.service" ]; then
|
|
EXEC="$REPO_DIR/run_main.sh"
|
|
else
|
|
EXEC="$REPO_DIR/run_huey.sh"
|
|
fi
|
|
|
|
TMPFILE="/tmp/$svc"
|
|
awk -v wd="$REPO_DIR" -v exec="$EXEC" '
|
|
{ if ($0 ~ /^WorkingDirectory=/) { print "WorkingDirectory=" wd; next } \
|
|
if ($0 ~ /^ExecStart=/) { print "ExecStart=" exec; next } \
|
|
print $0 }' "$SRC" > "$TMPFILE"
|
|
|
|
echo "Installing $svc -> /etc/systemd/system/$svc"
|
|
sudo cp "$TMPFILE" "/etc/systemd/system/$svc"
|
|
done
|
|
|
|
echo "Reloading systemd daemon and enabling services"
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable aio-3d-main.service aio-3d-huey.service || true
|
|
sudo systemctl restart aio-3d-huey.service || true
|
|
sudo systemctl restart aio-3d-main.service || true
|
|
|
|
echo "Installation completed successfully"
|
|
|