mount.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. set -e
  3. ENCFS_SOURCE_CONFIG_PATH="$ENCFS_SOURCE_DIR/.encfs6.xml"
  4. if [ ! -f "$ENCFS_PASSWORD_PATH" ]; then
  5. echo generating encfs password at $ENCFS_PASSWORD_PATH
  6. (set -x;
  7. tr -dc "$ENCFS_PASSWORD_CHARSET" < /dev/random | head -c "$ENCFS_PASSWORD_LENGTH" > "$ENCFS_PASSWORD_PATH")
  8. [ -f "$ENCFS_SOURCE_CONFIG_PATH" ] && (set -x; rm "$ENCFS_SOURCE_CONFIG_PATH")
  9. fi
  10. # cave: when $ENCFS6_CONFIG is set, encfs expects the config to already exist
  11. # ERROR fatal: config file specified by environment does not exist: /target/config/encfs6.xml [FileUtils.cpp:246]
  12. # https://github.com/vgough/encfs/issues/497
  13. function copy_config {
  14. sleep 4
  15. while [ ! -f "$ENCFS_SOURCE_CONFIG_PATH" ]; do
  16. echo waiting for encfs to create $ENCFS_SOURCE_CONFIG_PATH
  17. sleep 2
  18. done
  19. (set -x; cp "$ENCFS_SOURCE_CONFIG_PATH" "$ENCFS_CONFIG_COPY_PATH")
  20. }
  21. copy_config &
  22. set -x
  23. mkdir -p "$ENCFS_MOUNT_POINT"
  24. trap 'fusermount -u -z "$ENCFS_MOUNT_POINT"' SIGTERM
  25. encfs -f -o allow_other --reverse --standard \
  26. --extpass="cat \"$ENCFS_PASSWORD_PATH\"" \
  27. "$ENCFS_SOURCE_DIR" "$ENCFS_MOUNT_POINT" &
  28. wait $!