2023-03-29 01:16:31 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-09-19 20:04:12 +02:00
|
|
|
# Build the package in a clean Archlinux/openSUSE/Debian/Ubuntu container
|
2024-02-07 00:16:21 +01:00
|
|
|
# Copyright (C) 2022-2024 Alexandre Pujol <alexandre@pujol.io>
|
2023-03-29 01:16:31 +02:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
2023-09-01 20:26:52 +02:00
|
|
|
# Usage: make package dist=<distribution>
|
2023-03-29 01:16:31 +02:00
|
|
|
|
2023-09-19 20:04:12 +02:00
|
|
|
set -eu -o pipefail
|
2023-03-29 01:16:31 +02:00
|
|
|
|
|
|
|
readonly BASEIMAGE="${BASEIMAGE:-registry.gitlab.com/roddhjav/builders}"
|
|
|
|
readonly PREFIX="builder-"
|
|
|
|
readonly PKGNAME=apparmor.d
|
|
|
|
readonly VOLUME=/tmp/build
|
|
|
|
readonly BUILDIR=/home/build/tmp
|
2024-10-17 00:58:48 +02:00
|
|
|
readonly OUTDIR=".pkg"
|
|
|
|
readonly OUTPUT="$PWD/$OUTDIR"
|
2023-03-29 01:16:31 +02:00
|
|
|
readonly COMMAND="$1"
|
2023-09-19 20:04:12 +02:00
|
|
|
VERSION="0.$(git rev-list --count HEAD)"
|
2023-03-29 01:16:31 +02:00
|
|
|
PACKAGER="$(git config user.name) <$(git config user.email)>"
|
|
|
|
readonly VERSION PACKAGER
|
|
|
|
|
|
|
|
_start() {
|
|
|
|
local img="$1"
|
|
|
|
docker start "$img"
|
|
|
|
}
|
|
|
|
|
|
|
|
_is_running() {
|
|
|
|
local img="$1"
|
|
|
|
res="$(docker inspect -f '{{ .State.Running }}' "$img")" &>/dev/null
|
|
|
|
exist=$?
|
|
|
|
if [[ $exist -ne 0 ]]; then
|
|
|
|
return $exist
|
|
|
|
elif [[ "$res" == true ]]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_exist() {
|
|
|
|
local img="$1"
|
|
|
|
docker inspect -f '{{ .State.Running }}' "$img" &>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
sync() {
|
|
|
|
mkdir -p "$VOLUME"
|
|
|
|
rsync -ra --delete . "$VOLUME/$PKGNAME"
|
|
|
|
}
|
|
|
|
|
|
|
|
build_in_docker_makepkg() {
|
|
|
|
local dist="$1"
|
|
|
|
local img="$PREFIX$dist"
|
|
|
|
|
|
|
|
if _exist "$img"; then
|
|
|
|
if ! _is_running "$img"; then
|
|
|
|
_start "$img"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
docker pull "$BASEIMAGE/$dist"
|
2023-09-19 20:04:12 +02:00
|
|
|
docker run -tid --name "$img" --volume "$VOLUME:$BUILDIR" \
|
2023-10-21 22:51:23 +02:00
|
|
|
--env PKGDEST="$BUILDIR" --env PACKAGER="$PACKAGER" \
|
|
|
|
--env BUILDDIR=/tmp/build \
|
2023-03-29 01:16:31 +02:00
|
|
|
"$BASEIMAGE/$dist"
|
|
|
|
fi
|
|
|
|
|
2023-09-19 20:04:12 +02:00
|
|
|
docker exec --workdir="$BUILDIR/$PKGNAME" "$img" bash dists/build.sh pkg
|
2024-10-17 00:58:48 +02:00
|
|
|
mv "$VOLUME/$PKGNAME/$OUTDIR/$PKGNAME"-*.pkg.* "$OUTPUT"
|
2023-03-29 01:16:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
build_in_docker_dpkg() {
|
2023-12-10 14:23:11 +01:00
|
|
|
local dist="$1" target="$1"
|
2023-03-29 01:16:31 +02:00
|
|
|
local img="$PREFIX$dist"
|
|
|
|
|
2023-12-10 14:23:11 +01:00
|
|
|
[[ "$dist" == whonix ]] && dist=debian
|
2023-03-29 01:16:31 +02:00
|
|
|
if _exist "$img"; then
|
|
|
|
if ! _is_running "$img"; then
|
|
|
|
_start "$img"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
docker pull "$BASEIMAGE/$dist"
|
|
|
|
docker run -tid --name "$img" --volume "$VOLUME:$BUILDIR" \
|
2024-03-05 19:29:44 +01:00
|
|
|
--env DISTRIBUTION="$target" "$BASEIMAGE/$dist"
|
2023-03-29 01:16:31 +02:00
|
|
|
docker exec "$img" sudo apt-get update -q
|
2023-11-19 22:04:58 +01:00
|
|
|
docker exec "$img" sudo apt-get install -y config-package-dev rsync
|
2024-06-04 21:01:05 +02:00
|
|
|
[[ "$dist" == debian ]] && aptopt=(-t bookworm-backports)
|
2023-04-17 12:26:09 +02:00
|
|
|
docker exec "$img" sudo apt-get install -y "${aptopt[@]}" golang-go
|
2023-03-29 01:16:31 +02:00
|
|
|
fi
|
|
|
|
|
2023-09-19 20:04:12 +02:00
|
|
|
docker exec --workdir="$BUILDIR/$PKGNAME" "$img" bash dists/build.sh dpkg
|
2024-10-17 00:58:48 +02:00
|
|
|
mv "$VOLUME/$PKGNAME/$OUTDIR/${PKGNAME}_${VERSION}-1"_*.* "$OUTPUT"
|
2023-09-19 20:04:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
build_in_docker_rpm() {
|
|
|
|
local dist="$1"
|
|
|
|
local img="$PREFIX$dist"
|
|
|
|
|
|
|
|
if _exist "$img"; then
|
|
|
|
if ! _is_running "$img"; then
|
|
|
|
_start "$img"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
docker pull "$BASEIMAGE/$dist"
|
|
|
|
docker run -tid --name "$img" --volume "$VOLUME:$BUILDIR" \
|
|
|
|
"$BASEIMAGE/$dist"
|
2024-06-14 22:02:34 +02:00
|
|
|
docker exec "$img" sudo zypper install -y distribution-release golang-packaging rsync apparmor-profiles
|
2023-09-19 20:04:12 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
docker exec --workdir="$BUILDIR/$PKGNAME" "$img" bash dists/build.sh rpm
|
2024-10-17 00:58:48 +02:00
|
|
|
mv "$VOLUME/$PKGNAME/$OUTDIR/$PKGNAME-$VERSION-"*.rpm "$OUTPUT"
|
2023-03-29 01:16:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
case "$COMMAND" in
|
|
|
|
archlinux)
|
2023-04-16 22:25:52 +02:00
|
|
|
# build_in_docker_makepkg "$COMMAND"
|
2024-10-07 15:05:40 +02:00
|
|
|
PKGDEST="$OUTPUT" makepkg -Cf
|
2023-03-29 01:16:31 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
debian | ubuntu | whonix)
|
|
|
|
sync
|
|
|
|
build_in_docker_dpkg "$COMMAND"
|
|
|
|
;;
|
|
|
|
|
2023-04-16 22:25:52 +02:00
|
|
|
opensuse)
|
2023-09-19 20:04:12 +02:00
|
|
|
sync
|
|
|
|
build_in_docker_rpm "$COMMAND"
|
2023-04-16 22:25:52 +02:00
|
|
|
;;
|
|
|
|
|
2023-03-29 01:16:31 +02:00
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-10-07 15:05:40 +02:00
|
|
|
mkdir -p "$OUTPUT"
|
2023-03-29 01:16:31 +02:00
|
|
|
main "$@"
|