translate.sh (2058B)
1 to_duplicity_remote() { 2 3 # remote host is defined in rsync format 4 # ... and we will only support scp 5 # $remote_base is the path we want to parse 6 remote_duplicity_base= 7 remote_base=$1 8 9 # substring up until the first slash 10 s_firstslash=${remote_base%%/*} 11 12 # substring up until the first colon 13 s_firstcolon=${remote_base%%:*} 14 15 # string index of the first slash 16 i_firstslash=$((${#s_firstslash})) 17 18 # string index of the first colon 19 i_firstcolon=$((${#s_firstcolon})) 20 21 # if colon is before first slash that most likely means we have a remote host 22 # (Exception is if first directory of path happens to have ":" in it. Seriously, don't use ":" in filenames) 23 if [ "$i_firstcolon" -gt "0" ]; then 24 25 if [ "$i_firstcolon" -lt "$i_firstslash" ]; then 26 27 # pexpect addition due to lack of implicit private key fetch, without pexpect works only with key wo pwd 28 # https://serverfault.com/questions/982591/duplicity-backup-fails-private-key-file-is-encrypted 29 remote_duplicity_base="pexpect+scp://" 30 31 # trim url so that colon after hostname is removed 32 # (no support here for setting an alternate port number) 33 remote_duplicity_base=${remote_duplicity_base}${remote_base:0:$i_firstcolon} 34 remote_duplicity_base=${remote_duplicity_base}/${remote_base:(($i_firstcolon+1))} 35 36 # indicate that we have a remote host 37 remote=1 38 fi 39 fi 40 41 # If it's not a remote host, treat it as a file 42 if [ -z $remote_duplicity_base ]; then 43 remote_duplicity_base="file://${remote_base}" 44 fi 45 } 46 47 if [ ! -z "$BAK_TEST" ]; then 48 src=(/foo/bar foo/bar localhost:foo/bar localhost:/foo/bar) 49 res=(file:///foo/bar file://foo/bar pexpect+scp://localhost/foo/bar pexpect+scp://localhost//foo/bar) 50 51 i=0 52 for case_src in ${src[@]}; do 53 case_res=${res[$i]} 54 55 to_duplicity_remote $case_src 56 if [ "$remote_duplicity_base" != "$case_res" ]; then 57 >&2 echo "expected $case_res got $remote_duplicity_base from $case_src" 58 exit 1 59 elif [ "$remote_base" != "$case_src" ]; then 60 >&2 echo "$case_src got mangled into $remote_base" 61 exit 1 62 fi 63 i=$((i+1)) 64 done 65 fi