From ef919883120caae33901e52619e803df9c2e2feb Mon Sep 17 00:00:00 2001 From: Ian Walton Date: Tue, 3 Sep 2019 14:25:44 -0400 Subject: [PATCH 1/4] fix: Fix exception when updating via binary. Attempting to update Gitea using the binary mode results in an exception because `isTool` did not have a `self` parameter. This fixes the issue, allowing binary updates. --- gitea_auto_update/lib/download.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitea_auto_update/lib/download.py b/gitea_auto_update/lib/download.py index 68a8214..f178ad7 100644 --- a/gitea_auto_update/lib/download.py +++ b/gitea_auto_update/lib/download.py @@ -28,7 +28,7 @@ class Download: self.downloadGiteaFiles() self.checkAndExtract() - def isTool(name): + def isTool(self, name): # Function to check if tool is available ##Check whether `name` is on PATH and marked as executable. return which(name) is not None @@ -74,4 +74,4 @@ class Download: self.extractFile() else: logging.error('Download: error: sha256sum failed') - quit() \ No newline at end of file + quit() From 52bf4cb83530c55c28632c6e007bca3444480b73 Mon Sep 17 00:00:00 2001 From: Ian Walton Date: Tue, 3 Sep 2019 14:26:58 -0400 Subject: [PATCH 2/4] fix: Make downloaded binary executable. Current gitea releases do not ship with the binary in the archive executable. This results in the service failing to start after updating. This commit ensures the binary is always executable. --- gitea_auto_update/lib/download.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gitea_auto_update/lib/download.py b/gitea_auto_update/lib/download.py index f178ad7..5f51f0d 100644 --- a/gitea_auto_update/lib/download.py +++ b/gitea_auto_update/lib/download.py @@ -67,6 +67,8 @@ class Download: # moving temp file to gtfile location cmd = 'mv ' + self.tmpDir + 'gitea-' + self.githubVersion + '-' + self.gtSystem + ' ' + self.gtFile os.system(cmd) + cmd = 'chmod +x ' + self.gtFile + os.system(cmd) def checkAndExtract(self): os.chdir(self.tmpDir) From 0005c23b3862a480e135c3361738e20f07b1a4c5 Mon Sep 17 00:00:00 2001 From: Ian Walton Date: Tue, 3 Sep 2019 14:28:35 -0400 Subject: [PATCH 3/4] feat: Handle nonexistent binary. This patches the version component to return a version of 0.0.0 if it fails to detect a version. This allows the update script to install the binary if it does not already exist or is corrupted. --- gitea_auto_update/lib/version.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gitea_auto_update/lib/version.py b/gitea_auto_update/lib/version.py index 8f2c8a5..6c8e60b 100644 --- a/gitea_auto_update/lib/version.py +++ b/gitea_auto_update/lib/version.py @@ -35,9 +35,13 @@ class Version: currentVersion = self.getVersionFromFile() except: # Get the version via the web api if the file does fail - currentVersion = requests.get(self.gtSite).json()['version'] - if currentVersion.status_code != 200: - currentVersion = self.getVersionFromFile() + try: + currentVersion = requests.get(self.gtSite).json()['version'] + if currentVersion.status_code != 200: + raise RuntimeError("Could not download version.") + except: + # To allow installation, return a default version of "0.0.0". + currentVersion = "0.0.0" finally: logging.info('Version: current_version = %s', currentVersion) return currentVersion @@ -45,4 +49,4 @@ class Version: def getGithubVersionTag(self, apiUrl): versionTag = requests.get(apiUrl).json()['tag_name'] logging.info('Version: github_version_tag = %s', versionTag) - return versionTag \ No newline at end of file + return versionTag From bce9a482d7240ed6bdc41409fdc61355d43028b1 Mon Sep 17 00:00:00 2001 From: Ian Walton Date: Tue, 3 Sep 2019 14:31:06 -0400 Subject: [PATCH 4/4] feat: Update README with working configuration. The current configuration in the README does not install the update from the binary. It also instructs the user to use pip instead of pip3, which is the command to install using the script for python2 on most systems. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5d4bbb3..757df8a 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,15 @@ apiUrl=https://api.github.com/repos/go-gitea/gitea/releases/latest system=linux-amd64 file=/usr/local/bin/gitea tmpDir=/tmp/ -buildFromSource=None -sourceDir=/home/git/go/src/code.gitea.io/gitea +buildFromSource= +sourceDir= logFile=update.log ```` Use the following command to install gitea-auto-update. ``` - sudo pip install gitea-auto-update + sudo pip3 install gitea-auto-update ``` Enter the command `gite-auto-update --settings=/path/to/settings.ini` in your commandline.