-
Notifications
You must be signed in to change notification settings - Fork 9
/
cd-encfs
65 lines (55 loc) · 1.88 KB
/
cd-encfs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Auto EncFS mounting | Spencer Tipping
# Licensed under the terms of the MIT source code license
if which encfs > /dev/null; then
cd_on '^enc:' cd_encfs_mount cd_encfs_umount
cd_on '^renc:' cd_rencfs_mount cd_rencfs_umount
else
echo 'cd-encfs: no encfs binary found in $PATH'
fi
# An interesting thing with encfs: it doesn't by default hold an open
# filehandle to the directory you've mounted. As a result, if you cd into one
# virtual mountpoint, then cd into an enc:X directory inside that, the first
# one will be unmounted since it appears to not be in use.
#
# The workaround is to run a subshell process that will hold a reference (via
# CWD) to the outer filesystem for enough time to do the encFS mount. After
# that we can probably live with opportunistic unmounting provided no open
# files.
function cd_encfs_wrapper {
local target=${1#enc:}
local mountpoint=$2
# Convert the target into an absolute directory. Otherwise encfs will refuse
# to run in daemon mode.
pushd "$target" > /dev/null || return $?
local real_target=$PWD
(sleep 60 &)
popd > /dev/null
encfs -o allow_root "$real_target" "$mountpoint"
}
function cd_encfs_mount {
cd_mount cd_encfs_wrapper "$@"
}
function cd_encfs_umount {
cd_umount "fusermount -u" "$@"
}
# encfs --reverse support
# Just like encfs, but backwards: you mount an unencrypted directory and see an
# encrypted one. Useful for rsync to insecure locations.
function cd_rencfs_wrapper {
local target=${1#renc:}
local mountpoint=$2
# Convert the target into an absolute directory. Otherwise encfs will refuse
# to run in daemon mode.
pushd "$target" > /dev/null || return $?
local real_target=$PWD
(sleep 60 &)
popd > /dev/null
encfs --reverse -o allow_root "$real_target" "$mountpoint"
}
function cd_rencfs_mount {
cd_mount cd_rencfs_wrapper "$@"
}
function cd_rencfs_umount {
cd_umount "fusermount -u" "$@"
}