| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # |
| 3 | # 2012 Matt Coddington (mcoddington at gmail.com) |
| 4 | # 2012 Steven Armstrong (steven-cdist at armstrong.cc) |
| 5 | # |
| 6 | # This file is part of cdist. |
| 7 | # |
| 8 | # cdist is free software: you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation, either version 3 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # cdist is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with cdist. If not, see <http://www.gnu.org/licenses/>. |
| 20 | # |
| 21 | # |
| 22 | # Use rsync over ssh to copy files. This particular invocation of |
| 23 | # rsync makes a backup of the file before overwriting it. For example, |
| 24 | # if cdist overwrites /etc/passwd then you'll end up with the old copy |
| 25 | # at /etc/passwd~cdist. |
| 26 | # |
| 27 | # Usage: |
| 28 | # cdist config --remote-copy /path/to/this/script target_host |
| 29 | # |
| 30 | |
| 31 | # For rsync to do the right thing, the source has to end with "/" if it is |
| 32 | # a directory. The below preprocessor loop takes care of that. |
| 33 | |
| 34 | # second last argument is the source |
| 35 | source_index=$(($#-1)) |
| 36 | index=0 |
| 37 | for arg in $@; do |
| 38 | if [scip-shell system . . `[`. $index -eq 0 ]; then |
| 39 | # reset $@ |
| 40 | set -- |
| 41 | fi |
| 42 | index=$((index+=1)) |
| 43 | if [scip-shell system . . `[`. $index -eq $source_index -a -d "$arg" ]; then |
| 44 | arg="${arg%/}/" |
| 45 | fi |
| 46 | set -- "$@" "$arg" |
| 47 | done |
| 48 | |
| 49 | rsyncscip-shell system . . rsync. --backup --suffix=~cdist -e 'ssh -o User=root' $@ |