######################################################################
-if [[ "$@" == "" ]]; then
+if [[ "$@" == "" ]]
+then
print_help >&2
exit 1
fi
-if [[ ! $(id -u) == 0 ]]; then
+if [[ ! $(id -u) == 0 ]]
+then
echo "This command should be run as root (no offense, but you are $(id -un))." >&2
exit 1
fi
# mount | grep ^'/dev/dm-[0-9]*' | sed -e 's/^.* on \([^ ]*\) .*$/\1/' | \
mount | grep ^'/dev/mapper' | sed -e 's/^.* on \([^ ]*\) .*$/\1/' | \
- while read line; do
+ while read line
+ do
echo "umount ${line}"
umount ${line}
done
\ls /dev/mapper | grep -v ^control$ | \
- while read line; do
+ while read line
+ do
echo "cryptsetup luksClose ${line[0]}"
cryptsetup luksClose "${line[0]}"
done
losetup -a | sed -e "s/:.*$//" | \
- while read line; do
+ while read line
+ do
echo "losetup -d ${line}"
losetup -d ${line}
done
read -n 1 KEY
- if [[ ! "${KEY}" == "y" ]]; then
+ if [[ ! "${KEY}" == "y" ]]
+ then
echo "Cancelled!"
exit 1
fi
read -n 1 KEY
- if [[ "${KEY}" == "y" ]]; then
+ if [[ "${KEY}" == "y" ]]
+ then
echo
rsync --itemize-changes --delete --progress -axz "${DIR_MOUNT_SRC}/" "${DIR_MOUNT_DST}/"
else
shift
- if [[ "$1" == "-f" ]]; then
+ if [[ "$1" == "-f" ]]
+ then
force="-f"
shift
fi
- if [[ ! -a "$1" ]]; then
+ if [[ ! -a "$1" ]]
+ then
echo "Cannot find file \`$1'." >&2
exit 1
fi
[[ -e "/dev/mapper/crypt-dst" ]] && (echo "/dev/mapper/crypt-dst already exists." >&2 && exit 1)
- if [[ -f "$1" ]]; then
+ if [[ -f "$1" ]]
+ then
LOOP_DST="$(losetup -f)"
losetup "${LOOP_DST}" "$1"
DEVICE="${LOOP_DST}"
cryptsetup luksClose crypt-dst
- if [[ "${LOOP_DST}" ]]; then
+ if [[ "${LOOP_DST}" ]]
+ then
losetup -d "${LOOP_DST}" && unset LOOP_DST
fi
mount|umount)
- if [[ "$1" == "umount" ]]; then
+ if [[ "$1" == "umount" ]]
+ then
umount=yes
fi
mount_point=$(echo $1 | sed -e "s;/*$;;")
device=$(grep ^/ /etc/fstab | awk '{ print $2" "$1 }' | grep ^${mount_point} | cut -f 2 -d " ")
- if [[ ${device} =~ ^/dev/mapper ]]; then
+ if [[ ${device} =~ ^/dev/mapper ]]
+ then
mapped_device=${device/'/dev/mapper/'/}
- if [[ ${umount} ]]; then
+ if [[ ${umount} ]]
+ then
cat <<EOF
Attempting to unmount
${mount_point}.