Created
October 22, 2013 16:30
-
-
Save nickboldt/7103789 to your computer and use it in GitHub Desktop.
Using rsync over ssh, push all dirty files in local git repo to another server (or explicitly list which files to push)
This file contains hidden or 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 | |
| usage () | |
| { | |
| echo "Usage 1: $0 -s user@server:/path/ path/to/rsync path2/to/rsync path3/to/rsync ..." | |
| echo " $0 -s user@server:/path/to/devstudio/ updates/7.0/devstudio-directory.xml" | |
| echo "Usage 2: $0 -s user@server:/path/to/jbosstools/ -dirty" | |
| echo " -dirty flag will push all files listed with 'git status -s' to specified server" | |
| exit 1; | |
| } | |
| if [[ $# -lt 3 ]]; then | |
| usage; | |
| fi | |
| dirty=0 | |
| server="" | |
| paths="" | |
| while [[ "$#" -gt 0 ]]; do | |
| case $1 in | |
| '-s') server="$2"; shift 1;; | |
| '-dirty') dirty=1; paths="$paths `git status -s`"; shift 0;; | |
| *) paths="$paths $1";; | |
| esac | |
| shift 1 | |
| done | |
| for path in $paths; do | |
| # path must contain at least one slash or will be rejected | |
| if [[ ${path##*/*} == "" ]]; then | |
| echo "rsync {,${server}/}$path" | |
| rsync -Pzrlt --rsh=ssh --protocol=28 {,${server}/}$path | |
| elif [[ ${#path} -lt 3 ]]; then # show the git dirty state | |
| echo -n "$path " | |
| else | |
| echo "$path SKIPPED - paths must include a /" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment