#!/usr/bin/env bash -e # Build tools on Mac OS X host and in all vms MAKE_TASK='all -j' filters=() for arg in "$@"; do if [[ "$arg" =~ ^([A-Z_]+)=(.*)$ ]]; then eval "$(printf %q=%q "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}")" else filters+=($arg) fi done filters=$(IFS='|'; echo "${filters[*]}") passes-filter() { [[ '' = "$filters" ]] || [[ "$1" =~ $filters ]] } header() { printf '\033[1;7m######## %s ########\033[0m\n' "$1" } if [[ $(uname -s) != 'Darwin' ]]; then echo 'expected to run on Mac OS X' exit 1 fi make download-dependencies for arch in x86_64; do platform="darwin-$arch" passes-filter "$platform" || continue header "$platform" build_dir=~_image_optim/pack mkdir -p "vendor/$platform" rsync -aR --del Makefile checksums.mk download patches "$build_dir" sudo -u _image_optim --set-home bash -exc " mkdir -p '$build_dir' cd '$build_dir' make $MAKE_TASK ARCH=$arch " rsync -aR --del "$build_dir/./vendor/$platform" . done if command -v docker &> /dev/null; then container_tool="docker" elif command -v podman &> /dev/null; then container_tool="podman" else echo "neither docker nor podman found" exit 1 fi container_build() { vm=$1 image=$2 passes-filter "$vm" || return 0 header "$vm" container_name="image_optim_pack-build-$vm" workdir=/pack if [[ -z "$NO_UP" ]]; then status=$("$container_tool" inspect --format '{{.State.Status}}' "$container_name" 2>/dev/null || true) if [[ "$status" == "" ]]; then mount="./_path_:$workdir/_path_" "$container_tool" \ container create \ --name="$container_name" \ --stop-signal SIGHUP \ -it \ -v "${mount//_path_/}:ro" \ -v "${mount//_path_/build/$vm}" \ -v "${mount//_path_/vendor/$vm}" \ --workdir "$workdir" \ "$image" "$container_tool" container start "$container_name" "$container_tool" exec -it "$container_name" bash -exc " apt-get update apt-get -y install make gcc g++ chrpath perl pkg-config autoconf automake libtool nasm cmake patch " fi if [[ "$status" = @(created|exited) ]]; then "$container_tool" container start "$container_name" fi if [[ "$status" = @(created|exited|running) ]]; then "$container_tool" exec -it "$container_name" bash -exc " apt-get update apt-get -y dist-upgrade rustup update " fi if ! [[ "$status" = @(|created|exited|running) ]]; then echo "unexpected status $status" exit 1 fi fi "$container_tool" exec -it "$container_name" bash -exc " make $MAKE_TASK " [[ -n "$NO_HALT" ]] || "$container_tool" container stop "$container_name" } container_build linux-x86_64 rust:slim-buster