1
0
mirror of https://github.com/CMiksche/gitea-auto-update synced 2025-12-10 07:57:23 +01:00

fix: file structure

This commit is contained in:
Christoph Miksche
2019-08-26 22:46:46 +02:00
parent 8b64d5f518
commit 05caef9d41
9 changed files with 20 additions and 16 deletions

View File

View File

@@ -0,0 +1,24 @@
'''
Gitea Auto Updater
Copyright 2018, 2019 The Gitea-Auto-Update Authors
All rights reserved.
License: GNU General Public License
'''
import os
class Build:
def __init__(self, gtFile, sourceDir):
self.gtFile = gtFile
self.sourceDir = sourceDir
def fromSource(self, tag):
# Function to build the new version from source
os.chdir(self.sourceDir)
os.system("git checkout master")
os.system("git pull")
os.system("git checkout " + tag)
os.system('TAGS="bindata sqlite sqlite_unlock_notify" make generate build')
os.system("mv gitea " + self.gtFile)

View File

@@ -0,0 +1,77 @@
'''
Gitea Auto Updater
Copyright 2018, 2019 The Gitea-Auto-Update Authors
All rights reserved.
License: GNU General Public License
'''
import requests
import os
import logging
from shutil import which # from whichcraft import which
class Download:
def __init__(self, tmpDir, githubVersion, githubVersionTag, gtSystem, gtFile):
if not self.isTool("xz"):
logging.error('Download: missing dependency: xz')
quit()
self.tmpDir = tmpDir
self.githubVersion = githubVersion
self.githubVersionTag = githubVersionTag
self.gtSystem = gtSystem
self.gtFile = gtFile
self.downloadGiteaFiles()
self.checkAndExtract()
def isTool(name):
# Function to check if tool is available
##Check whether `name` is on PATH and marked as executable.
return which(name) is not None
def download(self, url, fileName):
# Function to download a file
# open in binary mode
with open(fileName, "wb") as file:
# get request
response = requests.get(url)
# write to file
file.write(response.content)
def downloadGiteaFiles(self):
# Set download url
gtDownload = 'https://github.com/go-gitea/gitea/releases/download/' + self.githubVersionTag + '/gitea-' + self.githubVersion + '-' + self.gtSystem + '.xz'
logging.info('Download: Gitea file: %s', gtDownload)
shaDownload = gtDownload + '.sha256'
logging.info('Download: SHA file: %s', shaDownload)
# Download file
logging.info('Download: downloading sha256 hashsum')
self.download(shaDownload, self.tmpDir + 'gitea.xz.sha256')
logging.info('Download: downloading %s', self.githubVersionTag + 'gitea.xz')
self.tmpXz = self.tmpDir +'gitea-' + self.githubVersion + '-' + self.gtSystem + '.xz'
self.download(gtDownload, self.tmpXz)
def shaCheck(self):
return os.system("sha256sum -c gitea.xz.sha256 > /dev/null") == 0
def extractFile(self):
logging.info('Download: sha ok, extracting file to location')
# extracting download file
cmd = "xz -d " + self.tmpXz
os.system(cmd)
# moving temp file to gtfile location
cmd = 'mv ' + self.tmpDir + 'gitea-' + self.githubVersion + '-' + self.gtSystem + ' ' + self.gtFile
os.system(cmd)
def checkAndExtract(self):
os.chdir(self.tmpDir)
if self.shaCheck():
self.extractFile()
else:
logging.error('Download: error: sha256sum failed')
quit()

View File

@@ -0,0 +1,48 @@
'''
Gitea Auto Updater
Copyright 2018, 2019 The Gitea-Auto-Update Authors
All rights reserved.
License: GNU General Public License
'''
from packaging import version
import os
import requests
import logging
class Version:
def __init__(self, gtSite, gtFile):
self.gtSite = gtSite
self.gtFile = gtFile
def checkVersion(self, newVersion, oldVersion):
# Function to check if there is a new version
return version.parse(newVersion) > version.parse(oldVersion)
def parseFileVersion(self, string):
return string.split(" ")[2]
def getVersionFromFile(self):
versionString = os.popen(self.gtFile + " -v").read()
return self.parseFileVersion(versionString)
def getCurrentVersion(self):
# Function to get the current version
try:
# Try to get the version from the file
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()
finally:
logging.info('Version: current_version = %s', currentVersion)
return currentVersion
def getGithubVersionTag(self, apiUrl):
versionTag = requests.get(apiUrl).json()['tag_name']
logging.info('Version: github_version_tag = %s', versionTag)
return versionTag