#!/bin/bash
set -e

source $(dirname $0)/version
cd $(dirname $0)/..

ARTIFACTS=$(pwd)/dist/artifacts
BUILD=build
INITRD_DIR=${BUILD}/initrd
export ARTIFACTS BUILD INITRD_DIR VERSION

./scripts/layout-initrd
./scripts/layout-kernel

DFS_ARCH=$(docker create ${DFS_IMAGE}${SUFFIX})
trap "docker rm -fv ${DFS_ARCH} >/dev/null" EXIT
docker export ${DFS_ARCH} | tar xf - -C ${INITRD_DIR} --exclude=usr/bin/docker*      \
                                                      --exclude=usr/share/git-core   \
                                                      --exclude=usr/bin/git          \
                                                      --exclude=usr/bin/ssh          \
                                                      --exclude=usr/libexec/git-core \
                                                      usr

./scripts/hash-initrd
