rgpgfs_unattended.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. set -e
  3. if [ -z "$RECIPIENT" ]; then
  4. echo missing \$RECIPIENT >&2
  5. exit 1
  6. fi
  7. if [ ! -d "$SOURCE_DIR" ]; then
  8. echo missing source dir "$SOURCE_DIR" >&2
  9. echo add -v /somewhere:"$SOURCE_DIR":ro >&2
  10. exit 1
  11. fi
  12. if [ ! -d "$CIPHER_DIR" ]; then
  13. echo missing mount point "$CIPHER_DIR" >&2
  14. echo add -v /somewhere:"$CIPHER_DIR":shared >&2
  15. exit 1
  16. fi
  17. function key_available {
  18. gpg --quiet --list-public-keys "$RECIPIENT" > /dev/null
  19. }
  20. recv_retries=0
  21. while [ $recv_retries -lt 3 ] && ! key_available; do
  22. [ $recv_retries -ne 0 ] && sleep 1s
  23. (set -x; gpg --receive-keys "$RECIPIENT") || true
  24. recv_retries=$((recv_retries + 1))
  25. done
  26. if ! key_available; then
  27. echo failed to fetch recipient\'s key >&2
  28. exit 1
  29. fi
  30. set -x
  31. grep -q "^trust-model always$" ~/.gnupg/gpg.conf 2> /dev/null \
  32. || echo trust-model always | tee ~/.gnupg/gpg.conf
  33. trap 'fusermount3 -u -z "$CIPHER_DIR"' SIGTERM
  34. rgpgfs -f -o allow_other \
  35. -o modules=subdir,subdir="$SOURCE_DIR" \
  36. -o recipient="$RECIPIENT" \
  37. "$CIPHER_DIR" &
  38. wait $!