暂存-安装脚本

This commit is contained in:
2026-05-15 12:08:02 +08:00
parent 6ccd3eb9c1
commit 91bedce2d7
5 changed files with 175 additions and 45 deletions

View File

@@ -1,34 +1,115 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail
echo "Start installation AIO_3D_Print_Exp"
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 "Clean existing installation"
# rm -rf /opt/AIO_3D_Print_Exp
systemctl stop aio-3d-main.service
systemctl stop aio-3d-huey.service
# rm -rf /etc/systemd/system/aio-3d-main.service
# rm -rf /etc/systemd/system/aio-3d-huey.service
echo "Installing AIO_3D_Print_Web_Platform into: $REPO_DIR"
echo "Using python: $PYTHON_BIN"
echo "Copy installation files"
# mkdir -p /opt/AIO_3D_Print_Exp
# cp -r ./. /opt/AIO_3D_Print_Exp/
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 "Set execute permissions"
# chmod +x /opt/AIO_3D_Print_Exp/run_main.sh
# chmod +x /opt/AIO_3D_Print_Exp/run_huey.sh
echo "Creating virtual environment at $VENV_DIR (if missing)"
if [ ! -d "$VENV_DIR" ]; then
$PYTHON_BIN -m venv "$VENV_DIR"
fi
echo "Copy service files"
# cp /opt/AIO_3D_Print_Exp/aio-3d-main.service /etc/systemd/system/
# cp /opt/AIO_3D_Print_Exp/aio-3d-huey.service /etc/systemd/system/
cp /home/lhye200/AIO_3D_Print_Exp/aio-3d-main.service /etc/systemd/system/
cp /home/lhye200/AIO_3D_Print_Exp/aio-3d-huey.service /etc/systemd/system/
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
echo "Reload systemd daemon"
systemctl daemon-reload
systemctl enable aio-3d-main.service
systemctl enable aio-3d-huey.service
systemctl start aio-3d-huey.service
systemctl start aio-3d-main.service
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"