From 3488d83af471462d686ff9d04dc645aa4b782634 Mon Sep 17 00:00:00 2001 From: Jeremy R Date: Sat, 23 Sep 2023 00:06:07 -0400 Subject: [PATCH 1/2] Create Update.sh I noticed you do not have an auto update script for us linux users so I went and created one for you. It a simple bash file that can take 3 arguments Update.sh = Checks to see if there is an update, if yes update Update.sh -update = Same as above Update.sh -force = Will update regardless if its needed or not Update.sh -check = Will check for an update, and prompt you if you want to update or not. --- Because there was not an easy way (that I knew of) to get the current version (maybe have an API or file with the version number) It will one first attempt assume its outdated. After the initial update, it will create a folder + file in the rdtcs root folder called .installed/version.txt and store the installed version in the text. It will then start comparing the latest github version to whats in the file. When it updates, it will check for the latest version using github's API and grab the version and download link from there. Afterwards, it will then 1. download the zip file 2. Stop the rdtc service 3. Backup the config and DB to .backup 4. Unzip the latest version 5. Update the version.txt file 6. Restore backup 7. Restart rdtc Would most likely be best to set a cron to run it on a set schedule either daily or weekly. If there is no update it will just exit, otherwise its fully automated. --- Update.sh | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Update.sh diff --git a/Update.sh b/Update.sh new file mode 100644 index 0000000..8a04b63 --- /dev/null +++ b/Update.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +# Define paths and URLs +INSTALL_DIR="/opt/rdtc" +INSTALLED_DIR="$INSTALL_DIR/.installed" +INSTALLED_FILE="$INSTALLED_DIR/version.txt" +BACKUP_DIR="$INSTALL_DIR/.backup" +GITHUB_API_URL="https://api.github.com/repos/rogerfar/rdt-client/releases/latest" +DOWNLOAD_URL=$(curl -s "$GITHUB_API_URL" | jq -r '.assets[0].browser_download_url') + +# Function to check if a newer version is available +check_for_update() { + local current_version + if [ -f "$INSTALLED_FILE" ]; then + current_version=$(cat "$INSTALLED_FILE") + else + mkdir -p $INSTALLED_DIR + current_version="0.0.0" + fi + + latest_version=$(curl -s "$GITHUB_API_URL" | jq -r '.name' | tr -d v) + + if [[ "$1" == "-force" ]]; then + update + fi + + if [[ "$current_version" == "$latest_version" ]]; then + echo "The installed version ($current_version) is up to date." + else + echo "A newer version ($latest_version) is available." + if [[ "$1" == "-update" ]]; then + update + elif [[ "$1" == "-check" ]]; then + read -p "Do you want to update? (Y/n): " choice + case "$choice" in + [Yy]*) + update + ;; + *) + echo "Update canceled." + ;; + esac + fi + fi +} + +# Function to update the software +update() { + echo "Updating RealDebridClient..." + + # Download the latest zip file + echo "Downloading Lastest RealDebridClient" + curl -sLO "$DOWNLOAD_URL" + + # Stop the rdtc service + echo "Stopping RealDebridClient" + sudo systemctl stop rdtc + + echo "Backing up RealDebridClient" + cp $INSTALL_DIR/appsettings.json $BACKUP_DIR + cp -r $INSTALL_DIR/db $BACKUP_DIR + + # Unzip the downloaded file + echo "Unzipping RealDebridClient.zip" + unzip -q -o RealDebridClient.zip -d "$INSTALL_DIR" + + # Store the new version in the installed file + echo "Updating Latest Version file" + echo "$latest_version" > "$INSTALLED_FILE" + + echo "Restoring Backup" + cp $BACKUP_DIR/appsettings.json $INSTALL_DIR + cp -r $BACKUP_DIR/db $INSTALL_DIR + + # Start the rdtc service + echo "Starting RealDebridClient" + sudo systemctl start rdtc + + echo "Update complete." +} + +# Main script +case "$1" in + "-update") + check_for_update "-update" + ;; + "-force") + update + ;; + "-check") + check_for_update "-check" + ;; + "") + check_for_update "-update" + ;; + *) + echo "Usage: $0 {-update|-force|-check}" + exit 1 + ;; +esac + +exit 0 From 3db5cd70601f328579c62051537514de68c32961 Mon Sep 17 00:00:00 2001 From: Jeremy R Date: Fri, 29 Sep 2023 06:22:07 -0400 Subject: [PATCH 2/2] Moved from root to server/RdtClient.Web/ Moved to proper location, next to windows update script --- Update.sh => server/RdtClient.Web/Update.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Update.sh => server/RdtClient.Web/Update.sh (100%) diff --git a/Update.sh b/server/RdtClient.Web/Update.sh similarity index 100% rename from Update.sh rename to server/RdtClient.Web/Update.sh