#!/bin/sh

WORK_DIR="$(mktemp -d -p "/tmp")"

COW_DIR="$(mktemp -d -p "${WORK_DIR}")"
ROOT_DIR="${COW_DIR}"
while read lf; do
	[ -e "${lf}" ] || \
		continue
	if [ -d "${lf}" ]; then
		l="${d}"
	else
		l="${WORK_DIR}/$(basename "${lf}")"
		mkdir -p "${l}"
		mount -o loop "${lf}" "${l}"
	fi
	r="$(mktemp -d -p "${WORK_DIR}")"
	mount -t overlayfs -o lowerdir="${l}",upperdir="${ROOT_DIR}" "overlayfs" "${r}"
	ROOT_DIR="${r}"
done << EOF
/lnet/image/LneTPers64/90pcjordi.squashfs
/lnet/image/LneTPers64/12firmwarert.squashfs
/lnet/image/LneTPers64/00filesystem.squashfs
EOF

echo "rootdir: ${ROOT_DIR}"
echo "COW: ${COW_DIR}"

exit 0

for f in $(find "${ROOT_DIR}/etc" -type f); do
	touch "${f}"
done

umount "${ROOT_DIR}"

while read f; do
	[ -d "${f}" ] && \
	mountpoint "${f}" && \
	umount "${f}" || :
done << EOF
$(find "${WORK_DIR}" -mindepth 1 -maxdepth 1 -type d)
EOF

:
