#!/bin/sh
[ -n "$1" ] || sh -c 'echo -e "\033[01;31mPlease specify the package name."; exit 1'
rm -rf "/pkgbuild/repositories/$1"
git clone "https://aur.archlinux.org/$1.git" "/pkgbuild/repositories/$1" || sh -c 'echo -e "\033[01;31mThe build encountered an error while fetching the PKGBUILD."; exit 1'
cd "/pkgbuild/repositories/$1"
makechrootpkg -c -r "/pkgbuild/build" || sh -c 'echo -e "\033[01;31mThe build encountered an error while making the package."; exit 1'
sh -c "cp /pkgbuild/repositories/$1/*.pkg.tar.xz /pkgbuild/jenkins/workspace/AUR/$1"
exit 0
