#!/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