arch/build-pkg/run.sh

60 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2021-05-13 15:44:34 +02:00
#!/bin/bash
set -e
DEFAULT_MAKEPKG_ARGS=('--syncdeps' '--noconfirm')
#################################
function main(){
# Write-permission for user "build"
sudo chown "build:wheel" /out
PKG=/pkg/"${1}"
shift; # remove first arg
echo "Looking for PKGBUILD in ${PKG} ..."
build-pkg "$@"
# Ensure permissions match those of the original PKGBUILD.
sudo chown "$(stat -c '%u:%g' "${PKG}"/PKGBUILD)" /out/*.pkg.tar.*
}
2021-05-13 15:44:34 +02:00
function build-pkg(){
# Make a copy as we don't want to change stuff inside "/pkg"
2021-05-13 15:44:34 +02:00
cp -r "${PKG}" /tmp/pkg
cd /tmp/pkg
MAKEPKG_ARGS=()
if [ "${#DEFAULT_MAKEPKG_ARGS[@]}" -gt 0 ]; then
2021-06-18 18:12:01 +02:00
MAKEPKG_ARGS+=("${DEFAULT_MAKEPKG_ARGS[@]}")
fi
if [ $# -gt 0 ]; then
MAKEPKG_ARGS+=("$@")
2021-06-14 20:16:40 +02:00
fi
2021-05-13 15:44:34 +02:00
# Build the package.
echo "Running: makepkg ${MAKEPKG_ARGS[*]}"
# Disable exit on error as we manually check the exit status in a switch-case
2021-05-13 15:44:34 +02:00
set +e
makepkg "${MAKEPKG_ARGS[@]}"; saved="$?";
2021-05-13 15:44:34 +02:00
set -e
case "${saved}" in
"0")
# Exit code 0, no error occurred.
true
;;
"13")
# Exit code 13: A package has already been built.
true # Skip already built packages!
;;
*)
# Exit with exit-code from makepkg.
2021-06-16 23:23:44 +02:00
echo "Error during build of package ${PKG}!"
2021-05-13 15:44:34 +02:00
exit ${saved}
;;
esac
}
main "$@"