From cfd79f06e166e80ba308f1a3796513d388e36591 Mon Sep 17 00:00:00 2001 From: Eideen Date: Tue, 23 Apr 2019 22:19:09 +0200 Subject: [PATCH 1/9] add download xz file save (40%) and use sha256 --- settings.py | 6 ++++-- updater.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/settings.py b/settings.py index 7dfcb83..8554105 100644 --- a/settings.py +++ b/settings.py @@ -13,8 +13,10 @@ gtgithubapiurl = 'https://api.github.com/repos/go-gitea/gitea/releases/latest' # Gitea System gtsystem = 'linux-amd64' # Name and Path of gitea file -gtfile = '/home/git/gitea' +gtfile = '/usr/local/bin/gitea' +# tmp Name and Path of gitea file +tmpdir = '/tmp/' # Build new version from source? build_from_source = None # Source directroy -source_dir = '/home/git/go/src/code.gitea.io/gitea' \ No newline at end of file +source_dir = '/home/git/go/src/code.gitea.io/gitea' diff --git a/updater.py b/updater.py index f0e95a3..ccd1d83 100644 --- a/updater.py +++ b/updater.py @@ -17,6 +17,7 @@ def download(url, file_name): # get request response = requests.get(url) # write to file + print ("writing file", file_name) file.write(response.content) # Function to build the new version from source @@ -36,18 +37,19 @@ def buildFromSource(tag): # Version from gitea site current_version = requests.get(settings.gtsite).json()['version'] - +print ("current_version =", current_version) # Get version tag from github and remove first char (v) github_version_tag = requests.get(settings.gtgithubapiurl).json()['tag_name'] - +print ("github_version_tag =", github_version_tag) # Get version from version tag github_version = github_version_tag[1:] - # Check if there is a new version if github_version > current_version: + # Stop systemd service - os.system("systemctl stop gitea.service") + print ("new version available, stopping service") + #os.system("systemctl stop gitea.service") # Should the new version be build from source? if settings.build_from_source: @@ -55,12 +57,50 @@ if github_version > current_version: buildFromSource(github_version_tag) else: - # Set download url - gtdownload = 'https://github.com/go-gitea/gitea/releases/download/'+github_version_tag+'/gitea-'+github_version+'-'+settings.gtsystem + ## main file + gtdownload = 'https://github.com/go-gitea/gitea/releases/download/'+github_version_tag+'/gitea-'+github_version+'-'+settings.gtsystem+'.xz' + print (gtdownload) + ## sha256 file + shadownload = 'https://github.com/go-gitea/gitea/releases/download/'+github_version_tag+'/gitea-'+github_version+'-'+settings.gtsystem+'.xz.sha256' + print (shadownload) # Download file - download(gtdownload, settings.gtfile) + + ## downloading sha + print ("downloading sha256 hashsum") + download(shadownload, settings.tmpdir+'gitea.xz.sha256') + ## downloading xz + print ("downloading", github_version_tag+'gitea.xz') + tmpxz = settings.tmpdir+'gitea-'+github_version+'-'+settings.gtsystem+'.xz' + download(gtdownload, tmpxz) + + # doing sha256 sum + os.chdir(settings.tmpdir) + #sha_value = os.system("sha256sum -c gitea.xz.sha256 > /dev/null") + + if os.system("sha256sum -c gitea.xz.sha256 > /dev/null") == 0: + print ("sha ok, extracting file to location") + # extracting download file + cmd = "xz -d "+tmpxz + print (cmd) + os.system(cmd) + # moving temp file to gtfile location + cmd = 'mv '+settings.tmpdir+'gitea-'+github_version+'-'+settings.gtsystem+' '+settings.gtfile + print (cmd) + os.system(cmd) + else: + print ("error") + quit() # Start systemd service + print ("starting gitea.service") os.system("systemctl start gitea.service") + + print ("update successfully") + + +else: + + #Print current version is uptodate + print ("current version is uptodate") From 01796aa02456efd8329185fc9bc3023d257bdc1d Mon Sep 17 00:00:00 2001 From: Eideen Date: Tue, 23 Apr 2019 22:35:26 +0200 Subject: [PATCH 2/9] add check for xz --- updater.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/updater.py b/updater.py index ccd1d83..f532601 100644 --- a/updater.py +++ b/updater.py @@ -10,6 +10,7 @@ import settings import requests import os + # Function to download a file def download(url, file_name): # open in binary mode @@ -35,6 +36,18 @@ def buildFromSource(tag): # Move binary os.system("mv gitea "+settings.gtfile) +def is_tool(name): + ##Check whether `name` is on PATH and marked as executable. + + # from whichcraft import which + from shutil import which + + return which(name) is not None + +if not is_tool("xz"): + print ("missing dependency: xz") + quit() + # Version from gitea site current_version = requests.get(settings.gtsite).json()['version'] print ("current_version =", current_version) From f16583749fc65072e1c0c24193452c29d1ecc084 Mon Sep 17 00:00:00 2001 From: Eideen Date: Sun, 19 May 2019 12:10:26 +0200 Subject: [PATCH 3/9] removed comment from debuging. --- updater.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updater.py b/updater.py index f532601..3508711 100644 --- a/updater.py +++ b/updater.py @@ -62,7 +62,7 @@ if github_version > current_version: # Stop systemd service print ("new version available, stopping service") - #os.system("systemctl stop gitea.service") + os.system("systemctl stop gitea.service") # Should the new version be build from source? if settings.build_from_source: From 750bb6cb3a10b1a43585742a3908219a1ae80457 Mon Sep 17 00:00:00 2001 From: Eideen Date: Sun, 19 May 2019 12:40:29 +0200 Subject: [PATCH 4/9] removed merge text --- updater.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/updater.py b/updater.py index 346eba6..9dd2eb2 100644 --- a/updater.py +++ b/updater.py @@ -9,7 +9,6 @@ License: GNU General Public License import settings import requests import os -<<<<<<< HEAD # Function to download a file @@ -36,9 +35,6 @@ def buildFromSource(tag): os.system('TAGS="bindata sqlite sqlite_unlock_notify" make generate build') # Move binary os.system("mv gitea "+settings.gtfile) -======= -import functions ->>>>>>> 38e9451f8a230c9110e7b43f34cd64f375858f71 def is_tool(name): ##Check whether `name` is on PATH and marked as executable. @@ -83,7 +79,6 @@ if functions.checkVersion(github_version, current_version): print (shadownload) # Download file -<<<<<<< HEAD ## downloading sha print ("downloading sha256 hashsum") @@ -110,9 +105,6 @@ if functions.checkVersion(github_version, current_version): else: print ("error") quit() -======= - functions.download(gtdownload, settings.gtfile) ->>>>>>> 38e9451f8a230c9110e7b43f34cd64f375858f71 # Start systemd service print ("starting gitea.service") From cb4a36b9a21ce7f04df3f56b2704ceec71b9245e Mon Sep 17 00:00:00 2001 From: Eideen Date: Sun, 19 May 2019 12:47:20 +0200 Subject: [PATCH 5/9] Merge update.py --- updater.py | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/updater.py b/updater.py index 9dd2eb2..0e678b1 100644 --- a/updater.py +++ b/updater.py @@ -9,35 +9,10 @@ License: GNU General Public License import settings import requests import os - - -# Function to download a file -def download(url, file_name): - # open in binary mode - with open(file_name, "wb") as file: - # get request - response = requests.get(url) - # write to file - print ("writing file", file_name) - file.write(response.content) - -# Function to build the new version from source -def buildFromSource(tag): - # Change to source dir - os.chdir(settings.source_dir) - # Checkout master - os.system("git checkout master") - # Update - os.system("git pull") - # Checkout relase branch - os.system("git checkout "+tag) - # Build from source - os.system('TAGS="bindata sqlite sqlite_unlock_notify" make generate build') - # Move binary - os.system("mv gitea "+settings.gtfile) +import functions def is_tool(name): - ##Check whether `name` is on PATH and marked as executable. + ##Check whether `name` is on PATH and marked as executable. # from whichcraft import which from shutil import which From bbfc7213130cb47c0e08557d972931cc29e88f1b Mon Sep 17 00:00:00 2001 From: Eideen Date: Sun, 19 May 2019 13:07:34 +0200 Subject: [PATCH 6/9] Moved is_tool to functions --- functions.py | 10 ++++++++++ updater.py | 10 +--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/functions.py b/functions.py index 770322e..ebc3e20 100644 --- a/functions.py +++ b/functions.py @@ -30,6 +30,7 @@ def buildFromSource(tag): def getVersionList(string): return list(map(int, string.split('.'))) +string.split # Function to check if there is a new version def checkVersion(new_version, old_version): new_version_list = getVersionList(new_version) @@ -40,3 +41,12 @@ def checkVersion(new_version, old_version): return True return None + +# Function to check if tool is available +def is_tool(name): + ##Check whether `name` is on PATH and marked as executable. + + # from whichcraft import which + from shutil import which + + return which(name) is not None diff --git a/updater.py b/updater.py index 0e678b1..35e112d 100644 --- a/updater.py +++ b/updater.py @@ -11,15 +11,7 @@ import requests import os import functions -def is_tool(name): - ##Check whether `name` is on PATH and marked as executable. - - # from whichcraft import which - from shutil import which - - return which(name) is not None - -if not is_tool("xz"): +if not functions.is_tool("xz"): print ("missing dependency: xz") quit() From bcc902db765e5f8c0165af883b177c450dfb6424 Mon Sep 17 00:00:00 2001 From: Eideen Date: Sun, 19 May 2019 13:08:24 +0200 Subject: [PATCH 7/9] fix typo. --- functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.py b/functions.py index ebc3e20..06a69f4 100644 --- a/functions.py +++ b/functions.py @@ -30,7 +30,7 @@ def buildFromSource(tag): def getVersionList(string): return list(map(int, string.split('.'))) -string.split + # Function to check if there is a new version def checkVersion(new_version, old_version): new_version_list = getVersionList(new_version) From a4fa04c035d2e159e93b85d8cee9c24b087cb4b8 Mon Sep 17 00:00:00 2001 From: Eideen Date: Sun, 19 May 2019 14:09:10 +0200 Subject: [PATCH 8/9] Update updater.py Co-Authored-By: Christoph Daniel Miksche --- updater.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updater.py b/updater.py index 35e112d..bf2e311 100644 --- a/updater.py +++ b/updater.py @@ -49,7 +49,7 @@ if functions.checkVersion(github_version, current_version): ## downloading sha print ("downloading sha256 hashsum") - download(shadownload, settings.tmpdir+'gitea.xz.sha256') + functions.download(shadownload, settings.tmpdir+'gitea.xz.sha256') ## downloading xz print ("downloading", github_version_tag+'gitea.xz') tmpxz = settings.tmpdir+'gitea-'+github_version+'-'+settings.gtsystem+'.xz' From 8c931c6cb3a755f68f3c0b7c8dc43295016279c6 Mon Sep 17 00:00:00 2001 From: Eideen Date: Sun, 19 May 2019 14:09:19 +0200 Subject: [PATCH 9/9] Update updater.py Co-Authored-By: Christoph Daniel Miksche --- updater.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updater.py b/updater.py index bf2e311..d855ac2 100644 --- a/updater.py +++ b/updater.py @@ -53,7 +53,7 @@ if functions.checkVersion(github_version, current_version): ## downloading xz print ("downloading", github_version_tag+'gitea.xz') tmpxz = settings.tmpdir+'gitea-'+github_version+'-'+settings.gtsystem+'.xz' - download(gtdownload, tmpxz) + functions.download(gtdownload, tmpxz) # doing sha256 sum os.chdir(settings.tmpdir)