Last active
November 10, 2018 17:50
-
-
Save eacousineau/1edce0fc62b375501e20b555c4cb5c63 to your computer and use it in GitHub Desktop.
Makes and mounts temporary encfs partition that is removed upon program exit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Makes and mounts temporary encfs partition that is removed upon program exit. | |
# Requires encfs. | |
set -eu -o pipefail | |
tmp=$(mktemp -d) | |
enc=${tmp}/.enc | |
mnt=${tmp}/mnt | |
encfs_stdin() { ( | |
secret=$(uuidgen) | |
echo "p" | |
echo "${secret}" | |
echo "${secret}" | |
) } | |
at_exit() { | |
echo "Cleanup" >&2 | |
rm -rf ${tmp} | |
} | |
wait_for_it() { | |
echo "Waiting..." >&2 | |
set +o pipefail | |
while ! mount | grep -q ${mnt}; do | |
sleep 0.1 | |
done | |
set -o pipefail | |
echo ${mnt} | |
echo "Ctrl+C to unmount and remove" >&2 | |
} | |
trap at_exit EXIT | |
wait_for_it & | |
mkdir ${enc} ${mnt} | |
encfs_stdin | { encfs -f -S ${enc} ${mnt} > /dev/null; } | |
echo "Done" >&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment