2021-05-13 15:44:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# For each ARG in ARGUMENTS
|
|
|
|
# build /pkg/$ARG/PKGBUILD
|
|
|
|
# and store the built package at /out/
|
|
|
|
#
|
|
|
|
# If no ARGUMENTS are given, then fallback to path /pkg/PKGBUILD
|
|
|
|
#
|
|
|
|
set -e
|
|
|
|
|
|
|
|
function build-pkg(){
|
|
|
|
# Make a copy as "/pkg" might be read-only and we do not want to alter it
|
|
|
|
cp -r "${PKG}" /tmp/pkg
|
|
|
|
cd /tmp/pkg
|
|
|
|
|
2021-06-14 20:16:40 +02:00
|
|
|
MAKEPKG_ARGS=('--syncdeps')
|
|
|
|
if [ "${INTERACTIVE}" != "true" ]; then
|
|
|
|
MAKEPKG_ARGS+=('--noconfirm') # --noconfirm is passed to pacman
|
|
|
|
fi
|
|
|
|
|
2021-05-13 15:44:34 +02:00
|
|
|
# Build the package.
|
|
|
|
set +e
|
2021-06-14 20:16:40 +02:00
|
|
|
makepkg "${MAKEPKG_ARGS[@]}"
|
2021-05-13 15:44:34 +02:00
|
|
|
saved="$?"
|
|
|
|
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.
|
|
|
|
exit ${saved}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
function main(){
|
|
|
|
# Write-permission for user "build"
|
|
|
|
sudo chown "build:wheel" /out
|
|
|
|
|
2021-05-13 17:14:49 +02:00
|
|
|
# Refresh mirrors
|
|
|
|
sudo pacman -Sy
|
2021-05-13 15:44:34 +02:00
|
|
|
|
2021-06-14 20:16:40 +02:00
|
|
|
if [ "${1}" = "interactive" ]; then
|
|
|
|
INTERACTIVE=true
|
|
|
|
shift; # remove first argument
|
|
|
|
fi
|
|
|
|
|
2021-05-13 15:44:34 +02:00
|
|
|
# If first argument is zero, use default directory
|
|
|
|
if [ -z "${1}" ]; then
|
|
|
|
PKG=/pkg
|
2021-05-14 12:59:53 +02:00
|
|
|
echo "No argument given. Using default directory ${PKG} to look for PKGBUILD ..."
|
|
|
|
# Else append argument $1 as relative path
|
2021-05-13 15:44:34 +02:00
|
|
|
else
|
2021-05-14 12:59:53 +02:00
|
|
|
PKG=/pkg/"${1}"
|
|
|
|
echo "Looking for PKGBUILD in ${PKG} ..."
|
2021-05-13 15:44:34 +02:00
|
|
|
fi
|
|
|
|
|
2021-05-14 12:59:53 +02:00
|
|
|
build-pkg
|
|
|
|
|
2021-05-13 15:44:34 +02:00
|
|
|
# Ensure permissions match those of the original PKGBUILD.
|
|
|
|
sudo chown "$(stat -c '%u:%g' "${PKG}"/PKGBUILD)" /out/*.pkg.tar.*
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|