1
0
mirror of https://github.com/Luzifer/archrepo.git synced 2024-09-19 18:52:55 +00:00
archrepo/scripts/update-repo.sh
2023-08-30 19:37:03 +02:00

55 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
source ./scripts/script_framework.sh
REPO_DIR=${REPO_DIR:-$(pwd)}
REPO=${1:-}
[ -z "${REPO}" ] && fail "No repo given as CLI argument"
step "Checking for changes from last build"
last_remote_hash=$(git ls-remote ${REPO} master | awk '{print $1}')
grep "${REPO}#${last_remote_hash}" .repo_cache && {
warn "Remote has no changes from last build, skipping..."
exit 0
} || true
# Create working dir
TMPDIR="/tmp/aur2repo_$(basename ${REPO})"
mkdir -p "${TMPDIR}/cfg"
# Ensure cleanup on script exit
function cleanup() {
rm -rf "${TMPDIR}"
}
trap cleanup EXIT
step "Fetching signing key"
vault read --field=key secret/jenkins/arch-signing >"${TMPDIR}/cfg/signing.asc"
step "Re-fetching Docker image"
docker pull git.luzifer.io/registry/arch-repo-builder
step "Building package $(basename ${REPO})"
extra_opts=()
if [[ -f /etc/pacman.d/mirrorlist ]]; then
info "Using host system mirrorlist..."
extra_opts+=(-v "/etc/pacman.d/mirrorlist:/etc/pacman.d/mirrorlist:ro")
fi
docker run --rm -ti \
-v "${TMPDIR}/src:/src" \
-v "${TMPDIR}/cfg:/config" \
-v "${REPO_DIR}:/repo" \
-v "$(pwd)/scripts/pacman.conf:/etc/pacman.conf:ro" \
"${extra_opts[@]}" \
--ulimit nofile=262144:262144 \
git.luzifer.io/registry/arch-repo-builder \
"${REPO}"
step "Updating cache entry"
grep -v "^${REPO}#" .repo_cache >.repo_cache.tmp || true
echo "${REPO}#${last_remote_hash}" >>.repo_cache.tmp
mv .repo_cache.tmp .repo_cache