2017-11-17 17:17:03 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-11-21 14:41:40 +00:00
|
|
|
buildscript() {
|
|
|
|
cat <<- EOF
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
# The builder user is already created in the rootfs
|
|
|
|
|
|
|
|
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
|
|
|
export LC_ALL=en_US.UTF-8
|
|
|
|
|
|
|
|
# Network
|
|
|
|
dhcpcd eth0
|
|
|
|
|
|
|
|
# Upgrade
|
|
|
|
pacman -Suy --noconfirm
|
|
|
|
|
|
|
|
# Build dir
|
|
|
|
mkdir -m777 /buildroot
|
|
|
|
|
|
|
|
# Build the damn thing
|
|
|
|
cd /buildroot
|
|
|
|
sudo -u builder git clone "$pkg_url" .
|
|
|
|
sudo -u builder makepkg -s --noconfirm -L
|
|
|
|
EOF
|
2017-11-17 17:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wrk_dir='/home/lxc'
|
|
|
|
pkg_url=$1
|
|
|
|
pkg_dest=$2
|
|
|
|
|
|
|
|
cnt="_makepkg.$$"
|
|
|
|
cnt_dir="$wrk_dir/containers/$cnt"
|
|
|
|
|
2017-11-21 14:41:40 +00:00
|
|
|
# Unmount the thing in any case
|
|
|
|
cleanup() { lxf umount "$cnt"; }
|
2017-11-17 17:17:03 +00:00
|
|
|
trap 'cleanup' INT TERM EXIT
|
|
|
|
|
2017-11-21 14:41:40 +00:00
|
|
|
# Create new container
|
|
|
|
lxf -r builder -i base new "$cnt"
|
2017-11-17 17:17:03 +00:00
|
|
|
|
|
|
|
# Add the build script
|
2017-11-21 14:41:40 +00:00
|
|
|
buildscript > "$cnt_dir/rootfs/init"
|
2017-11-17 17:17:03 +00:00
|
|
|
chmod 755 "$cnt_dir/rootfs/init"
|
|
|
|
|
|
|
|
# Tell it where to fetch the package
|
|
|
|
echo "$pkg_url" > "$cnt_dir/rootfs/repo"
|
|
|
|
|
2017-11-17 21:15:16 +00:00
|
|
|
export PKG_GIT_URL="$pkg_url"
|
|
|
|
|
2017-11-17 17:17:03 +00:00
|
|
|
# Start the container
|
2017-11-21 14:41:40 +00:00
|
|
|
lxc-start -n "$cnt" -F /init; lxc_exit=$?
|
2017-11-17 17:17:03 +00:00
|
|
|
(( lxc_exit )) && exit "$lxc_exit"
|
|
|
|
|
|
|
|
# Put the artifacts where asked to
|
|
|
|
[[ "$pkg_dest" ]] && {
|
|
|
|
artifacts=( "$cnt_dir/rootfs/buildroot/"*.pkg.* )
|
|
|
|
|
|
|
|
for i in "${artifacts[@]}"; do
|
|
|
|
i_name="${i##*/}"
|
|
|
|
|
|
|
|
printf 'Found artifact: %s\n' "$i_name"
|
|
|
|
|
|
|
|
if [[ -f "$pkg_dest/$i_name" ]]; then
|
|
|
|
echo "$pkg_dest/$i_name already exists, not overwriting."
|
|
|
|
else
|
|
|
|
cp -vn "$i" "$pkg_dest"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|