[cluster] deploy: fix destination directory

"~" is resolved by the local shell (dumb me!). We now get the
destination directory by connecting to the first alive host from the
hosts' list (using cluster-ping), and get the user's home directory.
This is not perfect because it assumes the home directory is the same on
each host.

We could add an option in the future to do the test on each host, but
this would be significantly slower. Alternatively, we could allow to use
scp instead of pscp (because scp is smart enough to get the remote
user's home directory by itself), transferring files once at time, but
again, it would be slow.
This commit is contained in:
Matteo Cypriani 2013-05-20 14:35:49 -04:00
parent 5a44742c28
commit 2c6f1a97ea
2 changed files with 23 additions and 5 deletions

View File

@ -73,4 +73,5 @@ Please note that unlike rsync, prsync cannot handle multiple local
files, therefore the -P option is ignored when passed along with -r or
-R.
Dependencies: parallel-scp (pscp), parallel-rsync (prsync)
Dependencies: parallel-scp (pscp), parallel-rsync (prsync), cluster-ping
(see above)

View File

@ -90,27 +90,44 @@ elif [ "$PRSYNC" = "" ] ; then
fi
# Hosts' list file
HOSTS="$HOME/.config/cluster/$1.lst"
HOSTS_LIST_NAME="$1"
HOSTS="$HOME/.config/cluster/${HOSTS_LIST_NAME}.lst"
shift
echo "Using file '$HOSTS' as hosts' list."
# Login
if [ "$LOGIN" != "" ] ; then
echo "Login: $LOGIN"
SSH_LOGIN="${LOGIN}@"
LOGIN="-l $LOGIN"
fi
# Test the connection to the first host and get the destination
# directory (home directory of the remote user)
FIRST_HOST=$(cluster-ping "$HOSTS_LIST_NAME" 2>/dev/null | sed -n "s/ is alive$//p" | head -n1)
if [ "$FIRST_HOST" = "" ] ; then
echo "None of the remote hosts is alive."
exit 6
fi
echo "Testing connection to $FIRST_HOST..."
DEST_DIR="$(ssh ${SSH_LOGIN}${FIRST_HOST} 'echo $HOME' 2>/dev/null)"
if [ "$DEST_DIR" = "" ] ; then
echo "Cannot connect to the first alive host. Aborting."
exit 7
fi
echo "Destination directory: $DEST_DIR"
# Transfer the files in parallel...
if [ "$PARALLEL" = "1" ] ; then
exec $PSCP -r $LOGIN -h "$HOSTS" -- "$@" ~
exec $PSCP -r $LOGIN -h "$HOSTS" -- "$@" "$DEST_DIR"
fi
# ... or one by one
for FILE in "$@" ; do
echo "Deploying '$FILE'..."
if [ "$RSYNC" = "1" ] ; then
$PRSYNC -a $DELETE $LOGIN -h "$HOSTS" -- "$FILE" ~
$PRSYNC -a $DELETE $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
else
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" ~
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" "$DEST_DIR"
fi
done