mirror of
https://github.com/CMiksche/gitea-auto-update
synced 2025-12-10 07:57:23 +01:00
Compare commits
40 Commits
v1.0.0
...
4f3dd23bf7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f3dd23bf7 | ||
|
|
18d6da360d | ||
|
|
52855058fc | ||
|
|
26efce05b5 | ||
|
|
c6621fa117 | ||
|
|
d926a19b6c | ||
|
|
af7941f10a | ||
|
|
f44d7c8954 | ||
|
|
4e5df22f2e | ||
|
|
c52491ae2e | ||
|
|
4f5bd47ea6 | ||
|
|
65bfa64517 | ||
|
|
054999a72e | ||
|
|
b92496fc0d | ||
|
|
ae8d54d018 | ||
|
|
72951e8dde | ||
|
|
b5b09085b3 | ||
|
|
8a58d0d57f | ||
|
|
cf53f7b9dc | ||
|
|
d0b0374d57 | ||
|
|
0fe58ec95c | ||
|
|
fad65bc0be | ||
|
|
480604dce3 | ||
|
|
70b6653b73 | ||
|
|
bce9a482d7 | ||
|
|
0005c23b38 | ||
|
|
52bf4cb835 | ||
|
|
ef91988312 | ||
|
|
3828e07d90 | ||
|
|
d291779fa7 | ||
|
|
43778a1b7b | ||
|
|
3174f2783f | ||
|
|
aa6fc91826 | ||
|
|
98ddb8c119 | ||
|
|
caeee31bb4 | ||
|
|
324225e795 | ||
|
|
05caef9d41 | ||
|
|
8b64d5f518 | ||
|
|
56f128b2f7 | ||
|
|
d95f1aacb8 |
11
.drone.yml
Normal file
11
.drone.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
kind: pipeline
|
||||||
|
name: default
|
||||||
|
steps:
|
||||||
|
- name: test
|
||||||
|
image: python
|
||||||
|
commands:
|
||||||
|
- pip install pipenv
|
||||||
|
- pipenv install
|
||||||
|
- pipenv run gitlint
|
||||||
|
- pipenv run pylint setup.py gitea_auto_update
|
||||||
|
- pipenv run python -m unittest
|
||||||
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||||
|
patreon: cmiksche
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: CMiksche
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: ['https://www.paypal.me/CMiksche', 'https://buymeacoff.ee/WmgU5Sk'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||||
8
.github/dependabot.yml
vendored
Normal file
8
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: pip
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
|
time: "04:00"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,3 +1,8 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
.pyc
|
.pyc
|
||||||
.idea
|
.idea
|
||||||
|
Pipfile.lock
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
*.egg-info
|
||||||
|
update.log
|
||||||
5
.gitlint
Normal file
5
.gitlint
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[general]
|
||||||
|
contrib=contrib-title-conventional-commits
|
||||||
|
|
||||||
|
[contrib-title-conventional-commits]
|
||||||
|
types = build,ci,docs,feat,fix,perf,refactor,style,test
|
||||||
17
.pre-commit-config.yaml
Normal file
17
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v2.5.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-yaml
|
||||||
|
- id: check-added-large-files
|
||||||
|
- repo: https://github.com/PyCQA/pylint
|
||||||
|
rev: pylint-2.5.0
|
||||||
|
hooks:
|
||||||
|
- id: pylint
|
||||||
|
additional_dependencies: ['packaging', 'requests']
|
||||||
|
- repo: https://github.com/jorisroovers/gitlint
|
||||||
|
rev: v0.13.1
|
||||||
|
hooks:
|
||||||
|
- id: gitlint
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
dist: xenial
|
|
||||||
language: python
|
|
||||||
python:
|
|
||||||
- "3.7"
|
|
||||||
cache: pip
|
|
||||||
install:
|
|
||||||
- pip install requests packaging
|
|
||||||
script:
|
|
||||||
- python tests.py
|
|
||||||
@@ -7,3 +7,4 @@ All good contributions which add a new feature or close a issue will be accepted
|
|||||||
1. Commit messages should follow the Angular Commit Message Format: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit
|
1. Commit messages should follow the Angular Commit Message Format: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit
|
||||||
2. New features should be added with a new function, if a new function is possible.
|
2. New features should be added with a new function, if a new function is possible.
|
||||||
3. Test-driven development (TDD) should be followed - this means you should always create unit tests for your function before you create the corresponding function.
|
3. Test-driven development (TDD) should be followed - this means you should always create unit tests for your function before you create the corresponding function.
|
||||||
|
4. You should use the linter
|
||||||
18
Pipfile
Normal file
18
Pipfile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[[source]]
|
||||||
|
name = "pypi"
|
||||||
|
url = "https://pypi.org/simple"
|
||||||
|
verify_ssl = true
|
||||||
|
|
||||||
|
[dev-packages]
|
||||||
|
|
||||||
|
[packages]
|
||||||
|
requests = "*"
|
||||||
|
packaging = "*"
|
||||||
|
fire = "*"
|
||||||
|
configparser = "*"
|
||||||
|
gitlint = "*"
|
||||||
|
pylint = "*"
|
||||||
|
pre-commit = "*"
|
||||||
|
|
||||||
|
[requires]
|
||||||
|
python_version = "3"
|
||||||
53
README.md
53
README.md
@@ -1,6 +1,8 @@
|
|||||||
# Gitea Auto Updater
|
# Gitea Auto Update
|
||||||
|
|
||||||
[](https://travis-ci.org/CMiksche/gitea-auto-update)
|
[](https://cloud.drone.io/CMiksche/gitea-auto-update)
|
||||||
|
[](https://badge.fury.io/py/gitea-auto-update)
|
||||||
|
[](https://pepy.tech/project/gitea-auto-update)
|
||||||
|
|
||||||
Script for a automatic update of gitea. Should be run locally on the gitea server. Has options for updating via new binary file or build from source.
|
Script for a automatic update of gitea. Should be run locally on the gitea server. Has options for updating via new binary file or build from source.
|
||||||
|
|
||||||
@@ -28,28 +30,57 @@ Uses python version 3
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Use the following command to install all dependencies.
|
Create a settings.ini file on your system. Example:
|
||||||
|
|
||||||
|
````
|
||||||
|
[Gitea]
|
||||||
|
site=https://your-gitea-instance.com/api/v1/version
|
||||||
|
apiUrl=https://api.github.com/repos/go-gitea/gitea/releases/latest
|
||||||
|
system=linux-amd64
|
||||||
|
file=/usr/local/bin/gitea
|
||||||
|
tmpDir=/tmp/
|
||||||
|
buildFromSource=
|
||||||
|
sourceDir=
|
||||||
|
logFile=update.log
|
||||||
|
````
|
||||||
|
|
||||||
|
Use the following command to install gitea-auto-update.
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo pip install requests packaging
|
sudo pip3 install gitea-auto-update
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Then clone the git repository.
|
Enter the command `gitea-auto-update --settings=/path/to/settings.ini` in your commandline.
|
||||||
|
|
||||||
3. After that, please change the variables in the settings.py file.
|
If you want to schedule your updates, edit your /etc/crontab file.
|
||||||
|
|
||||||
4. Enter the command `python updater.py` in your commandline.
|
|
||||||
|
|
||||||
5. If you want to schedule your updates, edit your /etc/crontab file.
|
|
||||||
|
|
||||||
## Tutorials
|
## Tutorials
|
||||||
|
|
||||||
* English: http://blog.m5e.de/gitea/update/upgrade/bash/script/2018/11/26/gitea-auto-update-script.html
|
* English: http://blog.m5e.de/gitea/update/upgrade/bash/script/2018/11/26/gitea-auto-update-script.html
|
||||||
* German: https://blog.wronnay.net/automatische-gitea-updates/
|
* German: https://blog.wronnay.net/automatische-gitea-updates/
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
The following instructions help you for developing.
|
||||||
|
|
||||||
|
* Check out the [Contribution Guidelines](CONTRIBUTING.md).
|
||||||
|
* Clone this git repo
|
||||||
|
* Install pipenv: `pip install pipenv`
|
||||||
|
* Install all dependencies: `pipenv install`
|
||||||
|
* Install git pre-commit hooks (for pylint and gitlint) with `pre-commit install`
|
||||||
|
* You can run the tests with `python -m unittest`
|
||||||
|
* After pushing, you should check the build status which currently checks the tests, pylint and the commit message format.
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
|
||||||
|
The following steps are automatically executed via pre-commit hooks.
|
||||||
|
|
||||||
|
* You can run pylint with `pylint gitea_auto_update`
|
||||||
|
* After changes and commit, you can check if your commit message follows the contribution guidelines with `gitlint`. If there is a problem, gitlint will show you a error message.
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
- [@Eideen](https://github.com/Eideen)
|
See https://github.com/CMiksche/gitea-auto-update/graphs/contributors
|
||||||
|
|
||||||
Thank you for your support!
|
Thank you for your support!
|
||||||
|
|
||||||
|
|||||||
71
functions.py
71
functions.py
@@ -1,71 +0,0 @@
|
|||||||
'''
|
|
||||||
Gitea Auto Updater
|
|
||||||
|
|
||||||
Copyright 2018, 2019 The Gitea-Auto-Update Authors
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
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
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Function to check if there is a new version
|
|
||||||
def checkVersion(new_version, old_version):
|
|
||||||
|
|
||||||
from packaging import version
|
|
||||||
|
|
||||||
return version.parse(new_version) > version.parse(old_version)
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
def parseFileVersion(string):
|
|
||||||
return string.split(" ")[2]
|
|
||||||
|
|
||||||
def getVersionFromFile():
|
|
||||||
version_string = os.popen(settings.gtfile+" -v").read()
|
|
||||||
return parseFileVersion(version_string)
|
|
||||||
|
|
||||||
# Function to get the current version
|
|
||||||
def getCurrentVersion():
|
|
||||||
try:
|
|
||||||
# Try to get the version from the file
|
|
||||||
current_version = getVersionFromFile()
|
|
||||||
except:
|
|
||||||
# Get the version via the web api if the file does fail
|
|
||||||
current_version = requests.get(settings.gtsite).json()['version']
|
|
||||||
if current_version.status_code != 200:
|
|
||||||
current_version = getVersionFromFile()
|
|
||||||
finally:
|
|
||||||
return current_version
|
|
||||||
0
gitea_auto_update/__init__.py
Normal file
0
gitea_auto_update/__init__.py
Normal file
0
gitea_auto_update/lib/__init__.py
Normal file
0
gitea_auto_update/lib/__init__.py
Normal file
20
gitea_auto_update/lib/build.py
Normal file
20
gitea_auto_update/lib/build.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
'''
|
||||||
|
Gitea Auto Updater
|
||||||
|
|
||||||
|
Copyright 2018, 2019, 2020 The Gitea-Auto-Update Authors
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
License: GNU General Public License
|
||||||
|
'''
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def build_from_source(tag, gt_file, source_dir):
|
||||||
|
"""Function to build the new version from source"""
|
||||||
|
os.chdir(source_dir)
|
||||||
|
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("cp gitea " + gt_file)
|
||||||
|
os.system("rm -f gitea")
|
||||||
95
gitea_auto_update/lib/download.py
Normal file
95
gitea_auto_update/lib/download.py
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
'''
|
||||||
|
Gitea Auto Updater
|
||||||
|
|
||||||
|
Copyright 2018, 2019, 2020 The Gitea-Auto-Update Authors
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
License: GNU General Public License
|
||||||
|
'''
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
from shutil import which # from whichcraft import which
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def is_tool(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(url, file_name):
|
||||||
|
"""Function to download a file"""
|
||||||
|
# open in binary mode
|
||||||
|
with open(file_name, "wb") as file:
|
||||||
|
# get request
|
||||||
|
response = requests.get(url)
|
||||||
|
# write to file
|
||||||
|
file.write(response.content)
|
||||||
|
|
||||||
|
|
||||||
|
def sha_check():
|
||||||
|
"""Check sha for gitea file"""
|
||||||
|
return os.system("sha256sum -c gitea.xz.sha256 > /dev/null") == 0
|
||||||
|
|
||||||
|
|
||||||
|
class Download:
|
||||||
|
"""Class for downloading gitea"""
|
||||||
|
|
||||||
|
def __init__(self, tmp_dir, github_version_tag, gt_system, gt_file):
|
||||||
|
if not is_tool("xz"):
|
||||||
|
logging.error('Download: missing dependency: xz')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
self.tmp_dir = tmp_dir
|
||||||
|
self.github_version_tag = github_version_tag
|
||||||
|
self.github_version = self.github_version_tag[1:]
|
||||||
|
self.gt_system = gt_system
|
||||||
|
self.gt_file = gt_file
|
||||||
|
|
||||||
|
self.download_gitea_files()
|
||||||
|
self.check_and_extract()
|
||||||
|
|
||||||
|
def download_gitea_files(self):
|
||||||
|
"""Download gitea files"""
|
||||||
|
# Set download url
|
||||||
|
gt_download = 'https://github.com/go-gitea/gitea/releases/download/' \
|
||||||
|
+ self.github_version_tag + '/gitea-' + self.github_version \
|
||||||
|
+ '-' + self.gt_system + '.xz'
|
||||||
|
logging.info('Download: Gitea file: %s', gt_download)
|
||||||
|
sha_download = gt_download + '.sha256'
|
||||||
|
logging.info('Download: SHA file: %s', sha_download)
|
||||||
|
|
||||||
|
# Download file
|
||||||
|
logging.info('Download: downloading sha256 hashsum')
|
||||||
|
download(sha_download, self.tmp_dir + 'gitea.xz.sha256')
|
||||||
|
logging.info('Download: downloading %s', self.github_version_tag + 'gitea.xz')
|
||||||
|
self.tmp_xz = self.tmp_dir + 'gitea-' + self.github_version + '-' + self.gt_system + '.xz'
|
||||||
|
download(gt_download, self.tmp_xz)
|
||||||
|
|
||||||
|
def extract_file(self):
|
||||||
|
"""Extract gitea file"""
|
||||||
|
logging.info('Download: sha ok, extracting file to location')
|
||||||
|
# extracting download file
|
||||||
|
cmd = "xz -d " + self.tmp_xz
|
||||||
|
os.system(cmd)
|
||||||
|
# copying temp file to gtfile location.
|
||||||
|
# Copying preserves SELinux permissions, see issue #22
|
||||||
|
cmd = 'cp ' + self.tmp_dir + 'gitea-' + self.github_version \
|
||||||
|
+ '-' + self.gt_system + ' ' + self.gt_file
|
||||||
|
os.system(cmd)
|
||||||
|
# cleaning up tmp file
|
||||||
|
cmd = 'rm -f ' + self.tmp_dir + 'gitea-' + self.github_version + '-' + self.gt_system
|
||||||
|
os.system(cmd)
|
||||||
|
cmd = 'chmod +x ' + self.gt_file
|
||||||
|
os.system(cmd)
|
||||||
|
|
||||||
|
def check_and_extract(self):
|
||||||
|
"""Check file and extract"""
|
||||||
|
os.chdir(self.tmp_dir)
|
||||||
|
if sha_check():
|
||||||
|
self.extract_file()
|
||||||
|
else:
|
||||||
|
logging.error('Download: error: sha256sum failed')
|
||||||
|
sys.exit()
|
||||||
52
gitea_auto_update/lib/test_version.py
Normal file
52
gitea_auto_update/lib/test_version.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
'''
|
||||||
|
Gitea Auto Updater
|
||||||
|
|
||||||
|
Copyright 2019, 2020 The Gitea-Auto-Update Authors
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
License: GNU General Public License
|
||||||
|
'''
|
||||||
|
import unittest
|
||||||
|
import gitea_auto_update.lib.version
|
||||||
|
|
||||||
|
VERSION = gitea_auto_update.lib.version
|
||||||
|
|
||||||
|
|
||||||
|
class TestVersion(unittest.TestCase):
|
||||||
|
"""Test the version class"""
|
||||||
|
|
||||||
|
def test_simple_version(self):
|
||||||
|
"""1.9.1 should be newer than 1.9.0"""
|
||||||
|
self.assertTrue(VERSION.check_version('1.9.1', '1.9.0'))
|
||||||
|
|
||||||
|
def test_two_int_version(self):
|
||||||
|
"""1.10.0 should be newer than 1.9.0"""
|
||||||
|
self.assertTrue(VERSION.check_version('1.10.0', '1.9.0'))
|
||||||
|
|
||||||
|
def test_false_version(self):
|
||||||
|
"""1.8.0 should be older than 1.9.0"""
|
||||||
|
self.assertFalse(VERSION.check_version('1.8.0', '1.9.0'))
|
||||||
|
|
||||||
|
def test_same_version(self):
|
||||||
|
"""1.9.7 should be the same as 1.9.7"""
|
||||||
|
self.assertFalse(VERSION.check_version('1.9.7', '1.9.7'))
|
||||||
|
|
||||||
|
def test_int(self):
|
||||||
|
"""9 should be newer than 8"""
|
||||||
|
self.assertTrue(VERSION.check_version('9', '8'))
|
||||||
|
|
||||||
|
def test_suffix(self):
|
||||||
|
"""1.9.0+dev-264-g8de76b6e6 should be newer than 1.8.0"""
|
||||||
|
self.assertTrue(VERSION.check_version('1.9.0+dev-264-g8de76b6e6', '1.8.0'))
|
||||||
|
|
||||||
|
def test_parse_file_version(self):
|
||||||
|
"""It should get the version from a string"""
|
||||||
|
string = 'Gitea version 1.8.1 built with go1.12.2 : bindata, sqlite, sqlite_unlock_notify'
|
||||||
|
self.assertEqual(
|
||||||
|
VERSION.parse_file_version(string),
|
||||||
|
'1.8.1'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
60
gitea_auto_update/lib/version.py
Normal file
60
gitea_auto_update/lib/version.py
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
'''
|
||||||
|
Gitea Auto Updater
|
||||||
|
|
||||||
|
Copyright 2018, 2019, 2020 The Gitea-Auto-Update Authors
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
License: GNU General Public License
|
||||||
|
'''
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
from packaging import version
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def get_github_version_tag(api_url):
|
||||||
|
"""Get the version from github"""
|
||||||
|
version_tag = requests.get(api_url).json()['tag_name']
|
||||||
|
logging.info('Version: github_version_tag = %s', version_tag)
|
||||||
|
return version_tag
|
||||||
|
|
||||||
|
|
||||||
|
def parse_file_version(string):
|
||||||
|
"""Get the version from a file"""
|
||||||
|
return string.split(" ")[2]
|
||||||
|
|
||||||
|
|
||||||
|
def check_version(new_version, old_version):
|
||||||
|
"""Function to check if there is a new version"""
|
||||||
|
return version.parse(new_version) > version.parse(old_version)
|
||||||
|
|
||||||
|
|
||||||
|
class Version:
|
||||||
|
"""Class to get and check the gitea version"""
|
||||||
|
|
||||||
|
def __init__(self, gt_site, gt_file):
|
||||||
|
self.gt_site = gt_site
|
||||||
|
self.gt_file = gt_file
|
||||||
|
|
||||||
|
def get_version_from_file(self):
|
||||||
|
"""Read the version from the gitea file"""
|
||||||
|
version_string = os.popen(self.gt_file + " -v").read()
|
||||||
|
return parse_file_version(version_string)
|
||||||
|
|
||||||
|
def get_current_version(self):
|
||||||
|
"""Function to get the current version"""
|
||||||
|
try:
|
||||||
|
# Try to get the version from the file
|
||||||
|
current_version = self.get_version_from_file()
|
||||||
|
except IOError:
|
||||||
|
# Get the version via the web api if the file does fail
|
||||||
|
try:
|
||||||
|
current_version = requests.get(self.gt_site).json()['version']
|
||||||
|
if current_version.status_code != 200:
|
||||||
|
raise RuntimeError("Could not download version.") from None
|
||||||
|
except RuntimeError:
|
||||||
|
# To allow installation, return a default version of "0.0.0".
|
||||||
|
current_version = "0.0.0"
|
||||||
|
finally:
|
||||||
|
logging.info('Version: current_version = %s', current_version)
|
||||||
|
return current_version
|
||||||
94
gitea_auto_update/update.py
Normal file
94
gitea_auto_update/update.py
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
'''
|
||||||
|
Gitea Auto Updater
|
||||||
|
|
||||||
|
Copyright 2018, 2019, 2020 The Gitea-Auto-Update Authors
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
License: GNU General Public License
|
||||||
|
'''
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
import configparser
|
||||||
|
import fire
|
||||||
|
import gitea_auto_update.lib.version
|
||||||
|
import gitea_auto_update.lib.download
|
||||||
|
import gitea_auto_update.lib.build
|
||||||
|
|
||||||
|
|
||||||
|
class Update:
|
||||||
|
"""
|
||||||
|
Main class to update gitea
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
config):
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
# Get version tag from github and remove first char (v)
|
||||||
|
self.github_version_tag = gitea_auto_update.lib.version.get_github_version_tag(
|
||||||
|
config.get('Gitea', 'apiUrl')
|
||||||
|
)
|
||||||
|
# Get version from version tag
|
||||||
|
self.github_version = self.github_version_tag[1:]
|
||||||
|
|
||||||
|
self.check_and_update()
|
||||||
|
|
||||||
|
def do_update(self):
|
||||||
|
"""Execute the update"""
|
||||||
|
|
||||||
|
# Should the new version be build from source?
|
||||||
|
if self.config.get('Gitea', 'buildFromSource'):
|
||||||
|
gitea_auto_update.lib.build.build_from_source(
|
||||||
|
self.github_version_tag,
|
||||||
|
self.config.get('Gitea', 'file'),
|
||||||
|
self.config.get('Gitea', 'sourceDir')
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
gitea_auto_update.lib.download.Download(
|
||||||
|
self.config.get('Gitea', 'tmpDir'),
|
||||||
|
self.github_version_tag,
|
||||||
|
self.config.get('Gitea', 'system'),
|
||||||
|
self.config.get('Gitea', 'file')
|
||||||
|
)
|
||||||
|
|
||||||
|
def check_and_update(self):
|
||||||
|
"""Check if a update is possible and do it if it is"""
|
||||||
|
# Version from gitea site
|
||||||
|
version = gitea_auto_update.lib.version.Version(
|
||||||
|
self.config.get('Gitea', 'site'),
|
||||||
|
self.config.get('Gitea', 'file')
|
||||||
|
)
|
||||||
|
current_version = version.get_current_version()
|
||||||
|
# Check if there is a new version
|
||||||
|
if gitea_auto_update.lib.version.check_version(self.github_version, current_version):
|
||||||
|
logging.info('Update: new version available, stopping service')
|
||||||
|
os.system("systemctl stop gitea.service")
|
||||||
|
self.do_update()
|
||||||
|
logging.info('Update: starting gitea.service')
|
||||||
|
os.system("systemctl start gitea.service")
|
||||||
|
print("update successfully")
|
||||||
|
else:
|
||||||
|
print("current version is uptodate")
|
||||||
|
|
||||||
|
|
||||||
|
def updater(settings='settings.ini'):
|
||||||
|
"""Get the config and set logging"""
|
||||||
|
# Config
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(settings)
|
||||||
|
# Create a log file
|
||||||
|
logging.basicConfig(filename=config.get('Gitea', 'logFile'), level=logging.DEBUG)
|
||||||
|
# Start update
|
||||||
|
Update(config)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main func"""
|
||||||
|
if not sys.version_info[0] == 3:
|
||||||
|
sys.exit("Sorry, Python 2 is not supported. Please update to Python 3.")
|
||||||
|
fire.Fire(updater)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
9
settings.ini
Normal file
9
settings.ini
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Gitea]
|
||||||
|
site=https://your-gitea-instance.com/api/v1/version
|
||||||
|
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
|
||||||
|
logFile=update.log
|
||||||
23
settings.py
23
settings.py
@@ -1,23 +0,0 @@
|
|||||||
'''
|
|
||||||
Gitea Auto Updater
|
|
||||||
|
|
||||||
Copyright 2018, 2019 The Gitea-Auto-Update Authors
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
License: GNU General Public License
|
|
||||||
'''
|
|
||||||
# Gitea Site
|
|
||||||
# Optional - the script will get the version from the gitea file if you change the url to a empty string
|
|
||||||
gtsite = 'https://your-gitea-instance.com/api/v1/version'
|
|
||||||
# Gitea GitHub API URL for latest Relase
|
|
||||||
gtgithubapiurl = 'https://api.github.com/repos/go-gitea/gitea/releases/latest'
|
|
||||||
# Gitea System
|
|
||||||
gtsystem = 'linux-amd64'
|
|
||||||
# Name and Path of gitea file
|
|
||||||
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'
|
|
||||||
41
setup.py
Normal file
41
setup.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
'''
|
||||||
|
Gitea Auto Updater
|
||||||
|
|
||||||
|
Copyright 2018, 2019, 2020 The Gitea-Auto-Update Authors
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
License: GNU General Public License
|
||||||
|
'''
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
with open("README.md", "r") as fh:
|
||||||
|
LONG_DESCRIPTION = fh.read()
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
name='gitea_auto_update',
|
||||||
|
version='2.0.9',
|
||||||
|
description='A script which can update gitea to a new version.',
|
||||||
|
long_description=LONG_DESCRIPTION,
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
url='https://github.com/CMiksche/gitea-auto-update',
|
||||||
|
author='Christoph Miksche',
|
||||||
|
author_email='christoph@miksche.org',
|
||||||
|
license='GPLv3',
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
||||||
|
"Operating System :: Unix",
|
||||||
|
],
|
||||||
|
keywords=['gitea', 'update', 'debian', 'linux'],
|
||||||
|
python_requires='>=3',
|
||||||
|
install_requires=[
|
||||||
|
'requests',
|
||||||
|
'packaging',
|
||||||
|
'fire',
|
||||||
|
'configparser'
|
||||||
|
],
|
||||||
|
packages=setuptools.find_packages(),
|
||||||
|
entry_points={
|
||||||
|
'console_scripts': ['gitea-auto-update=gitea_auto_update.update:main'],
|
||||||
|
}
|
||||||
|
)
|
||||||
36
tests.py
36
tests.py
@@ -1,36 +0,0 @@
|
|||||||
'''
|
|
||||||
Gitea Auto Updater
|
|
||||||
|
|
||||||
Copyright 2019 The Gitea-Auto-Update Authors
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
License: GNU General Public License
|
|
||||||
'''
|
|
||||||
import functions
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
class Tests(unittest.TestCase):
|
|
||||||
|
|
||||||
def testSimpleVersion(self):
|
|
||||||
self.assertTrue(functions.checkVersion('1.9.1', '1.9.0'))
|
|
||||||
|
|
||||||
def testTwoIntVersion(self):
|
|
||||||
self.assertTrue(functions.checkVersion('1.10.0', '1.9.0'))
|
|
||||||
|
|
||||||
def testFalseVersion(self):
|
|
||||||
self.assertFalse(functions.checkVersion('1.8.0', '1.9.0'))
|
|
||||||
|
|
||||||
def testSameVersion(self):
|
|
||||||
self.assertFalse(functions.checkVersion('1.9.7', '1.9.7'))
|
|
||||||
|
|
||||||
def testInt(self):
|
|
||||||
self.assertTrue(functions.checkVersion('9', '8'))
|
|
||||||
|
|
||||||
def testSuffix(self):
|
|
||||||
self.assertTrue(functions.checkVersion('1.9.0+dev-264-g8de76b6e6', '1.8.0'))
|
|
||||||
|
|
||||||
def testParseFileVersion(self):
|
|
||||||
self.assertEqual(functions.parseFileVersion('Gitea version 1.8.1 built with go1.12.2 : bindata, sqlite, sqlite_unlock_notify'), '1.8.1')
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
86
updater.py
86
updater.py
@@ -1,86 +0,0 @@
|
|||||||
'''
|
|
||||||
Gitea Auto Updater
|
|
||||||
|
|
||||||
Copyright 2018, 2019 The Gitea-Auto-Update Authors
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
License: GNU General Public License
|
|
||||||
'''
|
|
||||||
import settings
|
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
import functions
|
|
||||||
|
|
||||||
if not functions.is_tool("xz"):
|
|
||||||
print ("missing dependency: xz")
|
|
||||||
quit()
|
|
||||||
|
|
||||||
# Version from gitea site
|
|
||||||
current_version = functions.getCurrentVersion()
|
|
||||||
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 functions.checkVersion(github_version, current_version):
|
|
||||||
|
|
||||||
|
|
||||||
# Stop systemd 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:
|
|
||||||
|
|
||||||
functions.buildFromSource(github_version_tag)
|
|
||||||
|
|
||||||
else:
|
|
||||||
# Set download url
|
|
||||||
## 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
|
|
||||||
|
|
||||||
## 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
|
|
||||||
print ("starting 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