#!/bin/sh
# vim: set ts=4:
set -eu

. "$(dirname "$0")"/common.sh

title 'Setting up Alpine Linux'

mkdir -p "${ALPINE_ROOT}${CLONE_DIR}"
mount --bind "$CLONE_DIR" "${ALPINE_ROOT}${CLONE_DIR}"

alpine_run <<-EOF
	apk add alpine-sdk lua-aports

	adduser -u $SUDO_UID -G users -s /bin/sh -D $SUDO_USER
	addgroup $SUDO_USER abuild
	addgroup $SUDO_USER wheel

	echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel

	sed -i 's/JOBS=[0-9]*/JOBS=$(nproc)/' /etc/abuild.conf

	mkdir -p /var/cache/distfiles
	chmod a+w /var/cache/distfiles

	# Hack to disable apk's progress bar.
	install -m755 -D .travis/abuild-apk /usr/local/bin/abuild-apk
EOF

# This key will not be used anywhere, just to make abuild happy...
alpine_run $SUDO_USER <<-EOF
	abuild-keygen -ain
EOF
