X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=scripts.git;a=blobdiff_plain;f=luks_toolbox.sh;h=aed8dc013eed9dca01c6de29d85992984fbe957b;hp=ac4e3a2afe9328a45814a3cf7234660e70673d77;hb=HEAD;hpb=7cbe045476f5fbc3827daa881ffaf706b2818eca diff --git a/luks_toolbox.sh b/luks_toolbox.sh index ac4e3a2..aed8dc0 100755 --- a/luks_toolbox.sh +++ b/luks_toolbox.sh @@ -27,35 +27,37 @@ $(basename $0) [--help | clean | sync | fsck [-f] &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 @@ -66,25 +68,23 @@ case $1 in clean) - # mount | grep ^'/dev/dm-[0-9]*' | sed -e 's/^.* on \([^ ]*\) .*$/\1/' | \ + mount | grep ^'/dev/mapper' | sed -e 's/^.* on \([^ ]*\) .*$/\1/' | while read line + do + echo "umount ${line}" + umount "${line}" + done - mount | grep ^'/dev/mapper' | sed -e 's/^.* on \([^ ]*\) .*$/\1/' | \ - while read line; do - echo "umount ${line}" - umount ${line} - done + find /dev/mapper -type l | while read line + do + echo "cryptsetup luksClose ${line}" + cryptsetup luksClose "${line}" + done - \ls /dev/mapper | grep -v ^control$ | \ - while read line; do - echo "cryptsetup luksClose ${line[0]}" - cryptsetup luksClose "${line[0]}" - done - - losetup -a | sed -e "s/:.*$//" | \ - while read line; do - echo "losetup -d ${line}" - losetup -d ${line} - done + losetup -a | sed -e "s/:.*$//" | while read line + do + echo "losetup -d ${line}" + losetup -d "${line}" + done exit 0 @@ -109,7 +109,8 @@ case $1 in read -n 1 KEY - if [[ ! "${KEY}" == "y" ]]; then + if [[ ! "${KEY}" == "y" ]] + then echo "Cancelled!" exit 1 fi @@ -144,7 +145,8 @@ case $1 in 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 @@ -170,19 +172,22 @@ case $1 in 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}" @@ -198,7 +203,8 @@ case $1 in cryptsetup luksClose crypt-dst - if [[ "${LOOP_DST}" ]]; then + if [[ "${LOOP_DST}" ]] + then losetup -d "${LOOP_DST}" && unset LOOP_DST fi @@ -210,7 +216,8 @@ case $1 in mount|umount) - if [[ "$1" == "umount" ]]; then + if [[ "$1" == "umount" ]] + then umount=yes fi @@ -219,11 +226,13 @@ case $1 in 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 <