#!/bin/sh
set -e
. "$SETUP_DATA_DIR/common-data"
. "$SETUP_DATA_DIR/common-functions"
. "$SETUP_DATA_DIR/common-config"
if [ -n "${CHROOT_UNION_TYPE}" ] && [ "${CHROOT_UNION_TYPE}" != 'none' ]; then
if [ "$JENKINS_WORKSPACE" = "" ]; then
fatal "No JENKINS_WORKSPACE defined!"
fi
if [ "$STAGE" = "setup-start" ]; then
echo "Mounting $JENKINS_WORKSPACE inside the chroot"
mkdir -p "$CHROOT_MOUNT_LOCATION/tmp/jenkins"
mkdir -p "$CHROOT_MOUNT_LOCATION/$JENKINS_WORKSPACE"
mount -t overlayfs -o lowerdir="$JENKINS_WORKSPACE",upperdir="$CHROOT_MOUNT_LOCATION/tmp/jenkins" overlayfs "$CHROOT_MOUNT_LOCATION/$JENKINS_WORKSPACE"
echo "Overlay ready"
elif [ "$STAGE" = "setup-stop" ]; then
umount "$CHROOT_MOUNT_LOCATION/$JENKINS_WORKSPACE"
rm -rf "$CHROOT_MOUNT_LOCATION/tmp/jenkins"
echo "Teardown of $JENKINS_WORKSPACE overlayfs complete"
fi
fi