forked from Spark/builder
new builder stuff
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
6f7f61122c
commit
d3fcb9b4ee
70
lxf
70
lxf
|
@ -1,70 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
mkconf() {
|
|
||||||
for i in "${includes[@]}"; do
|
|
||||||
echo "lxc.include = $lxf_conf_dir/$i.conf"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "lxc.rootfs.path = $lxf_cont_dir/$cont_name/rootfs"
|
|
||||||
echo "lxc.uts.name = $cont_name"
|
|
||||||
}
|
|
||||||
|
|
||||||
mount_cont() {
|
|
||||||
ov-mount -n "$cont_name" "$rootfs" "$cont_dir/rootfs"
|
|
||||||
}
|
|
||||||
|
|
||||||
lxf_conf_dir='/etc/lxf/conf'
|
|
||||||
lxf_cont_dir='/var/lib/lxf/cont'
|
|
||||||
lxf_rootfs_dir='/var/lib/lxf/fs'
|
|
||||||
|
|
||||||
[[ -f '/etc/lxf.conf' ]] && source '/etc/lxf.conf'
|
|
||||||
|
|
||||||
while (( $# )); do
|
|
||||||
case $1 in
|
|
||||||
(-i) includes+=( "$2" ); shift;;
|
|
||||||
(-r) rootfs="$2"; shift;;
|
|
||||||
|
|
||||||
(--cont-dir) lxf_cont_dir=$2; shift;;
|
|
||||||
(--conf-dir) lxf_conf_dir=$2; shift;;
|
|
||||||
|
|
||||||
(--) shift; break;;
|
|
||||||
(-*) echo "Unknown key: $1" >&2: exit 1;;
|
|
||||||
(*) break;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
action=$1; shift; [[ $action ]] || exit 1
|
|
||||||
cont_name=$1; shift; [[ $cont_name ]] || exit 1
|
|
||||||
|
|
||||||
cont_dir="$lxf_cont_dir/$cont_name"
|
|
||||||
|
|
||||||
case $action in
|
|
||||||
(create|new)
|
|
||||||
[[ "$rootfs" ]] || exit 1
|
|
||||||
rootfs="$lxf_rootfs_dir/$rootfs"
|
|
||||||
|
|
||||||
[[ -d "$cont_dir" ]] && {
|
|
||||||
printf 'Container already exists: %s\n' "$cont_dir" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
mkdir -p "$cont_dir" || exit $?
|
|
||||||
|
|
||||||
mkconf > "$cont_dir/config"
|
|
||||||
mount_cont
|
|
||||||
;;
|
|
||||||
|
|
||||||
(mount)
|
|
||||||
mountpoint -q "$cont_dir/rootfs" && {
|
|
||||||
printf 'Container already mounted: %s\n' "$cont_dir/rootfs" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
mount_cont
|
|
||||||
;;
|
|
||||||
|
|
||||||
(umount) umount "$cont_dir/rootfs";;
|
|
||||||
esac
|
|
|
@ -1,69 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
# Depends on lxf
|
|
||||||
shopt -s nullglob
|
|
||||||
|
|
||||||
cleanup() { lxf umount "$cnt"; }
|
|
||||||
|
|
||||||
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
|
|
||||||
chown builder:builder /buildroot
|
|
||||||
|
|
||||||
# Build the damn thing
|
|
||||||
cd /buildroot
|
|
||||||
sudo -u builder git clone "$pkg_url" .
|
|
||||||
sudo -u builder makepkg -s --noconfirm -L
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# Config
|
|
||||||
wrk_dir='/home/lxc'
|
|
||||||
|
|
||||||
# Parameters
|
|
||||||
pkg_url=$1
|
|
||||||
pkg_dest=$2
|
|
||||||
cnt="_makepkg.$$"
|
|
||||||
cnt_dir="$wrk_dir/containers/$cnt"
|
|
||||||
|
|
||||||
# Create new container
|
|
||||||
lxf -r builder -i base new "$cnt" || exit $?
|
|
||||||
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
# Start the container
|
|
||||||
lxc-start -n "$cnt" -F /init || 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
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
err() { printf '%s\n' "$*" >&2; }
|
err() { printf '%s\n' "$*" >&2; }
|
||||||
|
|
||||||
build_remote() { sudo makepkg-overlay "$@"; }
|
build_remote() { sudo makepkg-docker "$@"; }
|
||||||
cleanup() { rm -f "$lockfile"; }
|
cleanup() { rm -f "$lockfile"; }
|
||||||
|
|
||||||
lock() {
|
lock() {
|
||||||
|
@ -44,11 +44,11 @@ while (($#>1)); do
|
||||||
mkdir -p "$wrkdir/${repo_path%$repo_name}"
|
mkdir -p "$wrkdir/${repo_path%$repo_name}"
|
||||||
git clone "$pkg_repo" "$repo_local"
|
git clone "$pkg_repo" "$repo_local"
|
||||||
|
|
||||||
build_remote "$pkg_repo" "$pkg_dest"
|
build_remote "$pkg_dest" "$pkg_repo"
|
||||||
else
|
else
|
||||||
git -C "$repo_local" remote update
|
git -C "$repo_local" remote update
|
||||||
if git -C "$repo_local" status --porcelain -bu | grep -q behind; then
|
if git -C "$repo_local" status --porcelain -bu | grep -q behind; then
|
||||||
build_remote "$pkg_repo" "$pkg_dest"
|
build_remote "$pkg_dest" "$pkg_repo"
|
||||||
git -C "$repo_local" pull
|
git -C "$repo_local" pull
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -27,7 +27,7 @@ is_latest() {
|
||||||
_pacsort() {
|
_pacsort() {
|
||||||
declare i
|
declare i
|
||||||
|
|
||||||
for i in *.pkg.tar.xz; do
|
for i in *.pkg.tar.xz *.pkg.tar.zst; do
|
||||||
printf '%s\n' "$i"
|
printf '%s\n' "$i"
|
||||||
done | pacsort -f
|
done | pacsort -f
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ for f in import/*; do
|
||||||
f_name="${f##*/}"
|
f_name="${f##*/}"
|
||||||
if [[ -f "$f_name" ]]; then
|
if [[ -f "$f_name" ]]; then
|
||||||
printf 'Package already exists: %s, not overwriting\n' "$f_name" >&2
|
printf 'Package already exists: %s, not overwriting\n' "$f_name" >&2
|
||||||
|
rm -vf "$f"
|
||||||
else
|
else
|
||||||
mv -vf "$f" ./
|
mv -vf "$f" ./
|
||||||
new_pkgs+=( "$f_name" )
|
new_pkgs+=( "$f_name" )
|
||||||
|
|
Loading…
Reference in New Issue
Block a user