From 4f569c67ebae2ff80b63985ee90a537d1215366c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Wed, 9 Jul 2025 07:42:06 +0200 Subject: [PATCH] Refactor (#5849) --- ct/gatus.sh | 16 +++++----------- install/gatus-install.sh | 15 +++------------ 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/ct/gatus.sh b/ct/gatus.sh index ee361ba17..b4c85b3bb 100644 --- a/ct/gatus.sh +++ b/ct/gatus.sh @@ -29,35 +29,29 @@ function update_script() { exit fi RELEASE=$(curl -s https://api.github.com/repos/TwiN/gatus/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') - if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then + if [[ "${RELEASE}" != "$(cat ~/.gatus 2>/dev/null)" ]] || [[ ! -f ~/.gatus ]]; then msg_info "Updating $APP" msg_info "Stopping $APP" systemctl stop gatus msg_ok "Stopped $APP" - msg_info "Updating $APP to v${RELEASE}" mv /opt/gatus/config/config.yaml /opt - rm -rf /opt/gatus/* - temp_file=$(mktemp) - curl -fsSL "https://github.com/TwiN/gatus/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file" - tar zxf "$temp_file" --strip-components=1 -C /opt/gatus + rm -rf /opt/gatus + fetch_and_deploy_gh_release "gatus" "TwiN/gatus" + + msg_info "Updating $APP to v${RELEASE}" cd /opt/gatus $STD go mod tidy CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o gatus . setcap CAP_NET_RAW+ep gatus mv /opt/config.yaml config - echo "${RELEASE}" >/opt/${APP}_version.txt msg_ok "Updated $APP to v${RELEASE}" msg_info "Starting $APP" systemctl start gatus msg_ok "Started $APP" - msg_info "Cleaning Up" - rm -f "$temp_file" - msg_ok "Cleanup Completed" - msg_ok "Update Successful" else msg_ok "No update required. ${APP} is already at v${RELEASE}" diff --git a/install/gatus-install.sh b/install/gatus-install.sh index 3b5cd563b..ea3e75d45 100644 --- a/install/gatus-install.sh +++ b/install/gatus-install.sh @@ -20,20 +20,15 @@ $STD apt-get install -y \ msg_ok "Installed Dependencies" setup_go +fetch_and_deploy_gh_release "gatus" "TwiN/gatus" -RELEASE=$(curl -s https://api.github.com/repos/TwiN/gatus/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') -msg_info "Setting up gatus v${RELEASE}" -temp_file=$(mktemp) -mkdir -p /opt/gatus -curl -fsSL "https://github.com/TwiN/gatus/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file" -tar zxf "$temp_file" --strip-components=1 -C /opt/gatus +msg_info "Configuring gatus" cd /opt/gatus $STD go mod tidy CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o gatus . setcap CAP_NET_RAW+ep gatus mv config.yaml config -echo "${RELEASE}" >/opt/gatus_version.txt -msg_ok "Done setting up gatus" +msg_ok "Configured gatus" msg_info "Creating Service" cat </etc/systemd/system/gatus.service @@ -58,10 +53,6 @@ motd_ssh customize msg_info "Cleaning up" -rm -f "$temp_file" $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned" - -motd_ssh -customize