#!/bin/sh
# Unmount compartments (all, or those named). Plaintext disappears from view.
#
#   tools/lock [c1 c2 ...]
. "$(dirname "$0")/lib.sh"

if [ -n "$CONTINUITY_REMOTE" ]; then
    for c in $(compartments "$@"); do
        ssh "$CONTINUITY_REMOTE" "m=\"$CONTINUITY_REMOTE_DATA/mnt/$c\"; mountpoint -q \"\$m\" || exit 0; fusermount3 -u \"\$m\" 2>/dev/null || fusermount -u \"\$m\"" \
            || die "could not lock $c on $CONTINUITY_REMOTE"
        say "$c locked (remote)"
    done
    exit 0
fi

status=0
for c in $(compartments "$@"); do
    is_mounted "$MNT/$c" || continue
    if unmount "$MNT/$c"; then say "$c locked"; else say "$c is busy: close files and editors using it, then retry"; status=1; fi
done
exit $status
