From 800ded9aac3cb1d735609748a3967af3532d0cd9 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Mon, 7 Nov 2022 00:11:50 +0100 Subject: semi-working --- Dockerfile | 17 ++++++++++++--- bin/buildpackage.sh | 15 +++++++++++-- bin/getpackage.py | 63 +++++++++++++++++++++++++++++++++++++++++++---------- sudoers | 2 ++ testrun.sh | 2 +- 5 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 sudoers diff --git a/Dockerfile b/Dockerfile index 13bb9a3..e19e7af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,17 @@ FROM archlinux:base-devel -RUN pacman --noconfirm -Syu ARG AUR_RPC_BASE_URL="https://aur.archlinux.org/rpc/" ARG PACKAGE_NAME="" ARG BUILD_ALL_AUR_DEPENDS="no" +ARG PACKAGER="John Doe " + +RUN pacman --noconfirm -Syu +RUN pacman --noconfirm -S git sudo + +RUN groupadd sudo +RUN useradd -G sudo -d /workdir -m aurbuilder +COPY --chown=root:root sudoers /etc/sudoers + RUN mkdir /pkgout /db VOLUME /pkgout @@ -11,6 +19,9 @@ VOLUME /db RUN pacman --noconfirm -S python python-requests -COPY --chown=root:root buildpackage.sh /buildpackage.sh +RUN mkdir -p /opt/aurbuilder + +COPY --chown=root:root bin/ /opt/aurbuilder +ENV PATH="${PATH}:/opt/aurbuilder" -CMD /buildpackage.sh +CMD buildpackage.sh diff --git a/bin/buildpackage.sh b/bin/buildpackage.sh index 1de569b..4be1b3a 100755 --- a/bin/buildpackage.sh +++ b/bin/buildpackage.sh @@ -3,5 +3,16 @@ echo "BUILDING: $PACKAGE_NAME" echo "Build Deps: $BUILD_ALL_AUR_DEPENDS" -ls -l /db -ls -l /pkgout +cd /workdir || exit 1 + +while read NAME BASE VER _; do + echo $NAME $BASE $VER + + sudo -u aurbuilder git clone "https://aur.archlinux.org/$BASE.git" "$BASE" + cd "$BASE" || exit 1 + + # TODO: PKGDEST instead of copy + sudo -u aurbuilder makepkg --syncdeps --noconfirm --install + + cp ./*.pkg.tar.zst /pkgout +done <<< "$(getpackage.py "$PACKAGE_NAME")" diff --git a/bin/getpackage.py b/bin/getpackage.py index 3e3c0b9..5f85b8e 100755 --- a/bin/getpackage.py +++ b/bin/getpackage.py @@ -17,8 +17,18 @@ def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) +# TODO we should actually use version limits instead +def sanitize_name(_name): + _name = _name.replace('<','=') + _name = _name.replace('>','=') + + return _name.split('=')[0] + + # TODO: Don't just take the first one. prioritize maybe Votes, version, git, bin, ... def aur_search_package(_name): + _name = sanitize_name(_name) + data = requests.get(f'https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg={_name}').json() for r in data['results']: @@ -26,13 +36,17 @@ def aur_search_package(_name): if p is None: continue - if _name in p['Provides']: - return p + if 'Provides' in p: + for prov in p['Provides']: + if sanitize_name(prov) == _name: + return p return None def aur_get_package(_name): + _name = sanitize_name(_name) + data = requests.get(f'https://aur.archlinux.org/rpc/?v=5&type=info&arg={_name}').json() if len(data['results']) != 1: @@ -41,24 +55,47 @@ def aur_get_package(_name): return data['results'][0] -def repo_get_package(_name): +def repo_search_package(_name): + _name = sanitize_name(_name) + + data = requests.get(f'https://archlinux.org/packages/search/json/?q={_name}').json() + for r in data['results']: + p = repo_get_package(r['pkgname'], False) + if p is None: + continue + + if 'provides' in p: + for prov in p['provides']: + if sanitize_name(prov) == _name: + return p + + return None + + +def repo_get_package(_name, _search=True): + _name = sanitize_name(_name) + data = requests.get(f'https://archlinux.org/packages/search/json/?name={_name}').json() if len(data['results']) != 1: - return None + if _search: + return repo_search_package(_name) + else: + return None return data['results'][0] -# TODO: We should also search for package provides! def build_aur_dependencies(_pkgname): + _pkgname = sanitize_name(_pkgname) + ret = [] maybe_deps = aur_get_package(_pkgname) if maybe_deps is None: eprint(f'WARNING: {_pkgname} Was not found in AUR!') return [] - elif 'Dependencies' not in maybe_deps: + elif 'Depends' not in maybe_deps: return [] deps = maybe_deps['Depends'] @@ -73,7 +110,8 @@ def build_aur_dependencies(_pkgname): continue ret.append(dep) - ret += build_aur_dependencies(dep) + ret.insert(0,dep) + ret = build_aur_dependencies(dep) + ret return ret @@ -92,11 +130,6 @@ if maybe_base_pkg_info is None: exit(1) base_pkg_info = maybe_base_pkg_info -TO_BUILD[base_pkg_info['Name']] = { - 'version':base_pkg_info['Version'], - 'base':base_pkg_info['PackageBase'] - } - aur_deps = build_aur_dependencies(PKG) for dep in aur_deps: @@ -111,5 +144,11 @@ for dep in aur_deps: 'version':pkg['Version'], 'base':pkg['PackageBase'] } + +TO_BUILD[base_pkg_info['Name']] = { + 'version':base_pkg_info['Version'], + 'base':base_pkg_info['PackageBase'] + } + for e in TO_BUILD: print(f'{e}\t{TO_BUILD[e]["base"]}\t{TO_BUILD[e]["version"]}') diff --git a/sudoers b/sudoers new file mode 100644 index 0000000..d023346 --- /dev/null +++ b/sudoers @@ -0,0 +1,2 @@ +root ALL=(ALL) ALL +%sudo ALL=(ALL) NOPASSWD: ALL diff --git a/testrun.sh b/testrun.sh index e400469..955bc95 100755 --- a/testrun.sh +++ b/testrun.sh @@ -6,7 +6,7 @@ mkdir -p testrun/pkgout ./build.sh -docker run --name archpkg-test --env PACKAGE_NAME=python-octodns \ +docker run --name archpkg-test --env PACKAGE_NAME=minipro \ -v $(pwd)/testrun/db:/db -v $(pwd)/testrun/pkgout:/pkgout \ archpkg -- cgit v1.2.3