Last active
August 29, 2015 14:16
-
-
Save yofreke/89d22dc16be8115668dc to your computer and use it in GitHub Desktop.
js.io container rsync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### | |
### EXPERIMENTAL: USE AT YOUR OWN RISK! | |
### Note: This is a 1 way sync. Initially the local directory is populated with | |
### files from the container, however any files created on the container (while | |
### this script is running) will be destroyed. | |
### ONLY CREATE FILES CLIENT SIDE WHILE RUNNING THIS SCRIPT. | |
### Usage: ./jsioContainerRsync.sh /Users/Brown/Documents/mycontainer weeby@joeorg1.js.io 49243 | |
### | |
command -v fswatch >/dev/null 2>&1 || { echo >&2 "Please run 'brew install fswatch' before running this program."; exit 1; } | |
LOCAL_DIR=$1 | |
REMOTE=$2 | |
PORT=$3 | |
RSYNC="rsync -avz -urO --exclude=\"*.log\" --exclude=\"build/*\" -e \"ssh -p $PORT\" --delete" | |
set -e | |
# Catch sigs since we will be in the while loop doing god knows what | |
trap "echo Exited!; exit;" SIGINT SIGTERM | |
# Run the initial sync | |
mkdir -p $LOCAL_DIR | |
sync_up () { | |
eval "$RSYNC $LOCAL_DIR/projects $REMOTE:/home/weeby" | |
} | |
sync_down () { | |
eval "$RSYNC $REMOTE:/home/weeby/projects $LOCAL_DIR" | |
} | |
sync_down | |
# Watch the directory | |
while true; do | |
echo "Watching for changes at $LOCAL_DIR" | |
fswatch -r1 $LOCAL_DIR -e \.git/ -e \.tmp | |
echo "SYNCING DIRECTORIES!" | |
sync_up | |
echo " Success" | |
echo "" | |
done | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment