3 #==============================================================================
5 # File ID: 0548a2d2-ea04-11ed-b5e0-83850402c3ce
7 # Mount a LUKS-encrypted disk under /media/
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
20 while test -n "$1"; do
22 -h|
--help) opt_help
=1; shift ;;
23 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
24 -u|
--umount) opt_umount
=1; shift ;;
25 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
26 --version) echo $progname $VERSION; exit 0 ;;
29 if printf '%s\n' "$1" |
grep -q ^
-; then
30 echo "$progname: $1: Unknown option" >&2
38 opt_verbose
=$
(($opt_verbose - $opt_quiet))
40 if test "$opt_help" = "1"; then
41 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
44 Mount a LUKS-encrypted disk under /media/.
46 Usage: $progname [options]
53 Be more quiet. Can be repeated to increase silence.
55 Increase level of verbosity. Can be repeated.
59 Print version information.
66 test $1 -gt $opt_verbose && return;
68 echo "$progname: $*" >&2
72 echo "$progname: $*" >&2
77 df |
grep -q "/media/$disk\$" && return 0
82 [ -z "$disk" ] && err No disk specified
84 blkid |
grep -q "LABEL=\"$disk\"" || err
$disk: Disk not found
in blkid
86 if [ "$opt_umount" != "1" ]; then
87 is_mounted
$disk && err
$disk: Already mounted
88 device
=$
(blkid
-L $disk)
89 msg
1 device
= \"$device\"
90 [ -z "$device" ] && err Cannot get device
for $disk
91 echo "$device" |
grep -q ^
/dev
/ || err
$device: Malformed device name
92 sudo cryptsetup status
$disk \
93 |
grep -q "/dev/mapper/$disk is active" \
94 || sudo cryptsetup luksOpen
$device $disk && mount
/media
/$disk
95 is_mounted
$disk && msg
0 $disk mounted on
/media
/$disk \
96 || err
$disk: mount failed
98 is_mounted
$disk && umount
/media
/$disk
99 is_mounted
$disk && err
/media
/$disk: umount failed
100 sudo cryptsetup luksClose
$disk
102 msg
0 $disk is unmounted and closed
105 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :