--- /dev/null
+#!/bin/sh
+[ "$(id | awk '{print $1}')" != 'uid=0(root)' ] && exec sudo "$0" "$@"
+
+dir="$(realpath "$(dirname "$0")/../alpine")"
+aports="$(realpath "$dir/../aports")"
+if [ $# -gt 0 ]; then
+ cmd="$@"
+else
+ cmd='/bin/ash -i'
+fi
+
+um=0
+uma() {
+ : $((++um))
+ eval "um$um='$1'"
+}
+m() {
+ src="$1"; shift
+ dst="$1"; shift
+ mkdir -p "$dst"
+ mount $@ "$src" "$dst"
+ uma "$dst"
+}
+mb() {
+ src="$1"; shift
+ if [ $# -gt 0 -a "x$(echo "$1" | cut -c 1)" = x/ ]; then
+ dst="$dir$1"; shift
+ else
+ dst="$dir$src"
+ fi
+ src="$(realpath $src)"
+ [ ! -e "$src" ] && return
+ m "$src" "$dst" --bind --slave $@
+}
+
+mb /dev -oro
+mb /dev/pts
+mb /dev/shm
+mb /dev/mqueue
+m none "$dir/proc" -t proc
+mb /sys
+ln -f /etc/resolv.conf "$dir/etc/resolv.conf"
+mb "$aports" /home/abuild/aports
+mb /srv/alpine/edge /home/abuild/packages
+mb /var/cache/distfiles
+mb /etc/apk/cache
+
+f="$(chroot "$dir" mktemp -p/tmp/)"
+
+chrdir="$PWD/"
+chrdir="${chrdir%/aports/*}"
+if [ "$chrdir" != "$PWD/" ]; then
+ cmd="cd \"/home/abuild${PWD#$chrdir}\" && $cmd"
+fi
+
+echo "$cmd" | tee "$dir/$f"
+chmod ugo+r "$dir/$f"
+chroot "$dir" /bin/su abuild -l "$f"
+
+rm -f "$dir/$f"
+
+for x in $(seq $um -1 1); do
+ eval "umount \$um$x"
+done
--- /dev/null
+#!/bin/sh
+set -e
+[ "$(id | awk '{print $1}')" != 'uid=0(root)' ] &&
+ exec sudo "$0" "$(id -u $(whoami))" "$@"
+[ "z$1" = z ] && return 1
+mirror=https://dl-cdn.alpinelinux.org/alpine/edge
+arch="${ABCHR_ARCH:-x86_64}"
+apk="apk-tools-static-$(apk info apk-tools-static |
+ awk '{if (NR==1) {print substr($1,18)}}').apk"
+dir="$(dirname "$0")/../alpine"
+tmp="$(dirname "$0")/../tmp"
+mkdir -p "$tmp"
+wget -P "$tmp" "$mirror/main/$arch/$apk"
+tar -xvzf "$tmp/$apk" -C "$tmp"
+"$tmp/sbin/apk.static" -UX "$mirror/main" -X "$mirror/community" \
+ --allow-untrusted -p "$dir" --initdb \
+ add busybox busybox-suid libc-utils sudo \
+ alpine-baselayout alpine-conf alpine-release apk-tools \
+ alpine-sdk alpine-repo-tools atools lua-aports
+rm -rf "$tmp"
+cp -Ln /etc/apk/keys/* "$dir/etc/apk/keys"
+cp -f /etc/apk/repositories "$dir/etc/apk/repositories"
+printf -- > "$dir/etc/sudoers.d/abuild" 'abuild ALL=(ALL) NOPASSWD: ALL'
+printf -- >> "$dir/etc/apk/repositories" \
+ '/home/abuild/packages/%s\n' main community testing
+chroot "$dir" /bin/sh -c "adduser -DGabuild -u$1 abuild"