Skip to content

Instantly share code, notes, and snippets.

@domeniko-gentner
Last active February 26, 2022 17:51
Show Gist options
  • Save domeniko-gentner/50e2ffebe7b3fab59080a00bcb999b40 to your computer and use it in GitHub Desktop.
Save domeniko-gentner/50e2ffebe7b3fab59080a00bcb999b40 to your computer and use it in GitHub Desktop.
Updating gitea automatically
#!/usr/bin/env python3
from requests import get
from requests import exceptions
from subprocess import run
def fetch_newest_gitea():
# change prefix as needed
GITEA_INSTALL = "/usr/local/bin/gitea"
GITEA_OS = "linux-amd64"
try:
headers = {'Accept': 'application/json'}
r = get('https://dl.gitea.io/gitea', headers=headers)
info = r.json()
for gitea_version in info['RenderedDirs']:
if gitea_version['Class'] == "current":
folder = info['Path']
gitea_path = f'https://dl.gitea.io/{folder}/{gitea_version["Name"]}/gitea-{gitea_version["Name"]}-{GITEA_OS}'
print(f"Downloading {gitea_path}")
r = get(gitea_path, stream=True)
r.raw.decode_content = True
with open(f'gitea-{gitea_version["Name"]}-{GITEA_OS}', 'wb') as fp:
print("writing chunks...")
for chunk in r.iter_content(chunk_size=1024):
fp.write(chunk)
run("systemctl stop gitea", shell=True)
run(["mv", f'gitea-{gitea_version["Name"]}-{GITEA_OS}', GITEA_INSTALL])
run(["chmod", "+x", GITEA_INSTALL])
run("systemctl start gitea", shell=True)
run("systemctl status gitea", shell=True)
except exceptions.Timeout:
print("Connection timed out")
exit(1)
except exceptions.InvalidURL:
print("Invalid URL")
exit(1)
if __name__ == "__main__":
fetch_newest_gitea()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment