This commit is contained in:
Fleshless Builder 2017-11-21 17:52:50 +03:00
parent 0e280608cc
commit 7f34912c09

View File

@ -1,4 +1,7 @@
#!/usr/bin/env bash
# Depends on lxf
cleanup() { lxf umount "$cnt"; }
buildscript() {
cat <<- EOF
@ -24,29 +27,25 @@ buildscript() {
EOF
}
# Config
wrk_dir='/home/lxc'
# Parameters
pkg_url=$1
pkg_dest=$2
cnt="_makepkg.$$"
cnt_dir="$wrk_dir/containers/$cnt"
# Unmount the thing in any case
cleanup() { lxf umount "$cnt"; }
trap 'cleanup' INT TERM EXIT
# Create new container
lxf -r builder -i base new "$cnt"
# Unmount the thing in any case
trap 'cleanup' INT TERM EXIT
# Add the build script
buildscript > "$cnt_dir/rootfs/init"
chmod 755 "$cnt_dir/rootfs/init"
# Tell it where to fetch the package
echo "$pkg_url" > "$cnt_dir/rootfs/repo"
export PKG_GIT_URL="$pkg_url"
# Start the container
lxc-start -n "$cnt" -F /init; lxc_exit=$?
(( lxc_exit )) && exit "$lxc_exit"