Last active
September 4, 2023 23:11
-
-
Save shvchk/5c2b311a4ba7e2ee07508d342fad4bcb to your computer and use it in GitHub Desktop.
Script to update rustdesk from the official repo releases page. Run with `sudo`, since it uses `apt install`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
set -euo pipefail | |
repo="rustdesk/rustdesk" | |
release_url="https://api.github.com/repos/$repo/releases/latest" | |
cur_version=$(rustdesk --version) | |
new_version=$(curl -fsSL "$release_url" | jq -r '.tag_name') | |
tmp_dir=$(mktemp -d) | |
case "$(uname -m)" in | |
x86_64) arch="x86_64" ;; | |
arm64) arch="aarch64" ;; | |
*) echo "Unsupported architecture: $(uname -m). Aborting"; exit 1 ;; | |
esac | |
_update() { | |
jq_expr=".assets[].browser_download_url | select(endswith(\"${arch}.deb\"))" | |
link="$(curl -fsSL "$release_url" | jq -r "$jq_expr")" | |
archive_path="${tmp_dir}/$(basename -- "$link")" | |
curl -fsSL -o "$archive_path" "$link" | |
apt install "$archive_path" -y | |
} | |
_is_version_newer() { | |
! printf '%s\n' "$1" "$2" | sort -CV | |
} | |
_cleanup() { | |
rm -rf "$tmp_dir" | |
} | |
trap _cleanup EXIT | |
if _is_version_newer "$new_version" "$cur_version"; then | |
echo "New version found, upgrading..." | |
_update | |
else | |
echo "No new version found" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment