From eb2c3b71569efdebe0f172408300b562bfaa7775 Mon Sep 17 00:00:00 2001 From: "push-app-to-main[bot]" <203845782+push-app-to-main[bot]@users.noreply.github.com> Date: Wed, 15 Oct 2025 21:58:16 +0200 Subject: [PATCH] Guardian (#8365) * 'Add new script' * Add messages to cleanup commands in guardian-install.sh * refactor --------- Co-authored-by: push-app-to-main[bot] <203845782+push-app-to-main[bot]@users.noreply.github.com> Co-authored-by: CanbiZ <47820557+MickLesk@users.noreply.github.com> Co-authored-by: Tobias <96661824+CrazyWolf13@users.noreply.github.com> --- ct/guardian.sh | 79 ++++++++++++++++++++++++++++++ ct/headers/guardian | 6 +++ frontend/public/json/guardian.json | 35 +++++++++++++ install/guardian-install.sh | 75 ++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) create mode 100755 ct/guardian.sh create mode 100644 ct/headers/guardian create mode 100644 frontend/public/json/guardian.json create mode 100644 install/guardian-install.sh diff --git a/ct/guardian.sh b/ct/guardian.sh new file mode 100755 index 000000000..cee37503e --- /dev/null +++ b/ct/guardian.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# 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 + +APP="Guardian" +var_tags="${var_tags:-media;monitoring}" +var_cpu="${var_cpu:-2}" +var_ram="${var_ram:-2048}" +var_disk="${var_disk:-6}" +var_os="${var_os:-debian}" +var_version="${var_version:-13}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { +header_info +check_container_storage +check_container_resources + +if [[ ! -d "/opt/guardian" ]] ; then + msg_error "No ${APP} Installation Found!" + exit +fi + +if check_for_gh_release "guardian" "HydroshieldMKII/Guardian" ; then + msg_info "Stopping Services" + systemctl stop guardian-backend guardian-frontend + msg_ok "Stopped Services" + + if [[ -f "/opt/guardian/backend/plex-guard.db" ]] ; then + msg_info "Backing up Database" + cp "/opt/guardian/backend/plex-guard.db" "/tmp/plex-guard.db.backup" + msg_ok "Backed up Database" + fi + + cp /opt/guardian/.env /opt + CLEAN_INSTALL=1 fetch_and_deploy_gh_release "guardian" "HydroshieldMKII/Guardian" "tarball" "latest" "/opt/guardian" + mv /opt/.env /opt/guardian + + if [[ -f "/tmp/plex-guard.db.backup" ]] ; then + msg_info "Restoring Database" + cp "/tmp/plex-guard.db.backup" "/opt/guardian/backend/plex-guard.db" + rm "/tmp/plex-guard.db.backup" + msg_ok "Restored Database" + fi + + msg_info "Updating Guardian" + cd /opt/guardian/backend + $STD npm ci + $STD npm run build + + cd /opt/guardian/frontend + $STD npm ci + $STD DEPLOYMENT_MODE=standalone npm run build + msg_ok "Updated Guardian" + + msg_info "Starting Services" + systemctl start guardian-backend guardian-frontend + msg_ok "Started Services" + msg_ok "Updated Successfully" +fi +exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW} Access it using the following URL:${CL}" +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}" diff --git a/ct/headers/guardian b/ct/headers/guardian new file mode 100644 index 000000000..e19ee5708 --- /dev/null +++ b/ct/headers/guardian @@ -0,0 +1,6 @@ + ______ ___ + / ____/_ ______ __________/ (_)___ _____ + / / __/ / / / __ `/ ___/ __ / / __ `/ __ \ +/ /_/ / /_/ / /_/ / / / /_/ / / /_/ / / / / +\____/\__,_/\__,_/_/ \__,_/_/\__,_/_/ /_/ + diff --git a/frontend/public/json/guardian.json b/frontend/public/json/guardian.json new file mode 100644 index 000000000..b7c6761d5 --- /dev/null +++ b/frontend/public/json/guardian.json @@ -0,0 +1,35 @@ +{ + "name": "Guardian", + "slug": "guardian", + "categories": [ + 13 + ], + "date_created": "2025-09-22", + "type": "ct", + "updateable": true, + "privileged": false, + "interface_port": 3000, + "documentation": "https://github.com/HydroshieldMKII/Guardian/blob/main/README.md", + "config_path": "/opt/guardian/.env", + "website": "https://github.com/HydroshieldMKII/Guardian", + "logo": null, + "description": "Guardian is a lightweight companion app for Plex that lets you monitor, approve or block devices in real time. It helps you enforce per-user or global policies, stop unwanted sessions automatically and grant temporary access - all through a simple web interface.", + "install_methods": [ + { + "type": "default", + "script": "ct/guardian.sh", + "resources": { + "cpu": 2, + "ram": 2048, + "hdd": 6, + "os": "Debian", + "version": "13" + } + } + ], + "default_credentials": { + "username": null, + "password": null + }, + "notes": [] +} diff --git a/install/guardian-install.sh b/install/guardian-install.sh new file mode 100644 index 000000000..994ee4407 --- /dev/null +++ b/install/guardian-install.sh @@ -0,0 +1,75 @@ +#!/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 + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt install -y sqlite3 +msg_ok "Installed Dependencies" + +NODE_VERSION="24" setup_nodejs +fetch_and_deploy_gh_release "guardian" "HydroshieldMKII/Guardian" "tarball" "latest" "/opt/guardian" + +msg_info "Configuring ${APPLICATION}" +cd /opt/guardian/backend +$STD npm ci +$STD npm run build +cd /opt/guardian/frontend +$STD npm ci +export DEPLOYMENT_MODE=standalone +$STD npm run build +msg_ok "Configured ${APPLICATION}" + +msg_info "Creating Service" +cat </etc/systemd/system/guardian-backend.service +[Unit] +Description=Guardian Backend +After=network.target + +[Service] +WorkingDirectory=/opt/guardian/backend +ExecStart=/usr/bin/node dist/main.js +Restart=always +RestartSec=3 +[Install] +WantedBy=multi-user.target +EOF + +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=DEPLOYMENT_MODE=standalone +ExecStart=/usr/bin/npm run start +Restart=always +RestartSec=3 +[Install] +WantedBy=multi-user.target +EOF + +systemctl enable -q --now guardian-backend +systemctl enable -q --now guardian-frontend +msg_ok "Created Service" + +motd_ssh +customize + +msg_info "Cleaning up" +$STD apt -y autoremove +$STD apt -y autoclean +$STD apt -y clean +msg_ok "Cleaned"