From 5cf7606f6e910fa761e9b2222e1caf61b278b369 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 5 May 2022 20:01:19 -0400 Subject: [PATCH] First pass at the new check for updates function. --- audiogame-manager.sh | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/audiogame-manager.sh b/audiogame-manager.sh index ff1e70c..0eb2593 100755 --- a/audiogame-manager.sh +++ b/audiogame-manager.sh @@ -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.