aboutsummaryrefslogtreecommitdiff
path: root/share/hydractl/mount-media
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2016-10-02 15:31:42 -0300
committerSilvio Rhatto <rhatto@riseup.net>2016-10-02 15:31:42 -0300
commitfdb07b542860089eb208ec5967826a2225899d10 (patch)
tree1684d5eee1520e8416c6775416f459afed04c02b /share/hydractl/mount-media
parentd13a337e8bc54ace1ea98ff5faae01d525d9dd21 (diff)
downloadhydra-fdb07b542860089eb208ec5967826a2225899d10.tar.gz
hydra-fdb07b542860089eb208ec5967826a2225899d10.tar.bz2
Adds media and backup scripts originally from puppet-backup
Diffstat (limited to 'share/hydractl/mount-media')
-rwxr-xr-xshare/hydractl/mount-media46
1 files changed, 46 insertions, 0 deletions
diff --git a/share/hydractl/mount-media b/share/hydractl/mount-media
new file mode 100755
index 0000000..0073292
--- /dev/null
+++ b/share/hydractl/mount-media
@@ -0,0 +1,46 @@
+#!/bin/bash
+#
+# mount-media
+#
+
+# Parameters
+MEDIA="$1"
+VOLUME="$2"
+BASENAME="`basename $0`"
+MOUNTPOINT="/media/$MEDIA"
+
+# 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 "Checking drive health status..."
+ $sudo smartctl -H /dev/$DISK
+ 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 mkdir -p $MOUNTPOINT
+ $sudo mount /dev/mapper/$MEDIA $MOUNTPOINT
+elif [ "$BASENAME" == "umount-media" ]; then
+ $sudo umount $MOUNTPOINT && \
+ $sudo cryptsetup luksClose $MEDIA
+fi