#!/bin/sh ################################################################# # Mounting an extrenal device and mount an encrypted container # # in it. # # # # Author: Maximilian Stiefel # # Last modified: 23. April 2017 # # CLI usage: ./mount_enc.sh # # Required PKGs: encfs, sudo # # # ################################################################# ################################################################# # Vars # ################################################################# # Mountpoint for external drive MOUNT_POINT="/media/sack/xxxx" # Device identifier DEVICE="/dev/sdc34" # File system (-t option of mount) FILE_SYSTEM="fat32" # Encfs enrypted files location ENC_LOC="$MOUNT_POINT/.sexy" # Encfs mount point ENC_MP="$MOUNT_POINT/sexy" # Link to mount point LINK="/home/sack/sssss" # Command to execute for mounting MYCMD1="sudo mount -t $FILE_SYSTEM $DEVICE $MOUNT_POINT" # Command to create a mount point if necessary MYCMD2="mdkir $MOUNT_POINT" # Command to check wether the device is already mounted MYCMD3=$(mount | grep $DEVICE) # Command to use encfs MYCMD4="encfs $ENC_LOC $ENC_MP" # Command to create link MYCMD5="ln -s $MOUNT_POINT $LINK" ################################################################# # Action # ################################################################# # Check if mount point does exist if not create if [ ! -d "$MOUNT_POINT" ]; then echo "####################################################" echo "Creating directory $MOUNT_POINT" echo "####################################################" echo "$MYCMD2" $MYCMD2 echo fi # Check if mounted already. Is string value set? if [ ! -n "$MYCMD3" ] then echo "####################################################" echo "Mounting external device $DEVICE" echo "to $MOUNT_POINT." echo "####################################################" echo "$MYCMD1" $MYCMD1 echo else echo "####################################################" echo "$DEVICE is already mounted." echo "####################################################" echo fi # Use encfs to create/mount encrypted files echo "####################################################" echo "Starting encfs." echo "####################################################" echo "$MYCMD4" $MYCMD4 echo # Check if link already exists if [ ! -e $LINK ] then echo "####################################################" echo "Creating symlink $LINK." echo "####################################################" echo "$MYCMD5" $MYCMD5 echo fi read -n1 -r -p "Waiting for termination. Press any key ... " key exit 0;