mirror of
https://github.com/hackacad/bastille.git
synced 2026-01-04 03:33:41 +01:00
bugfixes and code cleanup
This commit is contained in:
@@ -32,43 +32,55 @@
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
usage() {
|
||||
error_exit "Usage: bastille umount TARGET container_path"
|
||||
error_exit "Usage: bastille umount TARGET JAIL_PATH"
|
||||
}
|
||||
|
||||
# Handle special-case commands first.
|
||||
case "$1" in
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
case "${1}" in
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
if [ "$#" -ne 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
TARGET="${1}"
|
||||
MOUNT_PATH="${2}"
|
||||
|
||||
MOUNT_PATH=$1
|
||||
bastille_root_check
|
||||
set_target "${TARGET}"
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
|
||||
info "[${_jail}]:"
|
||||
set -x
|
||||
_jailpath="$( echo ${bastille_jailsdir}/${_jail}/root/${MOUNT_PATH} 2>/dev/null | sed 's#//#/#' )"
|
||||
_mount="$( mount | grep -ow ${_jailpath} )"
|
||||
_fstab_entry="$( cat ${bastille_jailsdir}/${_jail}/fstab | grep -ow ${_jailpath} )"
|
||||
|
||||
_jailpath="${bastille_jailsdir}/${_jail}/root/${MOUNT_PATH}"
|
||||
|
||||
if [ ! -d "${_jailpath}" ]; then
|
||||
error_exit "The specified mount point does not exist inside the jail."
|
||||
# Exit if mount point non-existent
|
||||
if [ -z "${_mount}" ] && [ -z "${_fstab_entry}" ]; then
|
||||
error_continue "The specified mount point does not exist."
|
||||
fi
|
||||
|
||||
# Unmount the volume. -- cwells
|
||||
if ! umount "${_jailpath}"; then
|
||||
error_exit "Failed to unmount volume: ${MOUNT_PATH}"
|
||||
# Unmount
|
||||
if [ -n "${_mount}" ]; then
|
||||
umount "${_jailpath}" || error_continue "Failed to unmount volume: ${MOUNT_PATH}"
|
||||
fi
|
||||
|
||||
# Remove the entry from fstab so it is not automounted in the future. -- cwells
|
||||
if ! sed -E -i '' "\, +${_jailpath} +,d" "${bastille_jailsdir}/${_jail}/fstab"; then
|
||||
error_exit "Failed to delete fstab entry: ${_fstab_entry}"
|
||||
# Remove entry from fstab
|
||||
if [ -n "${_fstab_entry}" ]; then
|
||||
if ! sed -E -i '' "\, +${_jailpath} +,d" "${bastille_jailsdir}/${_jail}/fstab"; then
|
||||
error_continue "Failed to delete fstab entry: ${MOUNT_PATH}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Delete if mount point was a file
|
||||
if [ -f "${_jailpath}" ]; then
|
||||
rm -f "${_jailpath}" || error_continue "Failed to unmount volume: ${MOUNT_PATH}"
|
||||
fi
|
||||
|
||||
echo "Unmounted: ${MOUNT_PATH}"
|
||||
echo
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user