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