From c472b47a739506f19e7fbce6503ebb3d5fd79921 Mon Sep 17 00:00:00 2001 From: deajan Date: Fri, 26 Jun 2015 17:54:49 +0200 Subject: [PATCH] Improved ssh uri recognition --- CHANGELOG.md | 1 + osync.sh | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef964d6..dd3a701 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ UNDER WORK RECENT CHANGES -------------- +- Improved ssh uri recognition (thanks to onovy) - Fixed #21 by adding portable shell readlink / realpath from https://github.com/mkropat/sh-realpath - Added detection of osync.sh script in osync-batch.sh to overcome mising path in crontab - Fixed osync-batch.sh script when osync is in executable path like /usr/local/bin diff --git a/osync.sh b/osync.sh index ca88005..93456ba 100755 --- a/osync.sh +++ b/osync.sh @@ -1741,11 +1741,12 @@ function Init # remove leadng 'ssh://' uri=${SLAVE_SYNC_DIR#ssh://*} - # remove everything after '@' - REMOTE_USER=${uri%@*} - if [ "$REMOTE_USER" == "" ] + if [[ "$uri" == *"@"* ]] then - REMOTE_USER=$LOCAL_USER + # remove everything after '@' + REMOTE_USER=${uri%@*} + else + REMOTE_USER=$LOCAL_USER fi if [ "$SSH_RSA_PRIVATE_KEY" == "" ] @@ -1757,13 +1758,14 @@ function Init _hosturiandpath=${uri#*@} # remove everything after first '/' _hosturi=${_hosturiandpath%%/*} - # remove last part if no port defined - REMOTE_HOST=${_hosturi%%:*} - REMOTE_PORT=${_hosturi##*:} - if [ "$REMOTE_PORT" == "" ] + if [[ "$_hosturi" == *":"* ]] then + REMOTE_PORT=${_hosturi##*:} + else REMOTE_PORT=22 fi + REMOTE_HOST=${_hosturi%%:*} + # remove everything before first '/' SLAVE_SYNC_DIR=${_hosturiandpath#*/} fi