103 lines
2.4 KiB
Bash
103 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Copyright (c) 2021-2025 community-scripts ORG
|
|
# Author: HydroshieldMKII
|
|
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
|
# Source: https://github.com/HydroshieldMKII/Guardian
|
|
|
|
# Import Functions und Setup
|
|
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
|
|
color
|
|
verb_ip6
|
|
catch_errors
|
|
setting_up_container
|
|
network_check
|
|
update_os
|
|
|
|
# Installing Dependencies
|
|
msg_info "Installing Dependencies"
|
|
$STD apt-get install -y \
|
|
git \
|
|
nodejs \
|
|
npm \
|
|
sqlite3 \
|
|
unzip \
|
|
curl
|
|
msg_ok "Installed Dependencies"
|
|
|
|
# Setup App
|
|
msg_info "Setup Guardian"
|
|
RELEASE=$(curl -fsSL https://api.github.com/repos/HydroshieldMKII/Guardian/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
|
|
curl -fsSL -o "${RELEASE}.zip" "https://github.com/HydroshieldMKII/Guardian/archive/refs/tags/${RELEASE}.zip"
|
|
unzip -q "${RELEASE}.zip"
|
|
# Strip 'v' prefix from RELEASE for folder name
|
|
FOLDER_NAME=$(echo "${RELEASE}" | sed 's/^v//')
|
|
mv "Guardian-${FOLDER_NAME}/" "/opt/Guardian"
|
|
echo "${RELEASE}" >/opt/Guardian_version.txt
|
|
msg_ok "Setup Guardian"
|
|
|
|
# ===== Build Backend =====
|
|
msg_info "Building backend"
|
|
cd /opt/Guardian/backend
|
|
npm ci
|
|
npm run build
|
|
msg_ok "Built backend"
|
|
|
|
# ===== Install Frontend Dependencies =====
|
|
msg_info "Installing frontend dependencies"
|
|
cd /opt/Guardian/frontend
|
|
npm ci
|
|
msg_ok "Installed frontend dependencies"
|
|
|
|
# ===== Backend Service =====
|
|
msg_info "Creating Backend Service"
|
|
cat <<EOF >/etc/systemd/system/guardian-backend.service
|
|
[Unit]
|
|
Description=Guardian Backend
|
|
After=network.target
|
|
|
|
[Service]
|
|
WorkingDirectory=/opt/Guardian/backend
|
|
Environment=NODE_ENV=development
|
|
ExecStart=/usr/bin/node dist/main.js
|
|
Restart=always
|
|
RestartSec=3
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
systemctl enable -q --now guardian-backend
|
|
msg_ok "Created Backend Service"
|
|
|
|
# ===== Frontend Service =====
|
|
msg_info "Creating Frontend Service"
|
|
cat <<EOF >/etc/systemd/system/guardian-frontend.service
|
|
[Unit]
|
|
Description=Guardian Frontend
|
|
After=guardian-backend.service network.target
|
|
Wants=guardian-backend.service
|
|
|
|
[Service]
|
|
WorkingDirectory=/opt/Guardian/frontend
|
|
Environment=NODE_ENV=development
|
|
Environment=PORT=3000
|
|
ExecStart=/usr/bin/npm run dev
|
|
Restart=always
|
|
RestartSec=3
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
systemctl enable -q --now guardian-frontend
|
|
msg_ok "Created Frontend Service"
|
|
|
|
motd_ssh
|
|
customize
|
|
|
|
# Cleanup
|
|
msg_info "Cleaning up"
|
|
rm -f "${RELEASE}".zip
|
|
$STD apt-get -y autoremove
|
|
$STD apt-get -y autoclean
|
|
msg_ok "Cleaned"
|