From 4dc458c605188ecce03c54283e96f423a7c9082d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Mon, 4 Aug 2025 15:43:07 +0200 Subject: [PATCH] Refactor (#6554) --- ct/pocketbase.sh | 30 +++++++++++++++++++----------- install/pocketbase-install.sh | 15 +++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/ct/pocketbase.sh b/ct/pocketbase.sh index ed8515d9d..219126660 100644 --- a/ct/pocketbase.sh +++ b/ct/pocketbase.sh @@ -27,18 +27,26 @@ function update_script() { msg_error "No ${APP} Installation Found!" exit fi - msg_info "Stopping ${APP}" - systemctl stop pocketbase - msg_ok "Stopped ${APP}" - msg_info "Updating ${APP}" - /opt/pocketbase/pocketbase update - msg_ok "Updated ${APP}" + RELEASE=$(curl -s https://api.github.com/repos/pocketbase/pocketbase/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + if [[ "${RELEASE}" != "$(cat ~/.pocketbase 2>/dev/null)" ]] || [[ ! -f ~/.pocketbase ]]; then + msg_info "Stopping ${APP}" + systemctl stop pocketbase + msg_ok "Stopped ${APP}" - msg_info "Starting ${APP}" - systemctl start pocketbase - msg_ok "Started ${APP}" - msg_ok "Updated Successfully" + msg_info "Updating ${APP}" + /opt/pocketbase/pocketbase update + echo "${RELEASE}" > ~/.pocketbase + msg_ok "Updated ${APP}" + + msg_info "Starting ${APP}" + systemctl start pocketbase + msg_ok "Started ${APP}" + + msg_ok "Update Successful" + else + msg_ok "No update required. ${APP} is already at ${RELEASE}" + fi exit } @@ -49,4 +57,4 @@ 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}" \ No newline at end of file +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8080/_/${CL}" diff --git a/install/pocketbase-install.sh b/install/pocketbase-install.sh index d4929f9fd..fba52a658 100644 --- a/install/pocketbase-install.sh +++ b/install/pocketbase-install.sh @@ -13,12 +13,13 @@ setting_up_container network_check update_os -msg_info "Installing Pocketbase" -RELEASE="$(curl -fsSL https://api.github.com/repos/pocketbase/pocketbase/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')" -curl -fsSL "https://github.com/pocketbase/pocketbase/releases/download/v${RELEASE}/pocketbase_${RELEASE}_linux_amd64.zip" -o "/tmp/pocketbase.zip" -mkdir -p /opt/pocketbase/{pb_public,pb_migrations,pb_hooks} -$STD unzip -o /tmp/pocketbase.zip -d /opt/pocketbase +fetch_and_deploy_gh_release "pocketbase" "pocketbase/pocketbase" "prebuild" "latest" "/opt/pocketbase" "pocketbase*linux_amd64.zip" +msg_info "Configuring Pocketbase" +mkdir -p /opt/pocketbase/{pb_public,pb_migrations,pb_hooks} +msg_ok "Configured Pocketbase" + +msg_info "Creating service" cat </etc/systemd/system/pocketbase.service [Unit] Description = pocketbase @@ -35,15 +36,13 @@ ExecStart = /opt/pocketbase/pocketbase serve --http=0.0.0.0:8080 [Install] WantedBy = multi-user.target EOF - systemctl enable -q --now pocketbase -msg_ok "Installed Pocketbase" +msg_ok "Service created" motd_ssh customize msg_info "Cleaning up" -rm -rf /tmp/pocketbase.zip $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"