#!/bin/sh
set -ev

cd $(realpath $(dirname "${0}"))

# Install basic build tools
apk update
apk add git file htop less openssh-client tree
# Install Alpine SDK (for APK builds)
apk add alpine-sdk
# Install Sphinx support (for documentation builds)
apk add py3-sphinx py3-sphinx_rtd_theme

# Copy root profile files and settings
mkdir -p /root/.config/htop
cp root/.profile /root/.profile
cp root/.config/htop/htoprc /root/.config/htop/htoprc

# Prepare abuild toolchain
adduser root abuild
cp etc/abuild.conf /etc/abuild.conf

# Prepare local APK repository
cp etc/nginx/conf.d/repo.conf /etc/nginx/conf.d/repo.conf
echo "172.17.0.1 repo.build.vm" >>/etc/hosts
service nginx reload

# Change SPOC repository
sed -i 's/https:\/\/repo\.spotter\.cz/http:\/\/repo.build.vm/' /etc/spoc/spoc.conf

# Supply abuild key
# echo '/root/repo.spotter.cz.rsa' | abuild-keygen

# Supply SPOC key
# openssl ecparam -genkey -name secp384r1 -out /etc/spoc/publish.key
# openssl ec -in /etc/spoc/publish.key -pubout -out /tmp/repository.pub
