arch/build-pkg/run.sh

63 lines
1.4 KiB
Bash
Raw Normal View History

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
# Build the package.
# One could add argument "--noconfirm" to "makepkg" (which will be passed to Pacman) for non-interactive mode.
set +e
makepkg --syncdeps
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
# 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 "$@"