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

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

APK_TOOLS_URI='https://github.com/alpinelinux/apk-tools/releases/download/v2.6.9/apk-tools-2.6.9-x86_64-linux.tar.gz'
APK_TOOLS_SHA256='694ec2063a0fc9455141da73ea85e4dbd8cd95823c33573936912429f0a45e5f'


title 'Downloading static apk-tools'

cd /tmp
wget -T 10 "$APK_TOOLS_URI"
echo "$APK_TOOLS_SHA256  ${APK_TOOLS_URI##*/}" | sha256sum -c
tar -xzf ${APK_TOOLS_URI##*/}
mv apk-tools-*/apk apk


title 'Installing Alpine Linux'

mkdir -p "$ALPINE_ROOT"/etc/apk
cd "$ALPINE_ROOT"

echo "$MIRROR_URI/main" > etc/apk/repositories
cp -R "$CLONE_DIR"/.travis/keys etc/apk/keys
cp /etc/resolv.conf etc/resolv.conf

/tmp/apk \
	--root . --update-cache --initdb --no-progress \
	add alpine-base

mount -t proc none proc
mount --rbind /sys sys
mount --rbind /dev dev
mount --rbind /run run

ln -sf /run/shm dev/shm
