blob: a6ef5b66594261b48e1f2be23b82f5c6075afbec (
plain)
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
34
35
36
37
38
39
40
41
42
43
|
#!/bin/bash
#
# mount-media
#
# Parameters
MEDIA="$1"
VOLUME="$2"
BASENAME="`basename $0`"
MOUNTPOINT="/media/usb"
# Check media config
if [ -z "$MEDIA" ]; then
echo "usage: $BASENAME <media> [volume]"
echo "example: $BASENAME mymedia sdb1"
exit 1
fi
# Check volume config
if [ -z "$VOLUME" ]; then
VOLUME="sdb1"
fi
DISK="`echo ${VOLUME} | sed -e s/[0-9]\$//g`"
# Set sudo config
if [ "`whoami`" != 'root' ]; then
sudo="sudo"
fi
if [ "$BASENAME" == "mount-media" ]; then
echo "Disabling STANDBY on drive..."
$sudo sdparm --clear STANDBY -6 /dev/$DISK
echo "Initializing crypto layer..."
$sudo cryptsetup luksOpen /dev/$VOLUME $MEDIA && \
echo "Checking filesystem..."
$sudo fsck -v -y /dev/mapper/$MEDIA && \
echo "Mounting volume at $MOUNTPOINT"
$sudo mount /dev/mapper/$MEDIA $MOUNTPOINT"
elif [ "$BASENAME" == "umount-media" ]; then
$sudo umount /media/usb && \
$sudo cryptsetup luksClose $MEDIA
fi
|