tatoo/ecryptfs_storage.sh

35 lines
1.3 KiB
Bash

[ "$EUID" -eq 0 ] || { echo '[ERROR] The script must be executed under sudo!'; exit 1; };
echo '----- START ECRYPTFS STORAGE -----';
# Get action
Action=${1};
echo '[INFO] Action: '${Action}'';
Directory=${2};
echo '[INFO] Directory: '${Directory}'';
if [ "${Action}" == 'mount' ]; then {
# Install packages
apt install -y ecryptfs-utils
# Key file must contain: Passphrase, Signature, KeyBytes (default 32), Cipher (default 'aes')
# Signature can be calculated with ecryptfs-add-passphrase
KeyFile=${3};
echo '[INFO] Key File: '${KeyFile}'';
source <( GNUPGHOME=/home/amnesia/.gnupg gpg -d "${KeyFile}"; );
[ -z "${Passphrase}" ] && { echo '[ERROR] Key File cannot be decrypted. Exiting.'; exit 1; };
mount -t ecryptfs "${Directory}" "${Directory}" -o key=passphrase:passphrase_passwd=${Passphrase},ecryptfs_unlink_sigs,ecryptfs_fnek_sig=${Signature},ecryptfs_key_bytes=${KeyBytes},ecryptfs_cipher=${Cipher},ecryptfs_sig=${Signature};
[ $? -eq 0 ] || { echo "[ERROR] Can't mount directory. Exiting."; exit 1; };
echo '[INFO] Directory mounted';
} fi;
if [ "${Action}" == 'umount' ]; then {
umount ${Directory};
[ $? -eq 0 ] || { echo "[ERROR] Can't unmount directory. Exiting."; exit 1; };
echo '[INFO] Directory unmounted';
} fi;
echo '----- END ECRYPTFS STORAGE -----';