diff options
author | Joey Hess <joey@kitenet.net> | 2013-12-27 16:01:43 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-12-27 16:01:43 -0400 |
commit | c1cc4d23de10e5669a42164b9145acea732be60d (patch) | |
tree | da75e73f9a0523428233d0e5f644826bae07c379 /doc/special_remotes | |
parent | c1d48d64b4d93c0a684ef68262b9e14b1b63005d (diff) |
add credential storage support for external special remotes & update example
Diffstat (limited to 'doc/special_remotes')
-rwxr-xr-x | doc/special_remotes/external/example.sh | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/doc/special_remotes/external/example.sh b/doc/special_remotes/external/example.sh index 97f8a2813..428e2ecb9 100755 --- a/doc/special_remotes/external/example.sh +++ b/doc/special_remotes/external/example.sh @@ -48,6 +48,32 @@ ask () { esac } +# This remote doesn't need credentials to access it, +# but many of them will. Here's how to handle requiring the user +# set MYPASSWORD and MYLOGIN when running initremote. The creds +# will be stored securely for later use, so the user only needs +# to provide them once. +setupcreds () { + if [ -z "$MYPASSWORD" ] || [ -z "$MYLOGIN" ]; then + echo INITREMOTE-FAILURE "You need to set MYPASSWORD and MYLOGIN environment variables when running initremote." + else + echo SETCREDS mycreds "$MYLOGIN" "$MYPASSWORD" + echo INITREMOTE-SUCCESS + fi +} + +getcreds () { + echo GETCREDS mycreds + read resp + case "${resp%% *}" in + CREDS) + MYLOGIN="$(echo "$resp" | sed 's/^CREDS \([^ ]*\) .*/\1/')" + MYPASSWORD="$(echo "$resp" | sed 's/^CREDS [^ ]* //')" + ;; + esac + +} + # This has to come first, to get the protocol started. echo VERSION 1 @@ -66,16 +92,17 @@ while read line; do # git annex initremote or git annex enableremote is # run.) + # The directory provided by the user + # could be relative; make it absolute, + # and store that. getconfig directory - # Input directory could be relative; make it - # absolute, and store that. - mydirectory="$(readlink -f "$RET")" + mydirectory="$(readlink -f "$RET")" || true setconfig directory "$mydirectory" if [ -z "$mydirectory" ]; then echo INITREMOTE-FAILURE "You need to set directory=" else if mkdir -p "$mydirectory"; then - echo INITREMOTE-SUCCESS + setupcreds else echo INITREMOTE-FAILURE "Failed to write to $mydirectory" fi @@ -87,6 +114,7 @@ while read line; do # special remote here. getconfig directory mydirectory="$RET" + getcreds echo PREPARE-SUCCESS ;; TRANSFER) |