Add timeout for makepkg

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-02-18 15:57:04 +01:00
parent c7a21ddca0
commit 2daa9d20f4
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5

76
run.sh
View file

@ -1,24 +1,26 @@
#!/usr/local/bin/dumb-init /bin/bash #!/usr/local/bin/dumb-init /bin/bash
set -euo pipefail set -euo pipefail
: ${TIMEOUT:=0} # allow to restrict runtime of the makepkg build
MAKEPKG_OPTS=(-cCs --noconfirm --needed) MAKEPKG_OPTS=(-cCs --noconfirm --needed)
REPOADD_OPTS=() REPOADD_OPTS=()
SKIP_VERIFY="${SKIP_VERIFY:-}" SKIP_VERIFY="${SKIP_VERIFY:-}"
while getopts ":hRs" opt; do while getopts ":hRs" opt; do
case "${opt}" in case "${opt}" in
R) # Remove older version of package from repo R) # Remove older version of package from repo
REPOADD_OPTS+=(-R) REPOADD_OPTS+=(-R)
;; ;;
s) # Skip PGP check for source signatures s) # Skip PGP check for source signatures
SKIP_VERIFY="true" SKIP_VERIFY="true"
;; ;;
h | *) # Display help h | *) # Display help
echo "Usage:" echo "Usage:"
grep '\s.)\ #' $0 grep '\s.)\ #' $0
exit 1 exit 1
;; ;;
esac esac
done done
SRC=${1:-} SRC=${1:-}
@ -27,34 +29,34 @@ SRC=${1:-}
cd /src cd /src
if [ ! -e PKGBUILD ]; then if [ ! -e PKGBUILD ]; then
if [ -z "${SRC}" ]; then if [ -z "${SRC}" ]; then
echo "No /src/PKGBUILD was found and no repo to clone was given as parameter" echo "No /src/PKGBUILD was found and no repo to clone was given as parameter"
exit 1 exit 1
fi fi
# Ensure permissions on src # Ensure permissions on src
chown -R builder /src chown -R builder /src
gosu builder git clone "${SRC}" /src/git gosu builder git clone "${SRC}" /src/git
cd /src/git cd /src/git
fi fi
[[ ${SKIP_VERIFY:-} == true ]] && { [[ ${SKIP_VERIFY:-} == true ]] && {
MAKEPKG_OPTS+=(--skippgpcheck) MAKEPKG_OPTS+=(--skippgpcheck)
} }
[ -e /config/signing.asc ] && { [ -e /config/signing.asc ] && {
gosu builder gpg --import </config/signing.asc gosu builder gpg --import </config/signing.asc
MAKEPKG_OPTS+=(--sign) MAKEPKG_OPTS+=(--sign)
REPOADD_OPTS+=(--sign) REPOADD_OPTS+=(--sign)
} }
if [ -e /config/pacman.conf ]; then if [ -e /config/pacman.conf ]; then
# Allow full overwrite of pacman.conf # Allow full overwrite of pacman.conf
cp /config/pacman.conf /etc/pacman.conf cp /config/pacman.conf /etc/pacman.conf
elif [ -e /config/pacman.conf.partial ]; then elif [ -e /config/pacman.conf.partial ]; then
# Allow to provide a partial pacman.conf to append # Allow to provide a partial pacman.conf to append
cat /config/pacman.conf.partial >>/etc/pacman.conf cat /config/pacman.conf.partial >>/etc/pacman.conf
fi fi
# Update pacman index and any updated package # Update pacman index and any updated package
@ -64,21 +66,21 @@ pacman -Syyu --noconfirm
gosu builder getkeys.sh gosu builder getkeys.sh
# Execute the build itself # Execute the build itself
gosu builder makepkg ${MAKEPKG_OPTS[@]} gosu builder timeout ${TIMEOUT} makepkg ${MAKEPKG_OPTS[@]}
PACKAGE=($(find . -regextype egrep -regex '^.*\.pkg(|\.tar|\.tar\.xz|\.tar\.zst)$')) PACKAGE=($(find . -regextype egrep -regex '^.*\.pkg(|\.tar|\.tar\.xz|\.tar\.zst)$'))
REPODB=$(find /repo -regextype egrep -regex '^.*\.db(\.tar|\.tar\.xz|\.tar.zst)$') REPODB=$(find /repo -regextype egrep -regex '^.*\.db(\.tar|\.tar\.xz|\.tar.zst)$')
if [ -z "${REPODB}" ]; then if [ -z "${REPODB}" ]; then
echo "No database found in /repo, not adding package." echo "No database found in /repo, not adding package."
echo "The built package is available in ${PACKAGE}" echo "The built package is available in ${PACKAGE}"
exit 0 exit 0
fi fi
for pkg_file in "${PACKAGE[@]}"; do for pkg_file in "${PACKAGE[@]}"; do
gosu builder mv ${pkg_file}* /repo gosu builder mv ${pkg_file}* /repo
pushd /repo pushd /repo
gosu builder repo-add ${REPOADD_OPTS[@]} ${REPODB} "${pkg_file}" gosu builder repo-add ${REPOADD_OPTS[@]} ${REPODB} "${pkg_file}"
popd popd
done done