First pass at the new check for updates function.

This commit is contained in:
Storm Dragon 2022-05-05 20:01:19 -04:00
parent 07054de7cb
commit 5cf7606f6e

View File

@ -68,36 +68,21 @@ check_news() {
# Automatic update function
update() {
local filePath="$(command -v ${0})"
if file "${filePath}" | grep -q 'Bourne-Again shell script' ; then
local url="$(git ls-remote --get-url)"
if [[ "$url" =~ ^ssh://|git@ ]] || [[ -z "$url" ]]; then
return
fi
# make sure the site can be reached
ping -c1 stormgames.wolfe.casa &> /dev/null || return
if [[ "$(uname)" == "Darwin" ]]; then
local downloadFile="audiogame-manager.mac"
else
if [[ "$(uname -m)" == "armv7l" ]]; then
local downloadFile="audiogame-manager.arm"
else
local downloadFile="audiogame-manager"
fi
fi
if [[ "$(wget --quiet -O - https://stormgames.wolfe.casa/downloads/${downloadFile} | sha256sum | cut -d ' ' -f1)" == "$(sha256sum "${filePath}" | cut -d ' ' -f1)" ]]; then
return
fi
dialog --backtitle "Audiogame Manager" --yesno "There is a new version of ${0##*/} available.\nDo you want to update now?" -1 -1
if [[ ${?} -eq 0 ]]; then
if [[ -w "$0" ]]; then
wget --quiet -O "${filePath}" "https://stormgames.wolfe.casa/downloads/${downloadFile}"
chmod +x "$0"
else
sudo wget --quiet -O "${filePath}" "https://stormgames.wolfe.casa/downloads/${downloadFile}"
sudo chmod +x "$0"
fi
echo "${0##*/} has been updated. Please launch the program again to use the latest version."
exit 0
fi
git remote update &> /dev/null
local upstream='@{u}'
local home="$(git rev-parse @)"
local remote="$(git rev-parse "$upstream")"
if [[ "$home" == "$remote" ]]; then
return
fi
dialog --backtitle "Audiogame Manager" \
--yesno "Updates are available. Would you like to update now?" -1 -1 --stdout || return
git pull
exit $?
}
# Function to open urls across OS.