#!/bin/sh -e
#
#    ecryptfs-dot-private
#    Copyright (C) 2009 Canonical Ltd.
#
#    Authors: Dustin Kirkland <kirkland@canonical.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 2 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License

if echo "$0" | grep -qs "ecryptfs"; then
    echo "ERROR: This file must be sourced, rather than executed:"
    echo
    echo "  . $0"
    echo
    exit 1
fi

# Hacky, umount.ecryptfs_private should be taught to exit 1 on
# unsuccessful unmount, must check who else depends on this exit code.
if /sbin/umount.ecryptfs_private | grep -v "Sessions still open"; then
    cd "$HOME"/.Private
else
    echo "ERROR: Unable to access .Private, please close some sessions"
fi
/sbin/mount.ecryptfs_private