From 849c43f85a2287d58ca1206e4b311bacfaed639d Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Tue, 27 May 2025 16:14:34 +0200 Subject: [PATCH] optimize backrest --- ct/backrest.sh | 17 +++++++++++------ install/backrest-install.sh | 11 +++++------ misc/tools.func | 9 +++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/ct/backrest.sh b/ct/backrest.sh index c69d359..6822dab 100644 --- a/ct/backrest.sh +++ b/ct/backrest.sh @@ -34,18 +34,23 @@ function update_script() { msg_ok "Stopped ${APP}" msg_info "Updating ${APP} to ${RELEASE}" - cd /opt/backrest/bin - curl -fsSL "https://github.com/garethgeorge/backrest/releases/download/v${RELEASE}/backrest_Linux_x86_64.tar.gz" -o "backrest_Linux_x86_64.tar.gz" - tar -xzf backrest_Linux_x86_64.tar.gz - rm -rf backrest_Linux_x86_64.tar.gz - rm -f install.sh uninstall.sh - chmod +x backrest + temp_file=$(mktemp) + rm -f /opt/backrest/bin/backrest + curl -fsSL "https://github.com/garethgeorge/backrest/releases/download/v${RELEASE}/backrest_Linux_x86_64.tar.gz" -o "$temp_file" + tar zxf "$temp_file" --strip-components=1 -C /opt/backrest/bin + chmod +x /opt/backrest/bin/backrest echo "${RELEASE}" >/opt/${APP}_version.txt msg_ok "Updated ${APP} to ${RELEASE}" msg_info "Starting ${APP}" systemctl start backrest msg_ok "Started ${APP}" + + msg_info "Cleaning up" + rm -f "$temp_file" + apt-get -y autoremove + apt-get -y autoclean + msg_ok "Cleaned up" msg_ok "Updated Successfully" else msg_ok "No update required. ${APP} is already at ${RELEASE}" diff --git a/install/backrest-install.sh b/install/backrest-install.sh index 14d7f1a..9d747c1 100644 --- a/install/backrest-install.sh +++ b/install/backrest-install.sh @@ -15,11 +15,11 @@ update_os msg_info "Installing Backrest" RELEASE=$(curl -fsSL https://api.github.com/repos/garethgeorge/backrest/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +temp_file=$(mktemp) mkdir -p /opt/backrest/{bin,config,data} -cd /opt/backrest/bin -curl -fsSL "https://github.com/garethgeorge/backrest/releases/download/v${RELEASE}/backrest_Linux_x86_64.tar.gz" -o "backrest_Linux_x86_64.tar.gz" -tar -xzf backrest_Linux_x86_64.tar.gz -chmod +x backrest +curl -fsSL "https://github.com/garethgeorge/backrest/releases/download/v${RELEASE}/backrest_Linux_x86_64.tar.gz" -o "$temp_file" +tar zxf "$temp_file" --strip-components=1 -C /opt/backrest/bin +chmod +x /opt/backrest/bin/backrest echo "${RELEASE}" >/opt/${APPLICATION}_version.txt msg_ok "Installed Backrest" @@ -48,8 +48,7 @@ motd_ssh customize msg_info "Cleaning up" +rm -f "$temp_file" $STD apt-get -y autoremove $STD apt-get -y autoclean -rm -rf backrest_Linux_x86_64.tar.gz -rm -f install.sh uninstall.sh msg_ok "Cleaned" diff --git a/misc/tools.func b/misc/tools.func index 6ccaa0b..be5e928 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -32,6 +32,15 @@ install_node_and_modules() { NEED_NODE_INSTALL=true fi + if ! command -v jq &>/dev/null; then + $STD msg_info "Installing jq..." + $STD apt-get update -qq &>/dev/null + $STD apt-get install -y jq &>/dev/null || { + msg_error "Failed to install jq" + return 1 + } + fi + # Install Node.js if required if [[ "$NEED_NODE_INSTALL" == true ]]; then $STD apt-get purge -y nodejs