entrypoint.sh 973 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. set -eu
  3. # sync with https://github.com/fphammerle/docker-gitolite/blob/master/entrypoint.sh
  4. if [ ! -f "$SSHD_HOST_KEYS_DIR/rsa" ]; then
  5. ssh-keygen -t rsa -b 4096 -N '' -f "$SSHD_HOST_KEYS_DIR/rsa"
  6. fi
  7. if [ ! -f "$SSHD_HOST_KEYS_DIR/ed25519" ]; then
  8. ssh-keygen -t ed25519 -N '' -f "$SSHD_HOST_KEYS_DIR/ed25519"
  9. fi
  10. unset SSHD_HOST_KEYS_DIR
  11. authorize_key() {
  12. if echo -E "$2" | grep -q '^[a-z]'; then
  13. echo "command=\"/usr/bin/borg serve --restrict-to-repository '$1'$3\" $2" >> ~/.ssh/authorized_keys
  14. fi
  15. }
  16. printenv SSH_CLIENT_PUBLIC_KEYS | while IFS=$'\n' read -r key; do
  17. authorize_key "$REPO_PATH" "$key" ""
  18. done
  19. unset SSH_CLIENT_PUBLIC_KEYS
  20. # https://borgbackup.readthedocs.io/en/stable/usage/notes.html#append-only-mode
  21. printenv SSH_CLIENT_PUBLIC_KEYS_APPEND_ONLY | while IFS=$'\n' read -r key; do
  22. authorize_key "$REPO_PATH" "$key" " --append-only"
  23. done
  24. unset SSH_CLIENT_PUBLIC_KEYS_APPEND_ONLY
  25. unset REPO_PATH
  26. set -x
  27. exec "$@"