#!/usr/bin/env bash cleanup() { umount "$cnt_dir/rootfs" } wrk_dir='/home/lxc' pkg_url=$1 pkg_dest=$2 cnt="_makepkg.$$" cnt_dir="$wrk_dir/containers/$cnt" trap 'cleanup' INT TERM EXIT lxf -r builder -i builder new "$cnt" # Add the build script cp "$wrk_dir/files/buildpackage" "$cnt_dir/rootfs/init" chmod 755 "$cnt_dir/rootfs/init" # Tell it where to fetch the package echo "$pkg_url" > "$cnt_dir/rootfs/repo" # Start the container lxc-start -n "$cnt" -F; lxc_exit=$? (( 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 }