t11 and new partitioner fixes
[automated-distro-installer] / fsf / close-crypt-luks-keys-loopback
1 #!/bin/bash
2
3 # usage: $0
4 # this script is idempotent
5
6 # warning: changes here may affect the open version of this script
7
8 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
9 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
10 set -eE -o pipefail
11 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
12
13 m() { printf "%s\n" "$*"; "$@"; }
14
15
16 fs_file=/root/crypt-luks-keys-loopback
17 mapper_name=crypt-luks-keys-loopback
18
19 if mountpoint /mnt2 &>/dev/null; then
20 m umount /mnt2
21 fi
22 if cryptsetup status /dev/mapper/$mapper_name &>/dev/null; then
23 m cryptsetup luksClose /dev/mapper/$mapper_name; then
24 fi
25 l=$(losetup -l --noheadings | awk '$6 ~ /\/'$mapper_name'$/ {print $1}')
26 if [[ $l ]]; then
27 m losetup -d $l
28 else
29 echo "$0: warning: no loopback device found" >&2
30 fi