Last active
March 15, 2025 16:37
-
-
Save Delnegend/f4cef1c053123823aa648c080e128294 to your computer and use it in GitHub Desktop.
Check update for apps I downloaded directly instead of through a package manager
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
#!/bin/zsh | |
# return the latest TAG version from GitHub repo (usually include "v" prefix) | |
get_github_latest_tag() { | |
local repo_path=$1 | |
curl -s -I -L "https://github.com/$repo_path/releases/latest" | \ | |
grep -i "^location" | \ | |
tail -n1 | \ | |
sed -E 's|.*/tag/([^/]+)$|\1|' | \ | |
tr -d '\r' | |
} | |
is_url_alive() { | |
local url=$1 | |
local status_code=$(curl -s -o /dev/null -w "%{http_code}" "$url") | |
# Consider 2xx and 3xx status codes as "alive" | |
if [[ $status_code -ge 200 && $status_code -lt 400 ]]; then | |
return 0 # URL is alive | |
else | |
return 1 # URL is not alive | |
fi | |
} | |
check_gh_update() { | |
local command=$1 | |
local repo_path=$2 | |
local version_extract_cmd=$3 | |
local file_name=$4 | |
if [[ ! -x "$(command -v $command)" ]]; then | |
return | |
fi | |
local curr_ver=$(eval "$version_extract_cmd") | |
local latest_tag=$(get_github_latest_tag "$repo_path") | |
local latest_ver=$(echo "$latest_tag" | sed -E 's/^v//g') | |
if [[ "$file_name" =~ "<VERSION>" ]]; then | |
file_name=${file_name//<VERSION>/$latest_ver} | |
fi | |
if [[ "$curr_ver" != "$latest_ver" ]]; then | |
local direct_dl_link="https://github.com/$repo_path/releases/download/$latest_tag/$file_name" | |
if is_url_alive "$direct_dl_link"; then | |
echo "$command: $curr_ver -> $latest_ver" | |
echo -e " - π \033[32m$direct_dl_link\033[0m" | |
echo | |
else | |
echo "$command: $curr_ver -> $latest_ver" | |
echo -e " - π \033[33mhttps://github.com/$repo_path/releases/latest\033[0m" | |
echo | |
fi | |
else | |
echo "$command: up to date\n" | |
fi | |
} | |
check_gh_update "fastfetch" "fastfetch-cli/fastfetch" "fastfetch --version | head -n1 | sed -E 's|.* ([0-9.]+).*|\1|'" "fastfetch-linux-amd64.zip" | |
check_gh_update "onefetch" "o2sh/onefetch" "onefetch --version | head -n1 | sed -E 's|.* ([0-9.]+).*|\1|'" "onefetch-linux.tar.gz" | |
check_gh_update "fzf" "junegunn/fzf" "fzf --version | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+).*/\1/'" "fzf-<VERSION>-linux_amd64.tar.gz" | |
check_gh_update "just" "casey/just" "just --version | head -n1 | sed -E 's|.* ([0-9.]+).*|\1|'" "just-<VERSION>-x86_64-unknown-linux-musl.tar.gz" | |
check_gh_update "lazygit" "jesseduffield/lazygit" "lazygit --version | grep -oP 'version=\K[0-9.]+' | head -n1" "lazygit_<VERSION>_Linux_x86_64.tar.gz" | |
check_gh_update "lazydocker" "jesseduffield/lazydocker" "lazydocker --version | grep -oP 'Version: \K[0-9.]+' | head -n1" "lazydocker_<VERSION>_Linux_x86_64.tar.gz" | |
check_ncdu() { | |
local current_version=$(ncdu --version | sed -E 's/ncdu ([0-9.]+)/\1/') | |
local latest_version=$(curl -s "https://dev.yorhel.nl/ncdu" | grep -oP '/download/ncdu-\K[0-9.]+(?=-linux-x86_64\.tar\.gz)' | head -n1) | |
local direct_dl_link="https://dev.yorhel.nl/download/ncdu-$latest_version-linux-x86_64.tar.gz" | |
local page_to_dl_link="https://dev.yorhel.nl/ncdu" | |
if [[ ! -x "$(command -v ncdu)" ]]; then | |
return | |
fi | |
if [[ "$current_version" != "$latest_version" ]]; then | |
if is_url_alive "$direct_dl_link"; then | |
echo "ncdu: $current_version -> $latest_version" | |
echo " - π \033[32m$direct_dl_link\033[0m" | |
echo | |
else | |
echo "ncdu: $current_version -> $latest_version" | |
echo " - π \033[33m$page_to_dl_link\033[0m" | |
echo | |
fi | |
else | |
echo "ncdu: up to date\n" | |
fi | |
} | |
check_ncdu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment