63 lines
1.1 KiB
Bash
Executable File
63 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Config
|
|
chroot_base='/var/chroot/root'
|
|
|
|
# Functions
|
|
icat() {
|
|
while read; do
|
|
echo -e "$REPLY"
|
|
done
|
|
}
|
|
|
|
build_script() {
|
|
icat <<- EOF
|
|
#!/bin/sh
|
|
|
|
pacman -Sy &>pacman.log
|
|
|
|
cd '/build'; chown builder:wheel /build
|
|
sudo -u builder PKGDEST='/pkg' makepkg -s --noconfirm -L &>makepkg.log
|
|
|
|
makepkg_exit="\$?"
|
|
|
|
case "\$makepkg_exit" in
|
|
0) echo 'ok';;
|
|
2) echo 'already built';;
|
|
*) echo 'FAIL';;
|
|
esac
|
|
|
|
exit "\$makepkg_exit"
|
|
EOF
|
|
}
|
|
|
|
main() {
|
|
chroot_dir="$1"
|
|
pkg_dest_dir="$2"
|
|
workdir="$PWD"
|
|
|
|
[[ "${chroot_dir}" ]] || { usage; exit 1; }
|
|
|
|
/usr/local/bin/mount-chroot.sh -s "$chroot_base" -n 'chroot_build' "$chroot_dir"
|
|
|
|
mkdir -m777 "$chroot_dir/pkg" "$chroot_dir/build"
|
|
|
|
mount --bind "$workdir" "$chroot_dir/build"
|
|
mount --bind "$pkg_dest_dir" "$chroot_dir/pkg"
|
|
|
|
build_script > "${chroot_dir}/build/build.sh"
|
|
|
|
#chmod 755 "${chroot_dir}/build/build.sh"
|
|
chroot "${chroot_dir}" sh /build/build.sh
|
|
|
|
if /usr/local/bin/mount-chroot.sh -u "$chroot_dir"; then
|
|
rm -r "${chroot_dir}"{,.work}
|
|
else
|
|
err "Cannot unmount $chroot_dir"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
main "$@"
|
|
|