]> git.madduck.net Git - etc/offlineimap.git/blob - .offlineimap/preauthtunnel.sh

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

ignore scratch dir
[etc/offlineimap.git] / .offlineimap / preauthtunnel.sh
1 #!/bin/sh
2
3 REMOTE_HOST="$1"
4 IMAP_COMMAND="${2:-MAIL=\$HOME/.maildir /usr/lib/dovecot/imap 2>/dev/null}"
5
6 SSH_KEY="$HOME/.offlineimap/${REMOTE_HOST}.ssh-seckey"
7 SSH_OPTIONS="command=\"$IMAP_COMMAND\",no-agent-forwarding,no-X11-forwarding,no-port-forwarding,no-pty"
8
9 if [ ! -f "$SSH_KEY" ]; then
10   ssh-keygen -f "$SSH_KEY" -C "OfflineIMAP from $(hostname)" -N '' -t ed25519
11   COMMAND="echo '$SSH_OPTIONS $(cat "$SSH_KEY.pub")' >> .ssh/authorized_keys"
12   ssh -F ~/.offlineimap/ssh_config -o ControlPath=none -o IdentityAgent=SSH_AUTH_SOCK \
13     ${REMOTE_HOST} "$COMMAND"
14 fi
15
16 exec ssh -F ~/.offlineimap/ssh_config -i "$SSH_KEY" ${1} \
17   echo "You need to configure a password-less SSH keypair and have the public key in the remote\'s" \
18     "\~/.ssh/authorized_keys file, prefixed by \'$SSH_OPTIONS\'. You can try to invoke \'$0 $REMOTE_HOST\'"\
19     "from an interactive shell and it will attempt to set this up for you."
20
21 # This relies on the IMAP command being specified on the server side, i.e. in
22 # ~/.ssh/authorized_keys, put a line like the following
23 #
24 #   command="MAIL=$HOME/.maildir /usr/lib/dovecot/imap 2>/dev/null",no-agent-forwarding,no-X11-forwarding,no-port-forwarding,no-pty ssh-ed25519 AAA…
25 #
26 # When a command is specified like this, it overrides the instructions being
27 # passed in the command above. So, when you invoke this script directly, you
28 # should see the IMAP server greet you:
29 #
30 # % ~/.offlineimap/preauthtunnel.sh madduck-net.imap.madduck.net
31 # * PREAUTH [CAPABILITY IMAP4rev1 […]] Logged in as madduck
32
33 # vim:tw=0