Skip to content

Instantly share code, notes, and snippets.

@eacousineau
Last active November 10, 2018 17:50
Show Gist options
  • Save eacousineau/1edce0fc62b375501e20b555c4cb5c63 to your computer and use it in GitHub Desktop.
Save eacousineau/1edce0fc62b375501e20b555c4cb5c63 to your computer and use it in GitHub Desktop.
Makes and mounts temporary encfs partition that is removed upon program exit.
#!/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