mirror of
https://github.com/CMiksche/gitea-auto-update
synced 2025-12-11 08:27:23 +01:00
Merge pull request #5 from Eideen/master
Add support for checksum, change to use zx, made more verbose
This commit is contained in:
10
functions.py
10
functions.py
@@ -30,6 +30,7 @@ def buildFromSource(tag):
|
|||||||
def getVersionList(string):
|
def getVersionList(string):
|
||||||
return list(map(int, string.split('.')))
|
return list(map(int, string.split('.')))
|
||||||
|
|
||||||
|
|
||||||
# Function to check if there is a new version
|
# Function to check if there is a new version
|
||||||
def checkVersion(new_version, old_version):
|
def checkVersion(new_version, old_version):
|
||||||
new_version_list = getVersionList(new_version)
|
new_version_list = getVersionList(new_version)
|
||||||
@@ -40,3 +41,12 @@ def checkVersion(new_version, old_version):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
return None
|
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
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ gtgithubapiurl = 'https://api.github.com/repos/go-gitea/gitea/releases/latest'
|
|||||||
# Gitea System
|
# Gitea System
|
||||||
gtsystem = 'linux-amd64'
|
gtsystem = 'linux-amd64'
|
||||||
# Name and Path of gitea file
|
# 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 new version from source?
|
||||||
build_from_source = None
|
build_from_source = None
|
||||||
# Source directroy
|
# Source directroy
|
||||||
|
|||||||
55
updater.py
55
updater.py
@@ -11,19 +11,24 @@ import requests
|
|||||||
import os
|
import os
|
||||||
import functions
|
import functions
|
||||||
|
|
||||||
|
if not functions.is_tool("xz"):
|
||||||
|
print ("missing dependency: xz")
|
||||||
|
quit()
|
||||||
|
|
||||||
# Version from gitea site
|
# Version from gitea site
|
||||||
current_version = requests.get(settings.gtsite).json()['version']
|
current_version = requests.get(settings.gtsite).json()['version']
|
||||||
|
print ("current_version =", current_version)
|
||||||
# Get version tag from github and remove first char (v)
|
# Get version tag from github and remove first char (v)
|
||||||
github_version_tag = requests.get(settings.gtgithubapiurl).json()['tag_name']
|
github_version_tag = requests.get(settings.gtgithubapiurl).json()['tag_name']
|
||||||
|
print ("github_version_tag =", github_version_tag)
|
||||||
# Get version from version tag
|
# Get version from version tag
|
||||||
github_version = github_version_tag[1:]
|
github_version = github_version_tag[1:]
|
||||||
|
|
||||||
# Check if there is a new version
|
# Check if there is a new version
|
||||||
if functions.checkVersion(github_version, current_version):
|
if functions.checkVersion(github_version, current_version):
|
||||||
|
|
||||||
|
|
||||||
# Stop systemd service
|
# 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?
|
# Should the new version be build from source?
|
||||||
@@ -32,12 +37,50 @@ if functions.checkVersion(github_version, current_version):
|
|||||||
functions.buildFromSource(github_version_tag)
|
functions.buildFromSource(github_version_tag)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# Set download url
|
# 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 file
|
||||||
functions.download(gtdownload, settings.gtfile)
|
|
||||||
|
## downloading sha
|
||||||
|
print ("downloading sha256 hashsum")
|
||||||
|
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'
|
||||||
|
functions.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
|
# Start systemd service
|
||||||
|
print ("starting gitea.service")
|
||||||
os.system("systemctl start gitea.service")
|
os.system("systemctl start gitea.service")
|
||||||
|
|
||||||
|
print ("update successfully")
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
#Print current version is uptodate
|
||||||
|
print ("current version is uptodate")
|
||||||
|
|||||||
Reference in New Issue
Block a user