builder/entrypoint.sh

124 lines
3.1 KiB
Bash
Raw Normal View History

#!/bin/bash
set -eEu
2023-03-27 07:15:54 +02:00
set -v
PIPELINE_ID=$RANDOM
echo ${PIPELINE_ID}
2023-03-27 04:28:02 +02:00
sudo pacman-key --init
# Pull Repo
## Needed so pacman doesnt complain.
repo-add "/repo/${AUR_REPO_NAME}.db.tar.xz"
sudo pacman -Syu --noconfirm minio-client pacman-contrib &>/dev/null # Setup tooling
mcli alias set s3 https://s3.tobiasmanske.de "${REPO_ACCESS_KEY}" "${REPO_SECRET_KEY}"
# LOCK
LOCK=""
while [[ "${LOCK}" != "${PIPELINE_ID}" ]]; do
LOCK=$(mcli cat s3/repo/LOCK)
if [[ "${LOCK}" == "FREE" ]]; then
echo $PIPELINE_ID | mcli pipe s3/repo/LOCK
fi
echo "Waiting for lock with id $PIPELINE_ID..."
sleep $((RANDOM % 10))
done
unlock() {
if [[ "${LOCK}" == "${PIPELINE_ID}" ]]; then
echo "FREE" | mcli pipe s3/repo/LOCK
fi
}
trap unlock EXIT INT TERM
echo "Pulling Repository"
(
2023-03-28 11:01:11 +02:00
mcli cp "s3/repo/x86_64/${AUR_REPO_NAME}.db.tar.xz" /repo
mcli cp "s3/repo/x86_64/${AUR_REPO_NAME}.db.tar.xz.sig" /repo
mcli cp "s3/repo/x86_64/${AUR_REPO_NAME}.files.tar.xz" /repo
mcli cp "s3/repo/x86_64/${AUR_REPO_NAME}.files.tar.xz.sig" /repo
) &>/dev/null
if ! (aur repo >/dev/null 2>&1); then
printf "Aur repo not initialized, initializing /repo...\n"
repo-add "/repo/${AUR_REPO_NAME}.db.tar.xz"
2023-03-27 04:28:02 +02:00
fi
# Keyring Signing Key
sudo pacman-key --add trustroot.asc
gpg --import --batch trustroot.asc
sudo pacman-key --lsign 10BE06BC275CE0E17373B368F67996C486D1B56B
# Setup signing
echo "${BUILD_GPG_KEY:-}" | base64 -d | gpg --import --batch
2023-03-27 04:28:02 +02:00
echo "C3FE87CFB8F8D503AE03EC1C033E7F3DC71FE89E:6:" | gpg --import-ownertrust --batch
sudo pacman --noconfirm -Syu archlinux-keyring &>/dev/null
2023-03-27 04:28:02 +02:00
git clone --recursive https://git.tobiasmanske.de/archlinux-repo/package_sources.git packages &>/dev/null
2023-03-27 04:28:02 +02:00
cd packages
2023-03-27 07:15:54 +02:00
touch buildqueue
## OBTAIN PACKAGES TO BUILD
git submodule update --remote --merge &>/dev/null # Make sure we are up to date if something is linked as a submodule
2023-03-27 04:52:34 +02:00
#
2023-03-27 04:28:02 +02:00
find . -name PKGBUILD -execdir sh -c 'makepkg --printsrcinfo > .SRCINFO' \;
2023-03-27 08:39:00 +02:00
# Obtain version of downloaded packages
find . -iname PKGBUILD -exec dirname {} \; | aur srcver --no-prepare - >vcs
2023-03-27 07:15:54 +02:00
2023-03-28 12:29:44 +02:00
# *missing Dependency resolution
cut -f1 vcs | aur depends -r - | tsort > dependencies
comm -23 <(sort dependencies) <(cut -f1 vcs | sort) | tee -a buildqueue | tee -a dep_missing | aur fetch -
if wc -l dep_missing | grep -q "^0 "; then
echo "No missing dependencies."
else
echo "!!! Missing dependencies !!!"
cat dep_missing
echo "!!! Missing dependencies !!!"
fi
2023-03-27 08:39:00 +02:00
# Rebuild all git packages
2023-03-28 11:01:11 +02:00
if [ -z "${NO_GIT_REBUILD:-}" ]; then
cut -f1 vcs | grep -e "-git$" | tee -a buildqueue
fi
2023-03-27 07:15:54 +02:00
2023-03-27 08:39:00 +02:00
# add all outdated packages to the build queue
aur repo --list | aur vercmp -q -p vcs | tee -a buildqueue
2023-03-27 07:15:54 +02:00
# Build missing packages
comm -23 <(cut -f1 vcs | sort) <(pacman -Slq "${AUR_REPO_NAME}" | sort) | tee -a buildqueue
2023-03-27 07:15:54 +02:00
# Build all packages defined in buildqueue
while read -r i; do
cat "$i"/.SRCINFO
done <buildqueue | aur graph | tsort | tac >queue
2023-03-27 04:28:02 +02:00
echo
echo QUEUE
echo
cat queue
2023-03-27 07:15:54 +02:00
if wc -l queue | grep -q "^0 "; then
echo "Nothing to build, exiting."
exit 0
fi
2023-03-27 07:15:54 +02:00
## BUILD
2023-03-27 04:28:02 +02:00
aur build -S --noconfirm -a queue --no-sync --margs -s
## Upload to repo
mcli mirror --overwrite /repo s3/repo/x86_64