#!/bin/sh # Copyright (C) 2019 Richard Mortier # Licensed under the MIT License, https://opensource.org/licenses/MIT set -eu # source the configuration if available if [ -f "/etc/dabuild.conf" ]; then . /etc/dabuild.conf fi # set defaults : "${DABUILD_DEBUG:=false}" : "${DABUILD_ARCH:=$(uname -m)}" : "${DABUILD_DOCKER:=docker}" : "${DABUILD_VERSION=}" : "${DABUILD_PACKAGES:=${PWD%/aports/*}/packages}}" : "${DABUILD_APK_CACHE:=true}" : "${DABUILD_CCACHE:=false}" : "${DABUILD_DISTFILES:=false}" : "${DABUILD_RM:=true}" : "${DABUILD_ARGS=}" # reset vars DABUILD_ENV= die () { printf >&2 "%s\\n" "$@" exit 1 } ## debug if [ "$DABUILD_DEBUG" = "true" ]; then set -x PS4='$LINENO: ' DABUILD_ENV="$DABUILD_ENV -e DABUILD_DEBUG=true" fi ## check running from within an `aports` tree if [ "${PWD%*/aports/*}" = "$PWD" ]; then die "Error: expecting to be run from within an aports tree!" \ "Could not find '/aports/' in the current path: $PWD" fi case "$DABUILD_ARCH" in x86|x86_64|aarch64|armhf|armv7);; armv8l|arm) DABUILD_ARCH=armv7;; *) die "Unsupported arch \"$DABUILD_ARCH\" detected." \ "Expected one of: x86|x86_64|aarch64|armhf|armv7" \ "You may force it setting DABUILD_ARCH=\"xxx\" in invocation";; esac ## allow setting of `docker` command by env variable case "$DABUILD_DOCKER" in podman|docker) ;; *) die "Unsupported docker CLI replacement \"$DABUILD_DOCKER\" detected." \ "Expected one of: docker|podman";; esac _DOCKER=$DABUILD_DOCKER ## use branch to figure out most appropriate alpine version if [ ! "$DABUILD_VERSION" ]; then APORTS_BRANCH=$(git symbolic-ref --short -q HEAD) case $APORTS_BRANCH in *-stable) DABUILD_VERSION=${APORTS_BRANCH%-stable};; *) DABUILD_VERSION=edge;; esac fi # set packages dir based on alpine release DABUILD_PACKAGES="$DABUILD_PACKAGES/$DABUILD_VERSION" ## setup volumes; use named volumes as cache if desired ABUILD_VOLUMES="-v ${PWD%/aports/*}/aports:/home/builder/aports \ -v ${DABUILD_PACKAGES}:/home/builder/packages" # pass over gitconfig for abuild-keygen if [ -f "$HOME/.gitconfig" ]; then ABUILD_VOLUMES="$ABUILD_VOLUMES \ -v $HOME/.gitconfig:/home/builder/.gitconfig" fi setup_named_volume() { local name=$1 dest=$2 single="${3:-false}" local volume="dabuild-$name-$DABUILD_VERSION-$DABUILD_ARCH" [ "$single" = "true" ] && volume="dabuild-$name" ABUILD_VOLUMES="$ABUILD_VOLUMES -v $volume:$dest" } if [ "$DABUILD_APK_CACHE" = "true" ]; then setup_named_volume apkcache "/etc/apk/cache" fi if [ "$DABUILD_CCACHE" = "true" ]; then setup_named_volume ccache "/home/builder/.ccache" DABUILD_ENV="$DABUILD_ENV -e DABUILD_CCACHE=true" fi # use a bind or named volume for distfiles. case $DABUILD_DISTFILES in */*) ABUILD_VOLUMES="$ABUILD_VOLUMES \ -v $DABUILD_DISTFILES:/var/cache/distfiles";; true) setup_named_volume distfiles "/var/cache/distfiles" true;; *) ;; esac setup_named_volume config "/home/builder/.abuild" true if [ "$DABUILD_RM" != "false" ]; then DABUILD_ARGS="$DABUILD_ARGS --rm" fi ## go! $_DOCKER run --tty --interactive \ $ABUILD_VOLUMES \ $DABUILD_ENV \ $DABUILD_ARGS \ --workdir /home/builder/aports/"${PWD#*/aports/}" \ %%ABUILD_IMAGE%%:$DABUILD_VERSION-$DABUILD_ARCH "$@"