From 385931094c2a5d923b06113420cb5d3555788f3e Mon Sep 17 00:00:00 2001 From: Vincent <114195376+HydroshieldMKII@users.noreply.github.com> Date: Tue, 30 Sep 2025 16:38:39 -0400 Subject: [PATCH] Refactor Guardian installation script to remove Docker installation, streamline dependency setup, and enhance service management for backend and frontend --- install/guardian-install.sh | 93 +++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 36 deletions(-) diff --git a/install/guardian-install.sh b/install/guardian-install.sh index 4640ed06..0edaa9f8 100644 --- a/install/guardian-install.sh +++ b/install/guardian-install.sh @@ -15,62 +15,83 @@ update_os msg_info "Installing Dependencies" $STD apt-get install -y \ - curl \ - ca-certificates \ - gnupg \ - lsb-release + git \ + nodejs \ + npm \ + sqlite3 \ + unzip \ + curl msg_ok "Installed Dependencies" -msg_info "Installing Docker" -curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg -echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null -$STD apt-get update -$STD apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin -systemctl enable --now docker -msg_ok "Installed Docker" - -msg_info "Setting up Guardian" -mkdir -p /opt/Guardian -cd /opt/Guardian - +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 docker-compose.yml "https://raw.githubusercontent.com/HydroshieldMKII/Guardian/main/docker-compose.example.yml" +curl -fsSL -o "${RELEASE}.zip" "https://github.com/HydroshieldMKII/Guardian/archive/refs/tags/${RELEASE}.zip" +unzip -q "${RELEASE}.zip" + +FOLDER_NAME=$(echo "${RELEASE}" | sed 's/^v//') +mv "Guardian-${FOLDER_NAME}/" "/opt/Guardian" echo "${RELEASE}" >/opt/Guardian_version.txt msg_ok "Setup Guardian" -msg_info "Starting Guardian" -cd /opt/Guardian -docker compose up -d -msg_ok "Started Guardian" -msg_info "Creating Guardian Service" -cat </etc/systemd/system/guardian.service +msg_info "Building backend" +cd /opt/Guardian/backend +npm ci +npm run build +msg_ok "Built backend" + +msg_info "Building frontend" +cd /opt/Guardian/frontend +npm ci +NODE_ENV=development npm run build +msg_ok "Built frontend" + +msg_info "Creating Backend Service" +cat </etc/systemd/system/guardian-backend.service [Unit] -Description=Guardian Docker Compose -Requires=docker.service -After=docker.service -Wants=network-online.target -After=network-online.target +Description=Guardian Backend +After=network.target [Service] -Type=oneshot -RemainAfterExit=true -WorkingDirectory=/opt/Guardian -ExecStart=/usr/bin/docker compose up -d -ExecStop=/usr/bin/docker compose down -TimeoutStartSec=0 +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 guardian -msg_ok "Created Guardian Service" +systemctl enable -q --now guardian-backend +msg_ok "Created Backend Service" + +msg_info "Creating Frontend Service" +cat </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=production +Environment=PORT=3000 +ExecStart=/usr/bin/npm run start +Restart=always +RestartSec=3 + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable -q --now guardian-frontend +msg_ok "Created Frontend Service" motd_ssh customize msg_info "Cleaning up" +rm -f "${RELEASE}".zip $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"