-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluks-list
executable file
·33 lines (29 loc) · 1.03 KB
/
luks-list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
tty -s && RED=$(tput setaf 1 2>/dev/null || echo $'\e[0;31m') || RED=
tty -s && GREEN=$(tput setaf 2 2>/dev/null || echo $'\e[0;32m') || GREEN=
tty -s && YELLOW=$(tput setaf 3 2>/dev/null || echo $'\e[0;33m') || YELLOW=
tty -s && RESET=$(tput sgr0 2>/dev/null || echo $'\e[0m') || RESET= # reset fg/bg color
if [ -n "$(shopt -s nullglob; echo /dev/mapper/*_crypt)" ]; then
MAP_COUNT=$(dmsetup ls --target crypt | wc -l) # returns not 0 when no devices are mapped, because "No devices found" is returned
else
MAP_COUNT=0
fi
echo "${GREEN}Mapped devices ($MAP_COUNT):$YELLOW"
if [ "$MAP_COUNT" -gt 0 ]; then
echo
dmsetup ls --target crypt | column -t
fi
echo "$RESET"
MOUNT_COUNT=$(mount | grep -c ^/dev/mapper/)
echo "${GREEN}Mount points ($MOUNT_COUNT):$YELLOW"
MOUNTS=$(mount | grep ^/dev/mapper/ | awk '{print $1" --> "$3}' | column -t)
if [ -n "$MOUNTS" ]; then
echo
echo "$MOUNTS"
fi
echo "$RESET"
if (( MAP_COUNT > MOUNT_COUNT)); then
echo "${RED}Info: Not all devices are mounted.$RESET"
echo
exit 1
fi >&2