#!/bin/bash set -eEu set -v PIPELINE_ID=$RANDOM echo ${PIPELINE_ID} 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" ( mcli mirror --overwrite s3/repo/x86_64 /repo &>/dev/null rm "/repo/${AUR_REPO_NAME}.db" rm "/repo/${AUR_REPO_NAME}.db.sig" rm "/repo/${AUR_REPO_NAME}.files" # rm "/repo/${AUR_REPO_NAME}.files.sig" ln -sf "/repo/${AUR_REPO_NAME}.db.tar.xz" "/repo/${AUR_REPO_NAME}.db" ln -sf "/repo/${AUR_REPO_NAME}.files.tar.xz" "/repo/${AUR_REPO_NAME}.files" ln -sf "/repo/${AUR_REPO_NAME}.db.tar.xz.sig" "/repo/${AUR_REPO_NAME}.db.sig" ln -sf "/repo/${AUR_REPO_NAME}.files.tar.xz.sig" "/repo/${AUR_REPO_NAME}.files.sig" ) &>/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" 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 echo "C3FE87CFB8F8D503AE03EC1C033E7F3DC71FE89E:6:" | gpg --import-ownertrust --batch sudo pacman --noconfirm -Syu archlinux-keyring &>/dev/null git clone --recursive https://git.tobiasmanske.de/archlinux-repo/package_sources.git packages &>/dev/null cd packages 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 # find . -name PKGBUILD -execdir sh -c 'makepkg --printsrcinfo > .SRCINFO' \; # Obtain version of downloaded packages find . -iname PKGBUILD -exec dirname {} \; | aur srcver --no-prepare - >vcs # Rebuild all git packages if [ ! -z "$NO_GIT_REBUILD" ]; then cut -f1 vcs | grep -e "-git$" | tee -a buildqueue fi # add all outdated packages to the build queue aur repo --list | aur vercmp -q -p vcs | tee -a buildqueue # Build missing packages comm -23 <(cut -f1 vcs | sort) <(pacman -Slq "${AUR_REPO_NAME}" | sort) | tee -a buildqueue # Build all packages defined in buildqueue while read -r i; do cat "$i"/.SRCINFO done queue echo echo QUEUE echo cat queue if wc -l queue | grep -q "^0 "; then echo "Nothing to build, exiting." exit 0 fi ## BUILD aur build -S --noconfirm -a queue --no-sync --margs -s ## Upload to repo mcli mirror --overwrite /repo s3/repo/x86_64