#!/usr/bin/env sh

CI_DATA=$1
suffix=$2
mount_point=$3

for i in upper wd
do
    if [ -d ${CI_DATA}/overlayfs/$i-${suffix} ]
    then
        rm -rf ${CI_DATA}/overlayfs/$i-${suffix}
    fi
    mkdir -p ${CI_DATA}/overlayfs/$i-${suffix}
done

/usr/libexec/apptainer/bin/fuse-overlayfs \
    -o squash_to_uid=$(id -u) \
    -o squash_to_gid=$(id -g) \
    -o lowerdir=${CI_DATA}/overlayfs/lower-${suffix} \
    -o upperdir=${CI_DATA}/overlayfs/upper-${suffix} \
    -o workdir=${CI_DATA}/overlayfs/wd-${suffix} \
    $mount_point
