Base builder
This commit is contained in:
commit
4212caa4c0
|
@ -0,0 +1,8 @@
|
|||
.vscode
|
||||
.venv
|
||||
|
||||
# Python
|
||||
*.pyc
|
||||
|
||||
# Debian builds
|
||||
*.deb
|
|
@ -0,0 +1,22 @@
|
|||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.2.3
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: flake8
|
||||
|
||||
- repo: https://github.com/asottile/seed-isort-config
|
||||
rev: v1.9.2
|
||||
hooks:
|
||||
- id: seed-isort-config
|
||||
- repo: https://github.com/pre-commit/mirrors-isort
|
||||
rev: v4.3.20
|
||||
hooks:
|
||||
- id: isort
|
||||
|
||||
- repo: https://github.com/ambv/black
|
||||
rev: stable
|
||||
hooks:
|
||||
- id: black
|
||||
language_version: python3.7
|
|
@ -0,0 +1,15 @@
|
|||
FROM archlinux/base:latest
|
||||
LABEL MAINTAINER "Felipe Martin <me@fmartingr.com>"
|
||||
|
||||
COPY requirements.txt /tmp/requirements.txt
|
||||
|
||||
RUN pacman -Syu --noconfirm python python-pip base-devel && \
|
||||
pip install -r /tmp/requirements.txt && \
|
||||
useradd builder
|
||||
|
||||
USER builder
|
||||
|
||||
COPY build.py /tmp/build.py
|
||||
WORKDIR /tmp
|
||||
|
||||
CMD ["python", "/tmp/build.py"]
|
|
@ -0,0 +1,13 @@
|
|||
# AUR Synology Drive Builder
|
||||
|
||||
[![AUR Synology Drive](https://img.shields.io/badge/AUR-synology--drive-green.svg)](https://aur.archlinux.org/packages/synology-drive/)
|
||||
|
||||
Simple script to generate the AUR builds for the Synology Drive software.
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
./docker-build.sh VERSION BUILD_NUMBER
|
||||
```
|
||||
|
||||
This will generate a new folder in the builds folder with the _PKGBUILD_ and _.SRCINFO_ files which are the required files to create an AUR package.
|
|
@ -0,0 +1,87 @@
|
|||
import os
|
||||
import hashlib
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import toml
|
||||
import huepy
|
||||
import requests
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
PACKAGE_NAME = os.environ["PACKAGE_NAME"]
|
||||
BUILDS_PATH = Path(f"/tmp/{PACKAGE_NAME}/builds")
|
||||
PACKAGE_FILE = f"/tmp/{PACKAGE_NAME}/package.toml"
|
||||
|
||||
package = toml.load(PACKAGE_FILE)
|
||||
print(
|
||||
huepy.run(
|
||||
f'Building {PACKAGE_NAME} v{package["version"]}-{package["build_number"]}'
|
||||
)
|
||||
)
|
||||
|
||||
if os.path.isdir(BUILDS_PATH / Path(f"{package['version']}-{package['build_number']}")):
|
||||
print(
|
||||
huepy.bad(
|
||||
f"{PACKAGE_NAME} {package['version']}-{package['build_number']} is already present."
|
||||
)
|
||||
)
|
||||
exit(1)
|
||||
|
||||
|
||||
def md5sum(url):
|
||||
response = requests.get(url, stream=True)
|
||||
hash_md5 = hashlib.md5()
|
||||
for chunk in response.iter_content(chunk_size=512):
|
||||
hash_md5.update(chunk)
|
||||
return hash_md5.hexdigest()
|
||||
|
||||
|
||||
class DebianBuilder:
|
||||
template = "PKGBUILD.debian.j2"
|
||||
|
||||
def update_package_definition(self, package):
|
||||
if "i686" in package["arch"]:
|
||||
source_i686 = package["sources"]["i686"]["url"].format(**package)
|
||||
package["sources"]["i686"]["url"] = source_i686
|
||||
package["sources"]["i686"]["md5sum"] = md5sum(source_i686)
|
||||
|
||||
if "x86_64" in package["arch"]:
|
||||
source_x86_64 = package["sources"]["x86_64"]["url"].format(**package)
|
||||
package["sources"]["x86_64"]["url"] = source_x86_64
|
||||
package["sources"]["x86_64"]["md5sum"] = md5sum(source_x86_64)
|
||||
|
||||
|
||||
BUILDERS = {"debian": DebianBuilder}
|
||||
|
||||
print(huepy.run(f"Using {package['builder']} builder"))
|
||||
builder = BUILDERS[package["builder"]]()
|
||||
builder.update_package_definition(package)
|
||||
|
||||
print(huepy.run("Generating PKGBUILD"))
|
||||
env = Environment(
|
||||
loader=FileSystemLoader(["templates", f"/tmp/{PACKAGE_NAME}"]), trim_blocks=True
|
||||
)
|
||||
if not os.path.isfile(f"/tmp/{PACKAGE_NAME}/PKGBUILD"):
|
||||
pkgbuild_template = env.get_template(builder.template)
|
||||
else:
|
||||
print(huepy.info("Using package-specific template"))
|
||||
pkgbuild_template = env.get_template("PKGBUILD")
|
||||
pkgbuild = pkgbuild_template.render(**package)
|
||||
|
||||
build_path = BUILDS_PATH / Path("{version}-{build_number}".format(**package))
|
||||
os.makedirs(build_path, exist_ok=True)
|
||||
|
||||
print(huepy.info(f"Writing PKGBUILD file..."))
|
||||
with open("%s/PKGBUILD" % build_path, "w") as handler:
|
||||
handler.write(pkgbuild)
|
||||
|
||||
print(huepy.info("Wiring .SRCINFO file..."))
|
||||
result = subprocess.run(
|
||||
"makepkg --printsrcinfo > .SRCINFO", shell=True, cwd=build_path, capture_output=True
|
||||
)
|
||||
if result.returncode != 0:
|
||||
print(huepy.bad("Error writing .SRCINFO file"))
|
||||
print(result.stderr)
|
||||
print(result.stdout)
|
||||
|
||||
print(huepy.good("Build finished"))
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash -xe
|
||||
|
||||
NAME=$1
|
||||
|
||||
docker build -t aur-package-builder .
|
||||
|
||||
clear
|
||||
|
||||
docker run -it --rm \
|
||||
-e PACKAGE_NAME="$NAME" \
|
||||
-v "$PWD/$NAME:/tmp/$NAME" \
|
||||
-v "$PWD/templates:/tmp/templates" \
|
||||
aur-package-builder
|
|
@ -0,0 +1,5 @@
|
|||
-r requirements.txt
|
||||
black
|
||||
flake8
|
||||
isort
|
||||
pre-commit
|
|
@ -0,0 +1,4 @@
|
|||
jinja2
|
||||
requests
|
||||
toml
|
||||
huepy
|
|
@ -0,0 +1,16 @@
|
|||
[flake8]
|
||||
ignore = E203, E266, E501, W503, F403
|
||||
max-line-length = 88
|
||||
max-complexity = 18
|
||||
select = B,C,E,F,W,T4,B9
|
||||
|
||||
[isort]
|
||||
use_parentheses = True
|
||||
multi_line_output = 3
|
||||
include_trailing_comma = True
|
||||
length_sort = 1
|
||||
lines_between_types = 0
|
||||
line_length = 88
|
||||
known_third_party = huepy,jinja2,requests,toml
|
||||
sections = FUTURE, STDLIB, DJANGO, THIRDPARTY, FIRSTPARTY, LOCALFOLDER
|
||||
no_lines_before = LOCALFOLDER
|
|
@ -0,0 +1,26 @@
|
|||
# Maintainer: Felipe Martin <me@fmartingr.com>
|
||||
|
||||
pkgname="{{ name }}"
|
||||
pkgver="{{ version }}"
|
||||
pkgrel="{{ build_number }}"
|
||||
pkgdesc="{{ description }}"
|
||||
arch=('{{ arch|join("' '") }}')
|
||||
url="{{ url }}"
|
||||
license=('{{ license }}')
|
||||
depends=('{{ depends|join("' '") }}')
|
||||
optdepends=('{{ optdepends|join("' '") }}')
|
||||
conflicts=('{{ conflicts|join("' '") }}')
|
||||
source=()
|
||||
md5sums=()
|
||||
|
||||
{% if "i686" in arch %}
|
||||
source_i686=({{ sources.i686.url }})
|
||||
md5sums_i686=('{{ sources.i686.md5sum }}')
|
||||
{% endif %}
|
||||
|
||||
{% if "x86_64" in arch %}
|
||||
source_x86_64=({{ sources.x86_64.url }})
|
||||
md5sums_x86_64=('{{ sources.x86_64.md5sum }}')
|
||||
{% endif %}
|
||||
|
||||
{% block operations%}{% endblock %}
|
|
@ -0,0 +1,16 @@
|
|||
{% extends "PKGBUILD.base.j2" %}
|
||||
|
||||
{% block operations %}
|
||||
prepare() {
|
||||
cd "$srcdir"
|
||||
mkdir -p data
|
||||
ar x {{ name }}-*
|
||||
xz -d data.tar.xz
|
||||
tar xf data.tar --directory data
|
||||
}
|
||||
|
||||
package() {
|
||||
cp -r "$srcdir/data/opt" "$pkgdir/opt"
|
||||
cp -r "$srcdir/data/usr" "$pkgdir/usr"
|
||||
}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue