Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#/bin/bash
# Load bash completion and return immediately if we are being sourced
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
_celestia-build() {
local cur=${COMP_WORDS[COMP_CWORD]}
case $COMP_CWORD in
1)
COMPREPLY=($(compgen -W '
core extra community multilib
testing community-testing multilib-testing
staging community-staging multilib-staging
updpkgsums' \
-- "$cur"))
;;
2)
COMPREPLY=($(compgen -W '
extra-x86_64-build
testing-x86_64-build
staging-x86_64-build
multilib-build
multilib-testing-build
multilib-staging-build
' -X "${COMP_WORDS[COMP_CWORD-1]}" \
-- "$cur"))
;;
esac
}
complete -F _celestia-build celestia-build
return
fi
if [[ ! -f PKGBUILD ]]; then
echo 'Missing PKGBUILD.'
exit 1
fi
stagingdir=$1
buildcmd=$2
build_host=build.archlinux.org
pkgbase=$(. PKGBUILD; echo ${pkgbase:-$pkgname})
workdir=$pkgbase-$RANDOM
# Cleanup on exit
trap "ssh $build_host rm -rf $workdir" EXIT
if [[ -z $buildcmd ]]; then
# Choose build command based on target repo
case $stagingdir in
core|extra|community)
buildcmd='extra-x86_64-build'
;;
testing|community-testing)
buildcmd='testing-x86_64-build'
;;
staging|community-staging)
buildcmd='staging-x86_64-build'
;;
multilib)
buildcmd='multilib-build'
;;
multilib-testing)
buildcmd='multilib-testing-build'
;;
multilib-staging)
buildcmd='multilib-staging-build'
;;
updpkgsums)
buildcmd='false'
;;
*)
echo 'Unknown repo; exiting.'
exit 2
esac
fi
# Upload sources
ssh $build_host mkdir $workdir
rsync -avzz --exclude=/src --exclude=/*.pkg.tar.zst . $build_host:$workdir/
# Update checksums only if requested
if [[ $1 == updpkgsums ]]; then
ssh -t $build_host "cd $workdir && updpkgsums" &&
scp $build_host:$workdir/PKGBUILD .
exit
fi
# Build
if [[ -t 2 ]]; then
ssh -t $build_host "cd $workdir && $buildcmd" || exit 1
else
ssh $build_host "cd $workdir && $buildcmd" || exit 1
fi
# Download packages
scp $build_host:$workdir/*.pkg.tar.zst . || exit 1
# Copy packages to orion
if [[ -n $stagingdir ]]; then
ssh repos.archlinux.org -t scp $build_host:$workdir/*.pkg.tar.zst staging/$stagingdir/
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment