Skip to content

Instantly share code, notes, and snippets.

@foutrelis
Last active May 25, 2023 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foutrelis/5e056df579c836eabd30 to your computer and use it in GitHub Desktop.
Save foutrelis/5e056df579c836eabd30 to your computer and use it in GitHub Desktop.
#/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{,-testing,-staging}
extra{,-testing,-staging}
multilib{,-testing,-staging}
getkeys
updpkgsums' \
-- "$cur"))
;;
2)
COMPREPLY=($(compgen -W '
core{,-testing,-staging}-x86_64-build
extra{,-testing,-staging}-x86_64-build
multilib{,-testing,-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*)
buildcmd="$stagingdir-x86_64-build"
;;
multilib*)
buildcmd="$stagingdir-build"
;;
getkeys | updpkgsums)
buildcmd='false'
;;
*)
echo 'Unknown repo; exiting.'
exit 2
;;
esac
fi
# Upload sources
ssh $build_host mkdir $workdir
rsync -avz --exclude=.git --exclude=/src --exclude=/*.pkg.tar.zst . $build_host:$workdir/
# Update checksums if requested and exit
if [[ $1 == updpkgsums ]]; then
ssh -t $build_host "cd $workdir && updpkgsums" &&
scp $build_host:$workdir/PKGBUILD .
exit
fi
# Export PGP keys if requested and exit
if [[ $1 == getkeys ]]; then
ssh $build_host "cd $workdir && export-pkgbuild-keys" &&
scp -r $build_host:$workdir/keys .
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
if grep -q validpgpkeys PKGBUILD; then
scp -r $build_host:$workdir/keys . || exit 1
fi
# Copy packages to gemini
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