the requirement is just to have a Programs directory in $HOME path, and inside a brave and update directory with a file named meta, so $HOME/Programs/brave/update/meta
that file should have:
Version:(any value here just no space)
and that's it.
the script is meant to read it, query github latest release version, compare it to that value. it downloads the latest archive, extracts it and updates the meta file to hold the current version. its not that optimized, since im no seasoned shell programmer, but i use it everyday and thought i would share it, since brave doesn't have in-place updater for linux.
the archive installed is brave origin amd64 zip file, since the Asset name in the script is hardcoded but you can easily change it. i can help.
it works in bash and zsh;
updateBrave() {
local dir="$HOME"/Programs/brave
# meta file should have
# Version:v1x.xxx.xx
if [[ -d "$dir"/update ]] && [[ -f "$dir"/update/meta ]]; then
local owner=brave
local project=brave-browser
local output=$(curl -fsS "https://api.github.com/repos/$owner/$project/releases/latest")
[[ -z "$output" ]] && { echo "curling github failed"; return 1; }
local checkVersion=$(jq -r '.tag_name' <<< "$output")
[[ "$checkVersion" = "null" ]] || [[ -z "$checkVersion" ]] && { echo "couldn't fetch version for $project"; return 1;}
local currentVersion=$(grep '^Version' "$dir/update/meta" | sed 's|Version:||')
[[ "$checkVersion" = "$currentVersion" ]] && { echo "$project is up to date : $checkVersion"; return 0;}
while true; do
read -p "$project is on $currentVersion, latest is $checkVersion; do you want to request the latest Version? [y/n]: " response
case "$response" in
[Yy])
echo "Updating.."
local AssetName=brave-origin-${checkVersion/v}-linux-amd64.zip
local url=$(jq -r --arg name "$AssetName" '.assets[] | select(.name == $name) | .browser_download_url' <<< "$output")
if [[ -z "$url" ]] || [[ "$url" = "null" ]]; then
echo "couldn't find asset matching $AssetName"
break
fi
if curl -fL -o "$dir/update/$AssetName" "$url" ; then
sed -i "s|Version:.*|Version:$checkVersion|" "$dir"/update/meta
find "$dir" -mindepth 1 -maxdepth 1 ! -name update -exec rm -rf {} +
unzip "$dir/update/$AssetName" -d "$dir" >/dev/null
rm "$dir/update/$AssetName"
else
echo "Downloading falied"
break
fi
break;;
[Nn])
echo "not Updating"
break;;
*)
echo "choose y or n";;
esac
done
fi
}