#!/usr/bin/env bash MACHINE=${MACHINE:-talircd-build} MACHINE_PATH=/var/lib/machines/${MACHINE} PROJECT_ROOT=${PROJECT_ROOT:-$(git rev-parse --show-toplevel)} DIST_DIR=${DIST_DIR:-${PROJECT_ROOT}/_dist} CODENAME=bullseye MIRROR=${MIRROR:-http://debian.csail.mit.edu/debian/} function init() { # TODO: fakeroot ? set -x sudo debootstrap \ --include=ocaml-base,ocaml,opam,ca-certificates,git,rsync \ --components=main,contrib \ ${CODENAME} ${MACHINE_PATH} ${MIRROR} } function cleanall() { set -x sudo rm -rf ${MACHINE_PATH} } function in_container() { set -x mkdir -p ${DIST_DIR} sudo systemd-nspawn -q \ --machine ${MACHINE} \ --bind-ro ${PROJECT_ROOT}:/root/talircd \ --bind ${DIST_DIR}:/root/dist:rootidmap \ -E OPAMROOTISOK=1 \ "$@" } function clean() { rm -rf ${DIST_DIR}/root in_container rm -rf /root/.opam } function build() { in_container --chdir /root /root/talircd/deploy/_build.sh } function shell() { in_container } case ${1:-build} in init) init ;; build) build ;; clean) clean ;; cleanall) cleanall ;; shell) shell ;; *) echo "invalid command $1" esac