From 0f29e5672c4d510722e0a0f8f47bfb1b00cb48d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Fri, 1 Aug 2025 07:26:58 +0200 Subject: [PATCH] Refactor: LubeLogger (#6400) --- ct/lubelogger.sh | 24 ++++++++++++++---------- install/lubelogger-install.sh | 18 ++++-------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/ct/lubelogger.sh b/ct/lubelogger.sh index d4f0cf4d9..c899a4640 100644 --- a/ct/lubelogger.sh +++ b/ct/lubelogger.sh @@ -27,16 +27,17 @@ function update_script() { msg_error "No ${APP} Installation Found!" exit fi - RELEASE=$(curl -fsSL https://api.github.com/repos/hargata/lubelog/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') - RELEASE_TRIMMED=$(echo "${RELEASE}" | tr -d ".") - if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + if ! command -v jq &>/dev/null; then + $STD apt-get install -y jq + fi + + RELEASE=$(curl -fsSL https://api.github.com/repos/hargata/lubelog/releases/latest | jq -r '.tag_name' | sed 's/^v//') + if [[ ! -f ~/.lubelogger ]] || [[ "${RELEASE}" != "$(cat ~/.lubelogger)" ]]; then msg_info "Stopping Service" systemctl stop lubelogger msg_ok "Stopped Service" - msg_info "Updating ${APP} to v${RELEASE}" - cd /opt - curl -fsSL "https://github.com/hargata/lubelog/releases/download/v${RELEASE}/LubeLogger_v${RELEASE_TRIMMED}_linux_x64.zip" -o $(basename "https://github.com/hargata/lubelog/releases/download/v${RELEASE}/LubeLogger_v${RELEASE_TRIMMED}_linux_x64.zip") + msg_info "Backing up data" mkdir -p /tmp/lubeloggerData/data cp /opt/lubelogger/appsettings.json /tmp/lubeloggerData/appsettings.json cp -r /opt/lubelogger/data/ /tmp/lubeloggerData/ @@ -50,20 +51,23 @@ function update_script() { [[ -e /opt/lubelogger/wwwroot/temp ]] && cp -r /opt/lubelogger/wwwroot/temp /tmp/lubeloggerData/data/ [[ -e /opt/lubelogger/log ]] && cp -r /opt/lubelogger/log /tmp/lubeloggerData/ rm -rf /opt/lubelogger - $STD unzip LubeLogger_v${RELEASE_TRIMMED}_linux_x64.zip -d lubelogger + msg_ok "Backed up data" + + fetch_and_deploy_gh_release "lubelogger" "hargata/lubelog" "prebuild" "latest" "/opt/lubelogger" "LubeLogger*linux_x64.zip" + + msg_info "Configuring LubeLogger" chmod 700 /opt/lubelogger/CarCareTracker cp -rf /tmp/lubeloggerData/* /opt/lubelogger/ - echo "${RELEASE}" >"/opt/${APP}_version.txt" - msg_ok "Updated ${APP} to v${RELEASE}" + msg_ok "Configured LubeLogger" msg_info "Starting Service" systemctl start lubelogger msg_ok "Started Service" msg_info "Cleaning up" - rm -rf /opt/LubeLogger_v${RELEASE_TRIMMED}_linux_x64.zip rm -rf /tmp/lubeloggerData msg_ok "Cleaned" + msg_ok "Updated Successfully" else msg_ok "No update required. ${APP} is already at v${RELEASE}." diff --git a/install/lubelogger-install.sh b/install/lubelogger-install.sh index d670f5856..5c22b2ec6 100644 --- a/install/lubelogger-install.sh +++ b/install/lubelogger-install.sh @@ -13,23 +13,14 @@ setting_up_container network_check update_os -msg_info "Installing Dependencies" -$STD apt-get install -y jq -msg_ok "Installed Dependencies" +fetch_and_deploy_gh_release "lubelogger" "hargata/lubelog" "prebuild" "latest" "/opt/lubelogger" "LubeLogger*linux_x64.zip" -msg_info "Installing LubeLogger" -cd /opt -mkdir -p /opt/lubelogger -RELEASE=$(curl -fsSL https://api.github.com/repos/hargata/lubelog/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') -RELEASE_TRIMMED=$(echo "${RELEASE}" | tr -d ".") +msg_info "Configuring LubeLogger" cd /opt/lubelogger -curl -fsSL "https://github.com/hargata/lubelog/releases/download/v${RELEASE}/LubeLogger_v${RELEASE_TRIMMED}_linux_x64.zip" -o "LubeLogger_v${RELEASE_TRIMMED}_linux_x64.zip" -$STD unzip LubeLogger_v${RELEASE_TRIMMED}_linux_x64.zip chmod 700 /opt/lubelogger/CarCareTracker cp /opt/lubelogger/appsettings.json /opt/lubelogger/appsettings_bak.json jq '.Kestrel = {"Endpoints": {"Http": {"Url": "http://0.0.0.0:5000"}}}' /opt/lubelogger/appsettings_bak.json >/opt/lubelogger/appsettings.json -echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" -msg_ok "Installed LubeLogger" +msg_ok "Configured LubeLogger" msg_info "Creating Service" cat </etc/systemd/system/lubelogger.service @@ -51,7 +42,7 @@ Restart=on-failure WantedBy=multi-user.target EOF -systemctl enable --now -q lubelogger.service +systemctl enable -q --now lubelogger msg_ok "Created Service" motd_ssh @@ -59,7 +50,6 @@ customize msg_info "Cleaning up" rm -rf /opt/lubelogger/appsettings_bak.json -rm -rf /opt/lubelogger/LubeLogger_v${RELEASE_TRIMMED}_linux_x64.zip $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"