Skip to content

Instantly share code, notes, and snippets.

@creategui
Last active May 19, 2017 15:43
Show Gist options
  • Save creategui/cf105cf778922b2b1b1d32f8b91eb040 to your computer and use it in GitHub Desktop.
Save creategui/cf105cf778922b2b1b1d32f8b91eb040 to your computer and use it in GitHub Desktop.
Look for atom remote-sync configuration in current path and use rsync to sync the full directory.
# This is a companion script to the atom remote-sync addon:
# https://atom.io/packages/remote-sync
# Use it when you modify a large number of the files in your project and
# remote-sync is not aware of all the changes (e.g. sync from source control).
# It is a stopgap until remote-sync has the ability to watch a path.
#
# Does not support upload mirrors.
#
# Put this in your ~/bin or some other path that is in your $PATH
# run it from the location of your atom project that is remote-sync enabled
# it takes no parameters, it looks for the .remote-sync.json file in the current path
# Works on Mac OS. Should work in Cygwin on Windows too but have not tried.
#
# Script will not delete from remote. If you want that, change the RSYNCPARAMS
# below to "av --delete". Check rsync manual for other options.
CURPATH=`pwd`
CONFIG=$CURPATH/.remote-sync.json
if [ ! -f $CONFIG ] ; then
echo "No .remote-sync.json file here"
exit -1
fi
RSYNCPARAMS="-av"
UPLOADMIRROR=`grep '"uploadMirrors"' .remote-sync.json`
TRANSPORT=`grep '"transport"' .remote-sync.json | cut -d':' -f2 | tr -d '", '`
REMOTEHOST=`grep '"hostname"' .remote-sync.json | cut -d':' -f2 | tr -d '", '`
REMOTEPORT=`grep '"port"' .remote-sync.json | cut -d':' -f2 | tr -d '", '`
REMOTETARGET=`grep '"target"' .remote-sync.json | cut -d':' -f2 | tr -d '", '`
REMOTEUSER=`grep '"username"' .remote-sync.json | cut -d':' -f2 | tr -d '", '`
SSHKEY=`grep '"keyfile"' .remote-sync.json | cut -d':' -f2 | tr -d '", '`
if [ -n "$UPLOADMIRROR" ] ; then
echo "Upload Mirrors not supported."
exit -1
fi
if [ -z $TRANSPORT ] ; then
echo "transport parameter not in .remote-sync.json"
exit -1
fi
if [ "$TRANSPORT" != "scp" ] ; then
echo "This script only supports SCP transport."
exit -1
fi
if [ -z $REMOTEPORT ] ; then
REMOTEPORT=22
fi
TMPIGNORE=`sed '/ignore/,/]\,/!d;//d' .remote-sync.json`
while read -r LINE; do
IGNORE=`echo $LINE | tr -d '", '`
EXCLUDE="$EXCLUDE --exclude '$IGNORE'"
done <<< "$TMPIGNORE"
COMMAND="rsync $RSYNCPARAMS $EXCLUDE $CURPATH/ -e \"ssh -i $SSHKEY -p $REMOTEPORT\" $REMOTEUSER@$REMOTEHOST:$REMOTETARGET"
echo $COMMAND
eval $COMMAND
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment