Files
builder/makepkg-overlay
T

68 lines
1.3 KiB
Bash
Raw Normal View History

2017-11-17 20:17:03 +03:00
#!/usr/bin/env bash
2017-11-21 17:52:50 +03:00
# Depends on lxf
cleanup() { lxf umount "$cnt"; }
2017-11-17 20:17:03 +03: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 20:17:03 +03:00
}
2017-11-21 17:52:50 +03:00
# Config
2017-11-17 20:17:03 +03:00
wrk_dir='/home/lxc'
2017-11-21 17:52:50 +03:00
# Parameters
2017-11-17 20:17:03 +03:00
pkg_url=$1
pkg_dest=$2
cnt="_makepkg.$$"
cnt_dir="$wrk_dir/containers/$cnt"
# Create new container
2017-11-22 15:48:15 +03:00
lxf -r builder -i base new "$cnt" || exit $?
2017-11-17 20:17:03 +03:00
2017-11-21 17:52:50 +03:00
# Unmount the thing in any case
trap 'cleanup' INT TERM EXIT
2017-11-17 20:17:03 +03:00
# Add the build script
buildscript > "$cnt_dir/rootfs/init"
2017-11-17 20:17:03 +03:00
chmod 755 "$cnt_dir/rootfs/init"
# Start the container
2017-11-22 15:48:15 +03:00
lxc-start -n "$cnt" -F /init || exit $?
2017-11-17 20:17:03 +03:00
# 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
}