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

41 Commits

Author SHA1 Message Date
Christoph Miksche
8b30f0b9d5 feat: add timeout
Add a timeout for the requests.
2022-09-04 16:07:41 +02:00
Christoph Daniel Miksche
6f85b5b0a3 docs: add badges
Add badges for license and twitter
2022-09-04 15:59:28 +02:00
Christoph Daniel Miksche
50586a33a3 docs: add xz as dependency
Add the missing dependency `xz`
2022-06-17 13:56:47 +02:00
Christoph Daniel Miksche
576f7454c1 Merge pull request #28 from BadCo-NZ/patch-1
Update README.md
2022-06-14 11:16:32 +02:00
BadCo-NZ
7379ad56ce Update README.md
Fixed code block error
2022-06-14 01:55:30 +00:00
BadCo-NZ
2740dcb1b8 Updated dependencies
Reworded Dependencies section
2022-06-14 01:53:27 +00:00
BadCo-NZ
92cefe029a Update README.md
Added dependencies section
2022-05-22 11:15:55 +00:00
Christoph Miksche
c2da136d7e fix: update if sha doesn't exists
Still update if there is no sha which we can check
2022-02-01 13:19:42 +01:00
Christoph Miksche
bdef0b6987 fix: change master to main
Change the branch name in the build process
2022-01-31 11:59:33 +01:00
Christoph Miksche
ccb3e058ef build: publish on every deploy
Deploy with GitHub Actions to PyPI

Closes #15
2021-10-16 16:59:07 +02:00
Christoph Daniel Miksche
4f3dd23bf7 Merge pull request #24 from R0GGER/patch-1
tiny typo
2021-09-16 16:18:35 +02:00
R0GGER
18d6da360d tiny typo 2021-09-16 13:57:22 +02:00
Christoph Miksche
52855058fc feat: release new version
Release new version with fix for SELinux
2021-06-15 21:13:45 +02:00
Christoph Daniel Miksche
26efce05b5 Merge pull request #23 from maloo1/patch-1
Changes for SELinux, closes #23
2021-06-15 21:03:56 +02:00
Paul Johnston
c6621fa117 fix: Also cleaning up the build dir 2021-06-16 02:56:03 +08:00
Paul Johnston
d926a19b6c Changed mv to cp to preserve SELinux permissions 2021-06-16 02:37:18 +08:00
Paul Johnston
af7941f10a Change mv to cp to preserve SELinux permissions 2021-06-16 02:27:10 +08:00
Christoph Daniel Miksche
f44d7c8954 Merge pull request #20 from CMiksche/dependabot/add-v2-config-file
Upgrade to GitHub-native Dependabot
2021-04-30 01:11:19 +02:00
dependabot-preview[bot]
4e5df22f2e ci: Upgrade Dependabot
Upgrade to GitHub-native Dependabot
2021-04-30 01:09:44 +02:00
Christoph Miksche
c52491ae2e ci: switch to drone
Switch the CI system from travis to drone

Closes #19
2021-04-20 18:33:52 +02:00
Christoph Daniel Miksche
4f5bd47ea6 docs: update download stats
Change download statistics to pepy.tech (pypistats.org is currently down)
2020-08-13 00:08:35 +02:00
Christoph Miksche
65bfa64517 feat: release new version
There were many changes since the last release.
2020-05-09 21:02:21 +02:00
Christoph Miksche
054999a72e feat: add pre-commit hooks
Add pre-commit hooks for running pylint and gitlint.
2020-05-08 11:42:39 +02:00
Christoph Miksche
b92496fc0d refactor: follow PEP standards
Follow Python Enhancement Proposals and add PyLint to enforce them.
2020-03-27 16:56:05 +01:00
Christoph Daniel Miksche
ae8d54d018 docs: add download stats
Add download statistics from PyPI to README
2020-02-26 21:47:39 +01:00
Christoph Daniel Miksche
72951e8dde docs: update funding methods
Add new funding methods.
2019-12-24 14:58:50 +01:00
Christoph Daniel Miksche
b5b09085b3 docs: create FUNDING.yml
Create a file about possibilities for supporting this project.
2019-11-03 16:59:33 +01:00
Christoph Daniel Miksche
8a58d0d57f feat: gitlint
Add gitlint settings to the master.
2019-09-11 13:53:51 +02:00
Christoph Miksche
cf53f7b9dc docs: update development instructions
Add more instructions for development to the README.md
2019-09-11 13:49:18 +02:00
Christoph Miksche
d0b0374d57 feat: add gitlint
Add gitlint to enforce Angular style commit messages.
2019-09-11 13:39:26 +02:00
Christoph Miksche
0fe58ec95c feat: add gitlint
Add gitlint to enforce Angular style commit messages.

WIP. Doesn't work currently.
2019-09-08 18:58:17 +02:00
Christoph Miksche
fad65bc0be docs: update README.md and .gitignore
- Add development instructions to README.md
- Add the update.log file to .gitignore
2019-09-08 18:49:52 +02:00
Christoph Miksche
480604dce3 docs: add contributor, update version & .gitignore
- Add the new contributor @iwalton3 to the README.md
- Update the version for publishing in PyPI
- Update .gitignore to ignore distribution files
2019-09-04 15:36:33 +02:00
Christoph Daniel Miksche
70b6653b73 Merge pull request #11 from iwalton3/master
Fixes: Make binary executable, fix isTool method signature, handle corrupted binary, and README tweaks.
2019-09-04 15:18:26 +02:00
Ian Walton
bce9a482d7 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.
2019-09-03 14:31:06 -04:00
Ian Walton
0005c23b38 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.
2019-09-03 14:28:35 -04:00
Ian Walton
52bf4cb835 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.
2019-09-03 14:26:58 -04:00
Ian Walton
ef91988312 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.
2019-09-03 14:25:44 -04:00
Christoph Miksche
3828e07d90 feat: add restriction for python 3
Add a restriction for python 3 so that installing this software with python 2 isn't possible.

Should fix GH-10.
2019-09-02 13:47:29 +02:00
Christoph Daniel Miksche
d291779fa7 Update README.md 2019-08-26 23:31:36 +02:00
Christoph Daniel Miksche
43778a1b7b Update README.md 2019-08-26 23:18:23 +02:00
18 changed files with 395 additions and 218 deletions

11
.drone.yml Normal file
View 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
View 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
View File

@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10

31
.github/workflows/pypi-publish.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
on:
release:
types:
- created
name: Publish Package
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: "Installs and upgrades pip, installs other dependencies and installs the package from setup.py"
run: |
# Upgrade pip
python3 -m pip install --upgrade pip
# Install build deps
python3 -m pip install pipenv setuptools wheel twine
pipenv install
# Install the package from setup.py
python3 setup.py install
- name: Build
run: |
python3 setup.py sdist bdist_wheel
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

4
.gitignore vendored
View File

@@ -2,3 +2,7 @@ __pycache__
.pyc .pyc
.idea .idea
Pipfile.lock Pipfile.lock
dist
build
*.egg-info
update.log

5
.gitlint Normal file
View 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
View 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

View File

@@ -1,10 +0,0 @@
dist: xenial
language: python
python:
- "3.7"
cache: pip
install:
- pip install pipenv
- pipenv install
script:
- python tests.py

View File

@@ -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

View File

@@ -10,6 +10,9 @@ requests = "*"
packaging = "*" packaging = "*"
fire = "*" fire = "*"
configparser = "*" configparser = "*"
gitlint = "*"
pylint = "*"
pre-commit = "*"
[requires] [requires]
python_version = "3.7" python_version = "3"

View File

@@ -1,8 +1,13 @@
# Gitea Auto Update # Gitea Auto Update
[![Build Status](https://travis-ci.org/CMiksche/gitea-auto-update.svg?branch=master)](https://travis-ci.org/CMiksche/gitea-auto-update) [![Build Status](https://cloud.drone.io/api/badges/CMiksche/gitea-auto-update/status.svg)](https://cloud.drone.io/CMiksche/gitea-auto-update)
[![PyPI version](https://badge.fury.io/py/gitea-auto-update.svg)](https://badge.fury.io/py/gitea-auto-update)
[![Downloads](https://pepy.tech/badge/gitea-auto-update)](https://pepy.tech/project/gitea-auto-update)
![GitHub](https://img.shields.io/github/license/cmiksche/gitea-auto-update?style=flat)
[![Twitter Follow](https://img.shields.io/twitter/follow/cmiksche?style=social)](https://twitter.com/cmiksche)
[![Mastodon Follow](https://img.shields.io/mastodon/follow/106336578279256330?domain=https%3A%2F%2Fmastodon.social&style=social)](https://mastodon.social/@cmiksche)
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 an automatic update of gitea. Should be run locally on the gitea server. Has options for updating via new binary file or build from source.
## Procedure ## Procedure
* Get Gitea Version from the Gitea CLI and if that fails from the Gitea API * Get Gitea Version from the Gitea CLI and if that fails from the Gitea API
@@ -26,6 +31,10 @@ Author: Christoph Daniel Miksche (m5e.de)
Uses python version 3 Uses python version 3
## Dependencies
Ensure `pip3`, `setuptools`, `xz-utils` and `wheel` dependencies are installed on the system you are running this script in. (Most Linux OS like Ubuntu or Debian come with these pre-installed)
## Installation ## Installation
Create a settings.ini file on your system. Example: Create a settings.ini file on your system. Example:
@@ -37,18 +46,18 @@ apiUrl=https://api.github.com/repos/go-gitea/gitea/releases/latest
system=linux-amd64 system=linux-amd64
file=/usr/local/bin/gitea file=/usr/local/bin/gitea
tmpDir=/tmp/ tmpDir=/tmp/
buildFromSource=None buildFromSource=
sourceDir=/home/git/go/src/code.gitea.io/gitea sourceDir=
logFile=update.log logFile=update.log
```` ````
Use the following command to install all gitea-auto-update. 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. Enter the command `gitea-auto-update --settings=/path/to/settings.ini` in your commandline.
If you want to schedule your updates, edit your /etc/crontab file. If you want to schedule your updates, edit your /etc/crontab file.
@@ -57,9 +66,28 @@ If you want to schedule your updates, edit your /etc/crontab file.
* 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!

View File

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

View File

@@ -1,77 +1,99 @@
''' '''
Gitea Auto Updater Gitea Auto Updater
Copyright 2018, 2019 The Gitea-Auto-Update Authors Copyright 2018, 2019, 2020 The Gitea-Auto-Update Authors
All rights reserved. All rights reserved.
License: GNU General Public License License: GNU General Public License
''' '''
import requests
import os import os
import sys
import logging import logging
from shutil import which # from whichcraft import which 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, timeout=3600)
# write to file
file.write(response.content)
def sha_check():
"""Check sha for gitea file"""
sha_path = 'gitea.xz.sha256'
if os.path.exists(sha_path):
return os.system("sha256sum -c "+sha_path+" > /dev/null") == 0
# return true because we don't have a sha file to check
return True
class Download: class Download:
"""Class for downloading gitea"""
def __init__(self, tmpDir, githubVersion, githubVersionTag, gtSystem, gtFile): def __init__(self, tmp_dir, github_version_tag, gt_system, gt_file):
if not self.isTool("xz"): if not is_tool("xz"):
logging.error('Download: missing dependency: xz') logging.error('Download: missing dependency: xz')
quit() sys.exit()
self.tmpDir = tmpDir self.tmp_dir = tmp_dir
self.githubVersion = githubVersion self.github_version_tag = github_version_tag
self.githubVersionTag = githubVersionTag self.github_version = self.github_version_tag[1:]
self.gtSystem = gtSystem self.gt_system = gt_system
self.gtFile = gtFile self.gt_file = gt_file
self.downloadGiteaFiles() self.download_gitea_files()
self.checkAndExtract() self.check_and_extract()
def isTool(name): def download_gitea_files(self):
# Function to check if tool is available """Download gitea files"""
##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 # Set download url
gtDownload = 'https://github.com/go-gitea/gitea/releases/download/' + self.githubVersionTag + '/gitea-' + self.githubVersion + '-' + self.gtSystem + '.xz' gt_download = 'https://github.com/go-gitea/gitea/releases/download/' \
logging.info('Download: Gitea file: %s', gtDownload) + self.github_version_tag + '/gitea-' + self.github_version \
shaDownload = gtDownload + '.sha256' + '-' + self.gt_system + '.xz'
logging.info('Download: SHA file: %s', shaDownload) logging.info('Download: Gitea file: %s', gt_download)
sha_download = gt_download + '.sha256'
logging.info('Download: SHA file: %s', sha_download)
# Download file # Download file
logging.info('Download: downloading sha256 hashsum') logging.info('Download: downloading sha256 hashsum')
self.download(shaDownload, self.tmpDir + 'gitea.xz.sha256') download(sha_download, self.tmp_dir + 'gitea.xz.sha256')
logging.info('Download: downloading %s', self.githubVersionTag + 'gitea.xz') logging.info('Download: downloading %s', self.github_version_tag + 'gitea.xz')
self.tmpXz = self.tmpDir +'gitea-' + self.githubVersion + '-' + self.gtSystem + '.xz' self.tmp_xz = self.tmp_dir + 'gitea-' + self.github_version + '-' + self.gt_system + '.xz'
self.download(gtDownload, self.tmpXz) download(gt_download, self.tmp_xz)
def shaCheck(self): def extract_file(self):
return os.system("sha256sum -c gitea.xz.sha256 > /dev/null") == 0 """Extract gitea file"""
def extractFile(self):
logging.info('Download: sha ok, extracting file to location') logging.info('Download: sha ok, extracting file to location')
# extracting download file # extracting download file
cmd = "xz -d " + self.tmpXz cmd = "xz -d " + self.tmp_xz
os.system(cmd) os.system(cmd)
# moving temp file to gtfile location # copying temp file to gtfile location.
cmd = 'mv ' + self.tmpDir + 'gitea-' + self.githubVersion + '-' + self.gtSystem + ' ' + self.gtFile # 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) os.system(cmd)
def checkAndExtract(self): def check_and_extract(self):
os.chdir(self.tmpDir) """Check file and extract"""
if self.shaCheck(): os.chdir(self.tmp_dir)
self.extractFile() if sha_check():
self.extract_file()
else: else:
logging.error('Download: error: sha256sum failed') logging.error('Download: error: sha256sum failed')
quit() sys.exit()

View 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()

View File

@@ -1,48 +1,60 @@
''' '''
Gitea Auto Updater Gitea Auto Updater
Copyright 2018, 2019 The Gitea-Auto-Update Authors Copyright 2018, 2019, 2020 The Gitea-Auto-Update Authors
All rights reserved. All rights reserved.
License: GNU General Public License License: GNU General Public License
''' '''
from packaging import version
import os import os
import requests
import logging 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, timeout=30).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 Version:
"""Class to get and check the gitea version"""
def __init__(self, gtSite, gtFile): def __init__(self, gt_site, gt_file):
self.gtSite = gtSite self.gt_site = gt_site
self.gtFile = gtFile self.gt_file = gt_file
def checkVersion(self, newVersion, oldVersion): def get_version_from_file(self):
# Function to check if there is a new version """Read the version from the gitea file"""
return version.parse(newVersion) > version.parse(oldVersion) version_string = os.popen(self.gt_file + " -v").read()
return parse_file_version(version_string)
def parseFileVersion(self, string): def get_current_version(self):
return string.split(" ")[2] """Function to get the current version"""
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:
# Try to get the version from the file # Try to get the version from the file
currentVersion = self.getVersionFromFile() current_version = self.get_version_from_file()
except: except IOError:
# Get the version via the web api if the file does fail # Get the version via the web api if the file does fail
currentVersion = requests.get(self.gtSite).json()['version'] try:
if currentVersion.status_code != 200: current_version = requests.get(self.gt_site, timeout=30).json()['version']
currentVersion = self.getVersionFromFile() 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: finally:
logging.info('Version: current_version = %s', currentVersion) logging.info('Version: current_version = %s', current_version)
return currentVersion return current_version
def getGithubVersionTag(self, apiUrl):
versionTag = requests.get(apiUrl).json()['tag_name']
logging.info('Version: github_version_tag = %s', versionTag)
return versionTag

View File

@@ -1,12 +1,13 @@
''' '''
Gitea Auto Updater Gitea Auto Updater
Copyright 2018, 2019 The Gitea-Auto-Update Authors Copyright 2018, 2019, 2020 The Gitea-Auto-Update Authors
All rights reserved. All rights reserved.
License: GNU General Public License License: GNU General Public License
''' '''
import os import os
import sys
import logging import logging
import configparser import configparser
import fire import fire
@@ -14,68 +15,80 @@ import gitea_auto_update.lib.version
import gitea_auto_update.lib.download import gitea_auto_update.lib.download
import gitea_auto_update.lib.build import gitea_auto_update.lib.build
class Update: class Update:
"""
Main class to update gitea
"""
def __init__(self, gtSite, gtFile, sourceDir, apiUrl, buildFromSource, tmpDir, gtSystem): def __init__(self,
self.gtSite = gtSite config):
self.gtFile = gtFile self.config = config
self.sourceDir = sourceDir
self.apiUrl = apiUrl
self.buildFromSource = buildFromSource
self.tmpDir = tmpDir
self.gtSystem = gtSystem
self.initVersionAndBuild() # Get version tag from github and remove first char (v)
self.getVersionAndTag() self.github_version_tag = gitea_auto_update.lib.version.get_github_version_tag(
self.checkAndUpdate() config.get('Gitea', 'apiUrl')
)
# Get version from version tag
self.github_version = self.github_version_tag[1:]
def initVersionAndBuild(self): self.check_and_update()
self.version = gitea_auto_update.lib.version.Version(self.gtSite, self.gtFile)
self.build = gitea_auto_update.lib.build.Build(self.gtFile, self.sourceDir)
def getVersionAndTag(self): def do_update(self):
self.currentVersion = self.version.getCurrentVersion() # Version from gitea site """Execute the update"""
self.githubVersionTag = self.version.getGithubVersionTag(self.apiUrl) # Get version tag from github and remove first char (v)
self.githubVersion = self.githubVersionTag[1:] # Get version from version tag
def doUpdate(self): # Should the new version be build from source?
if self.buildFromSource: # Should the new version be build from source? if self.config.get('Gitea', 'buildFromSource'):
self.build.fromSource(self.githubVersionTag) gitea_auto_update.lib.build.build_from_source(
self.github_version_tag,
self.config.get('Gitea', 'file'),
self.config.get('Gitea', 'sourceDir')
)
else: else:
self.download = gitea_auto_update.lib.download.Download(self.tmpDir, gitea_auto_update.lib.download.Download(
self.githubVersion, self.config.get('Gitea', 'tmpDir'),
self.githubVersionTag, self.github_version_tag,
self.gtSystem, self.config.get('Gitea', 'system'),
self.gtFile) self.config.get('Gitea', 'file')
)
def checkAndUpdate(self): def check_and_update(self):
if self.version.checkVersion(self.githubVersion, self.currentVersion): # Check if there is a new version """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') logging.info('Update: new version available, stopping service')
os.system("systemctl stop gitea.service") os.system("systemctl stop gitea.service")
self.doUpdate() self.do_update()
logging.info('Update: starting gitea.service') logging.info('Update: starting gitea.service')
os.system("systemctl start gitea.service") os.system("systemctl start gitea.service")
print("update successfully") print("update successfully")
else: else:
print("current version is uptodate") print("current version is uptodate")
def updater(settings='settings.ini'): def updater(settings='settings.ini'):
"""Get the config and set logging"""
# Config # Config
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(settings) config.read(settings)
# Create a log file # Create a log file
logging.basicConfig(filename=config.get('Gitea', 'logFile'), level=logging.DEBUG) logging.basicConfig(filename=config.get('Gitea', 'logFile'), level=logging.DEBUG)
# Start update # Start update
Update(config.get('Gitea', 'site'), Update(config)
config.get('Gitea', 'file'),
config.get('Gitea', 'sourceDir'),
config.get('Gitea', 'apiUrl'),
config.get('Gitea', 'buildFromSource'),
config.get('Gitea', 'tmpDir'),
config.get('Gitea', 'system'))
def main(): 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) fire.Fire(updater)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -1,31 +1,41 @@
'''
Gitea Auto Updater
Copyright 2018, 2019, 2020, 2021, 2022 The Gitea-Auto-Update Authors
All rights reserved.
License: GNU General Public License
'''
import setuptools import setuptools
with open("README.md", "r") as fh: with open("README.md", "r", encoding='utf8') as fh:
long_description = fh.read() LONG_DESCRIPTION = fh.read()
setuptools.setup(name='gitea_auto_update', setuptools.setup(
version='2.0.5', name='gitea_auto_update',
description='A script which can update gitea to a new version.', version='2.0.11',
long_description=long_description, description='A script which can update gitea to a new version.',
long_description_content_type="text/markdown", long_description=LONG_DESCRIPTION,
url='https://github.com/CMiksche/gitea-auto-update', long_description_content_type="text/markdown",
author='Christoph Miksche', url='https://github.com/CMiksche/gitea-auto-update',
author_email='christoph@miksche.org', author='Christoph Miksche',
license='GPLv3', author_email='christoph@miksche.org',
classifiers=[ license='GPLv3',
"Programming Language :: Python :: 3", classifiers=[
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Programming Language :: Python :: 3",
"Operating System :: Unix", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
], "Operating System :: Unix",
keywords=['gitea', 'update', 'debian', 'linux'], ],
install_requires=[ keywords=['gitea', 'update', 'debian', 'linux'],
'requests', python_requires='>=3',
'packaging', install_requires=[
'fire', 'requests',
'configparser' 'packaging',
], 'fire',
packages=setuptools.find_packages(), 'configparser'
entry_points={ ],
'console_scripts': ['gitea-auto-update=gitea_auto_update.update:main'], packages=setuptools.find_packages(),
} entry_points={
) 'console_scripts': ['gitea-auto-update=gitea_auto_update.update:main'],
}
)

View File

@@ -1,38 +0,0 @@
'''
Gitea Auto Updater
Copyright 2019 The Gitea-Auto-Update Authors
All rights reserved.
License: GNU General Public License
'''
import gitea_auto_update.lib.version
import unittest
version = gitea_auto_update.lib.version.Version('', '')
class Tests(unittest.TestCase):
def testSimpleVersion(self):
self.assertTrue(version.checkVersion('1.9.1', '1.9.0'))
def testTwoIntVersion(self):
self.assertTrue(version.checkVersion('1.10.0', '1.9.0'))
def testFalseVersion(self):
self.assertFalse(version.checkVersion('1.8.0', '1.9.0'))
def testSameVersion(self):
self.assertFalse(version.checkVersion('1.9.7', '1.9.7'))
def testInt(self):
self.assertTrue(version.checkVersion('9', '8'))
def testSuffix(self):
self.assertTrue(version.checkVersion('1.9.0+dev-264-g8de76b6e6', '1.8.0'))
def testParseFileVersion(self):
self.assertEqual(version.parseFileVersion('Gitea version 1.8.1 built with go1.12.2 : bindata, sqlite, sqlite_unlock_notify'), '1.8.1')
if __name__ == '__main__':
unittest.main()