From 045d4752baaf837ca9d12eb03e5588e1af824451 Mon Sep 17 00:00:00 2001 From: Christoph Miksche Date: Mon, 26 Nov 2018 21:47:12 +0100 Subject: [PATCH] publish actual version --- README.md | 33 +++++++++++++++++++++++++++++++++ settings.py | 16 ++++++++++++++++ updater.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 README.md create mode 100644 settings.py create mode 100644 updater.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..4df55e1 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Gitea Remote Updater + +Script for a automatic update of gitea. Should be run locally on the gitea server. + +## Procedure +* Get Gitea Version via Gitea API +* Get latest Relase via GitHub API +* Check if there is a newer Version +* If true + * Download new version, overwrite old version + +## General Information +License: GNU General Public License + +Author: Christoph Daniel Miksche (m5e.de) + +Uses python version 3 + +## Installation + +1. Use the following command to install all dependencies. + + ``` + sudo pip install requests + ``` + +2. Then clone the git repository. + +3. After that, please change the variables in the settings.py file. + +4. Enter the command `python updater.py` in your commandline. + +5. If you want to schedule your updates, edit your /etc/crontab file. diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..1ae655b --- /dev/null +++ b/settings.py @@ -0,0 +1,16 @@ +''' +Gitea Remote Updater + +Copyright 2018 Christoph Daniel Miksche +All rights reserved. + +License: GNU General Public License +''' +# Gitea Site +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 = '/home/git/gitea' diff --git a/updater.py b/updater.py new file mode 100644 index 0000000..3699a30 --- /dev/null +++ b/updater.py @@ -0,0 +1,44 @@ +''' +Gitea Remote Updater + +Copyright 2018 Christoph Daniel Miksche +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) + +# Version from gitea site +current_version = requests.get(settings.gtsite).json()['version'] + +# Get version tag from github and remove first char (v) +github_version_tag = requests.get(settings.gtgithubapiurl).json()['tag_name'] + +# 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") + + # Set download url + gtdownload = 'https://github.com/go-gitea/gitea/releases/download/'+github_version_tag+'/gitea-'+github_version+'-'+settings.gtsystem + + # Download file + download(gtdownload, settings.gtfile) + + # Start systemd service + os.system("systemctl start gitea.service")