From e0ccdb42fc60e92a5b9c2054cd014c1ec4f82344 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 3 Jul 2025 13:22:19 +0200 Subject: [PATCH] testing --- ct/trilium.sh | 86 ++++++++++++++++++++++++++++++++++++ ct/zigbee2mqtt.sh | 90 -------------------------------------- install/trilium-install.sh | 44 +++++++++++++++++++ 3 files changed, 130 insertions(+), 90 deletions(-) create mode 100644 ct/trilium.sh delete mode 100644 ct/zigbee2mqtt.sh create mode 100644 install/trilium-install.sh diff --git a/ct/trilium.sh b/ct/trilium.sh new file mode 100644 index 00000000..be477e71 --- /dev/null +++ b/ct/trilium.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func) +# Copyright (c) 2021-2025 tteck +# Author: tteck (tteckster) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/TriliumNext/Trilium + +APP="Trilium" +var_tags="${var_tags:-notes}" +var_cpu="${var_cpu:-1}" +var_ram="${var_ram:-512}" +var_disk="${var_disk:-2}" +var_os="${var_os:-debian}" +var_version="${var_version:-12}" +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/trilium ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + RELEASE=$(curl -fsSL https://api.github.com/repos/TriliumNext/Trilium/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + if [[ "${RELEASE}" != "$(cat ~/.Trilium 2>/dev/null)" ]] || [[ ! -f ~/.Trilium ]]; then + + if [[ -d /opt/trilium/db ]]; then + DB_PATH="/opt/trilium/db" + DB_RESTORE_PATH="/opt/trilium/db" + elif [[ -d /opt/trilium/assets/db ]]; then + DB_PATH="/opt/trilium/assets/db" + DB_RESTORE_PATH="/opt/trilium/assets/db" + else + msg_error "Database not found in either /opt/trilium/db or /opt/trilium/assets/db" + exit 1 + fi + + msg_info "Stopping ${APP}" + systemctl stop trilium + sleep 1 + msg_ok "Stopped ${APP}" + + msg_info "Backing up Database" + mkdir -p /opt/trilium_backup + cp -r "${DB_PATH}" /opt/trilium_backup/ + rm -rf /opt/trilium + msg_ok "Backed up Database" + + fetch_and_deploy_gh_release "Trilium" "TriliumNext/Trilium" "prebuild" "latest" "/opt/trilium" "TriliumNotes-Server-*-linux-x64.tar.xz" + + # Restore database + msg_info "Restoring Database" + mkdir -p "$(dirname "${DB_RESTORE_PATH}")" + cp -r /opt/trilium_backup/$(basename "${DB_PATH}") "${DB_RESTORE_PATH}" + msg_ok "Restored Database" + + msg_info "Cleaning up" + rm -rf /opt/trilium_backup + msg_ok "Cleaned" + + msg_info "Starting ${APP}" + systemctl start trilium + sleep 1 + msg_ok "Started ${APP}" + msg_ok "Updated Successfully" + else + msg_ok "No update required. ${APP} is already at ${RELEASE}" + 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}:8080${CL}" diff --git a/ct/zigbee2mqtt.sh b/ct/zigbee2mqtt.sh deleted file mode 100644 index f087d75b..00000000 --- a/ct/zigbee2mqtt.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env bash -source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func) -# Copyright (c) 2021-2025 tteck -# Author: tteck (tteckster) -# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE -# Source: https://www.zigbee2mqtt.io/ - -APP="Zigbee2MQTT" -var_tags="${var_tags:-smarthome;zigbee;mqtt}" -var_cpu="${var_cpu:-2}" -var_ram="${var_ram:-1024}" -var_disk="${var_disk:-4}" -var_os="${var_os:-debian}" -var_version="${var_version:-12}" -var_unprivileged="${var_unprivileged:-0}" - -header_info "$APP" -variables -color -catch_errors - -function update_script() { - header_info - check_container_storage - check_container_resources - if [[ ! -d /opt/zigbee2mqtt ]]; then - msg_error "No ${APP} Installation Found!" - exit - fi - - if [[ -f ~/.zigbee2mqtt ]]; then - CURRENT="$(cat ~/.zigbee2mqtt)" - elif [[ -f /opt/${APP}_version.txt ]]; then - CURRENT="$(cat /opt/${APP}_version.txt)" - rm -f /opt/${APP}_version.txt - else - CURRENT="" - fi - - RELEASE=$(curl -fsSL https://api.github.com/repos/Koenkk/zigbee2mqtt/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') - if [[ "$RELEASE" != "$CURRENT" ]]; then - if ! command -v jq &>/dev/null; then - $STD apt-get update - $STD apt-get install -y jq - fi - NODE_VERSION=24 NODE_MODULE="pnpm@$(curl -fsSL https://raw.githubusercontent.com/Koenkk/zigbee2mqtt/master/package.json | jq -r '.packageManager | split("@")[1]')" setup_nodejs - - msg_info "Stopping Service" - systemctl stop zigbee2mqtt - msg_ok "Stopped Service" - - msg_info "Creating Backup" - rm -rf /opt/${APP}_backup*.tar.gz - mkdir -p /opt/z2m_backup - $STD tar -czf /opt/z2m_backup/${APP}_backup_$(date +%Y%m%d%H%M%S).tar.gz -C /opt zigbee2mqtt - mv /opt/zigbee2mqtt/data /opt/z2m_backup - msg_ok "Backup Created" - - fetch_and_deploy_gh_release "Zigbee2MQTT" "Koenkk/zigbee2mqtt" "tarball" "latest" "/opt/zigbee2mqtt" - - msg_info "Updating ${APP} to v${RELEASE}" - rm -rf /opt/zigbee2mqtt/data - mv /opt/z2m_backup/data /opt/zigbee2mqtt - cd /opt/zigbee2mqtt - $STD pnpm install --frozen-lockfile - $STD pnpm build - msg_ok "Updated Zigbee2MQTT" - - msg_info "Starting Service" - systemctl start zigbee2mqtt - msg_ok "Started Service" - - msg_info "Cleaning up" - rm -rf /opt/z2m_backup - msg_ok "Cleaned up" - echo "${RELEASE}" >/opt/${APP}_version.txt - else - msg_ok "No update required. ${APP} is already at v${RELEASE}." - 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}:9442${CL}" diff --git a/install/trilium-install.sh b/install/trilium-install.sh new file mode 100644 index 00000000..6547b1ce --- /dev/null +++ b/install/trilium-install.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2025 tteck +# Author: tteck (tteckster) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/TriliumNext/Trilium + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +fetch_and_deploy_gh_release "Trilium" "TriliumNext/Trilium" "prebuild" "latest" "/opt/trilium" "TriliumNotes-Server-*-linux-x64.tar.xz" + +msg_info "Creating Service" +cat </etc/systemd/system/trilium.service +[Unit] +Description=Trilium Daemon +After=syslog.target network.target + +[Service] +User=root +Type=simple +ExecStart=/opt/trilium/trilium.sh +WorkingDirectory=/opt/trilium/ +TimeoutStopSec=20 +Restart=always + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable --now -q trilium +msg_ok "Created Service" + +motd_ssh +customize + +msg_info "Cleaning up" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned"