Skip to content

Commit

Permalink
Release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
reasonablytall committed Apr 21, 2018
1 parent a83d29e commit 16edcfa
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 1 deletion.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
# yarsync
A clean, simple, and swashbuckling tool for synchronizing directories
A quick, simple, and swashbuckling tool for synchronizing directories

## Install

Clone this repository and move `yarsync` somewhere in your path, or call it directly.

### Dependences

yarsync requires `rsync` as well as `inotifywait` from `inotify-tools`.

## Usage

Specify `src` and `dest` directories, and yarsync will keep `dest` synchronized with `src` until exited. `dest` can be a network directory over ssh, like below:

```sh
yarsync ship/ [email protected]:~/ &

touch ship/cannon.ball
# cannon.ball now exists in both ship/cannon.ball and [email protected]:~/ship/cannon.ball
# changes to ship/cannon.ball will be mirrored in [email protected]:~/ship/cannon.ball
```

## Options

See `yarsync -h` for a list of all options.

* `yarsync --delete src dest` will delete files in `dest` if they aren't in `src` to keep both sides ship-shape.

* `yarsync --exclude=swabbie src dest` will exclude the file/directory `swabbie` from synchronization.
`--exclude` can be specified multiple times.
105 changes: 105 additions & 0 deletions yarsync
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/sh

# Constants --------------------------------------------------------------------

VERSION=1.0.0
NAME=$(basename "$0")

OPTIONS=de:vhV
LONGOPTIONS=delete,exclude:,help,verbose,version

USAGE="\
Usage: $0 [OPTION]... [-e PATTERN]... SRC DEST
continuously sync two directories using rsync
-d, --delete delete extraneous files and directories in DEST
-e, --exclude=PATTERN exclude files matching PATTERN
-v, --verbose be verbose
-h, --help show this help text
-V, --version print program version"

# Options ----------------------------------------------------------------------

# test if enhanced getopt is available
getopt --test >/dev/null
if [[ $? -ne 4 ]]; then
echo "I’m sorry, $(getopt --test) failed in this environment."
exit 1
fi

# use getopt to parse arguments
parsed=$(getopt --options=$OPTIONS --longoptions=$LONGOPTIONS --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
exit 2
fi
eval set -- "$parsed"

while true; do
case "$1" in
-d | --delete)
delete=true
shift
;;
-e | --exclude)
excluded="$excluded --exclude $2"
shift 2
;;
-v | --verbose)
verbose=true
shift
;;
-h | --help)
echo "$USAGE"
exit 0
;;
-V | --version)
echo "$NAME $VERSION"
exit 0
;;
-o | --output)
outFile="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Getopt parsing error"
exit 3
;;
esac
done

# handle non-option arguments
if [[ $# -ne 2 ]]; then
echo "Not enough input arguments. See $NAME --help"
exit 4
fi

src="$1"
dest="$2"

# Setup ------------------------------------------------------------------------

if [[ $verbose ]]; then
inwait_opts="-rq"
rsync_opts="-azv"
else
inwait_opts="-rqq"
rsync_opts="-az"
fi

inwait_events="-e modify -e attrib -e close_write -e move -e move_self \
-e create -e delete -e delete_self -e unmount"

inwait_args="$inwait_opts $inwait_events $src $excluded"
rsync_args="$rsync_opts $src $dest $excluded"

# Main -------------------------------------------------------------------------

rsync $rsync_args | sed "s/^/rsync: /"
while inotifywait $inwait_args | sed "s/^/inotifywait: /"; do
rsync $rsync_args | sed "s/^/rsync: /"
done

0 comments on commit 16edcfa

Please sign in to comment.