dotfiles/tools/mount-vault
2020-02-01 16:14:13 +00:00

34 lines
799 B
Bash
Executable file

#!/usr/bin/env bash
set -e
VERACRYPT="veracrypt"
if [[ "$OSTYPE" == "darwin"* ]]; then
VERACRYPT="/Applications/VeraCrypt.app/Contents/MacOS/VeraCrypt"
fi
MOUNT_TARGET=$2
if [[ -z "$MOUNT_TARGET" ]]; then
MOUNT_TARGET=$HOME/.vault
fi
sudo chown $USER "$MOUNT_TARGET"
mkdir -p "$MOUNT_TARGET"
MOUNT_SOURCE=$1
if [[ -z "$MOUNT_SOURCE" ]]; then
MOUNT_SOURCE="$HOME/vaults/vault.vera"
fi
if [[ -z "$VAULT_PASSWORD" ]]; then
echo "interactive mount"
$VERACRYPT -t --mount "$MOUNT_SOURCE" "$MOUNT_TARGET"
else
echo "non-interactive mount of '$MOUNT_SOURCE' to '$MOUNT_TARGET'"
sudo $VERACRYPT -t --non-interactive -p $VAULT_PASSWORD --mount "$MOUNT_SOURCE" "$MOUNT_TARGET"
fi
sudo chown $USER "$MOUNT_TARGET"
echo "$MOUNT_SOURCE -> $MOUNT_TARGET"
$MOUNT_TARGET/install