Pastery

mushya +

declare -A binaries
binaries[rg]="BurntSushi/ripgrep"
binaries[fd]="sharkdp/fd"

for binary in "${!binaries[@]}"
do
    curvers=
    if command -V $binary > /dev/null 2>&1; then
        curvers="$($binary -V | cut -d' ' -f2 | sed 's/^v//')"
    fi
    latesturl="https://api.github.com/repos/${binaries[$binary]}/releases/latest"
    latestvers="$(curl -s "$latesturl" | jq -r .tag_name | sed 's/^v//')"
    if [ "$curvers" = "$latestvers" ]; then
        echo "${binary} ${curvers} is up to date"
        continue
    fi

    url=$(curl -s https://api.github.com/repos/${binaries[$binary]}/releases/latest | jq -r '.["assets"] | map(.["browser_download_url"]) | map(select(. | match("amd64.deb")))[0]')
    name=${url##*/}
    (cd /tmp && curl -LO "$url" && sudo dpkg -i "$name")
    echo "${binary} updated from $curvers to $latestvers"
done
New paste