From 35195710ed0cfa53f3f46f845c9769623f29f3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 26 Feb 2023 13:14:09 +0100 Subject: [PATCH] add script/files to download binary and create .deb --- Makefile | 48 ++++++++++++++++++++++++++++++++++++++++++++ debian/changelog | 5 +++++ debian/control | 10 +++++++++ debian/gitea.service | 41 +++++++++++++++++++++++++++++++++++++ debian/rules | 7 +++++++ debian/source/format | 1 + download.py | 45 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 157 insertions(+) create mode 100644 Makefile create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/gitea.service create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100644 download.py diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3dc99b6 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +.PHONY: clean name version fullname dist dist-bzip2 + +NAME=gitea +VERSION=`git describe | sed 's/^v//; s/-/./g' ` + +prefix = /usr + +gitea: + python3 download.py $(VERSION) + chmod +x gitea + +all: gitea + +install: gitea + +clean: + rm -f gitea + +DIST_FILES = \ + COPYING \ + Makefile \ + download.py + +dist: clean + -mkdir sdist + rm -rf sdist/$(NAME)-$(VERSION) + mkdir -p sdist/$(NAME)-$(VERSION) + echo $(VERSION) > sdist/$(NAME)-$(VERSION)/VERSION + for i in $(DIST_FILES); do \ + cp -R "$$i" sdist/$(NAME)-$(VERSION); \ + done + +install: gitea + mkdir -p $(DESTDIR)$(prefix)/bin/ + cp -r gitea $(DESTDIR)$(prefix)/bin/ + +dist-bzip2: dist + -mkdir sdist + cd sdist && tar cfj ../sdist/$(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION) + +version: + @(echo $(VERSION)) + +name: + @(echo $(NAME)) + +fullname: + @(echo $(NAME)-$(VERSION)) diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..94cd8c5 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +gitea (1.18.5-1) unstable; urgency=low + + * Initial release + + -- Frederic Peters Sun, 26 Feb 2023 12:42:38 +0100 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..377e4ae --- /dev/null +++ b/debian/control @@ -0,0 +1,10 @@ +Source: gitea +Maintainer: info@entrouvert.com +Section: web +Priority: optional +Build-Depends: debhelper-compat (= 12), python3-all, python3-requests, xz-utils +Standards-Version: 3.9.6 + +Package: gitea +Architecture: amd64 +Description: Git with a cup of tea, painless self-hosted git service diff --git a/debian/gitea.service b/debian/gitea.service new file mode 100644 index 0000000..80f84b4 --- /dev/null +++ b/debian/gitea.service @@ -0,0 +1,41 @@ +[Unit] +Description=Gitea (Git with a cup of tea) +After=syslog.target +After=network.target + +[Service] +# Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that +# LimitNOFILE=524288:524288 +RestartSec=2s +Type=simple +User=gitea +Group=gitea +WorkingDirectory=/var/lib/gitea/ +# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file +# (manually creating /run/gitea doesn't work, because it would not persist across reboots) +RuntimeDirectory=gitea +ExecStart=/usr/bin/gitea web --config /etc/gitea/app.ini +Restart=always +Environment=USER=gitea HOME=/home/gitea GITEA_WORK_DIR=/var/lib/gitea +# If you install Git to directory prefix other than default PATH (which happens +# for example if you install other versions of Git side-to-side with +# distribution version), uncomment below line and add that prefix to PATH +# Don't forget to place git-lfs binary on the PATH below if you want to enable +# Git LFS support +#Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin +# If you want to bind Gitea to a port below 1024, uncomment +# the two values below, or use socket activation to pass Gitea its ports as above +### +#CapabilityBoundingSet=CAP_NET_BIND_SERVICE +#AmbientCapabilities=CAP_NET_BIND_SERVICE +### +# In some cases, when using CapabilityBoundingSet and AmbientCapabilities option, you may want to +# set the following value to false to allow capabilities to be applied on gitea process. The following +# value if set to true sandboxes gitea service and prevent any processes from running with privileges +# in the host user namespace. +### +#PrivateUsers=false +### + +[Install] +WantedBy=multi-user.target diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..74ea88a --- /dev/null +++ b/debian/rules @@ -0,0 +1,7 @@ +#!/usr/bin/make -f + +export DEB_BUILD_OPTIONS=nostrip +#export DH_VERBOSE=1 + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/download.py b/download.py new file mode 100644 index 0000000..10eaae2 --- /dev/null +++ b/download.py @@ -0,0 +1,45 @@ +#! /usr/bin/env python3 + +import hashlib +import os +import subprocess +import sys + +import requests + +if os.path.exists('gitea'): + os.unlink('gitea') + +if len(sys.argv) > 1: + version = sys.argv[1].split('.') +elif os.path.exists('VERSION'): + with open('VERSION') as fd: + version = fd.read() + +version = '.'.join(version.split('.')[:3]) + +url = f'https://github.com/go-gitea/gitea/releases/download/v{version}/gitea-{version}-linux-amd64.xz' +print('downloading', url) +r = requests.get(url) +if not r.ok: + print('failed to download') + sys.exit(1) + +sha_r = requests.get(f'{url.removesuffix(".xz")}.sha256') +if not sha_r.ok: + print('failed to download checksum') + sys.exit(1) + +sha = sha_r.text.split()[0] + +with open('gitea.xz', 'wb') as fd: + fd.write(r.content) + +p = subprocess.run(['unxz', 'gitea.xz']) + +with open('gitea', 'rb') as fd: + checksum = hashlib.sha256(fd.read()).hexdigest() + if checksum != sha: + print(f'invalid checksum, {checksum} (expected: {sha})') + os.unlink('gitea') + sys.exit(1)