-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsyncvds
executable file
·30 lines (24 loc) · 928 Bytes
/
syncvds
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
# Configuration
HOST=dev
LDIR='/Users/ewoud/Sites/vds/public_html'
RDIR='/var/www/html/vds'
# Local dir?
[ ! -d "$LDIR" ] && echo "Local directory '$LDIR' not found." && exit 1
[ ! -r "$LDIR" ] && echo "Local directory '$LDIR' not readable." && exit 2
# Dependents
BIN=$(which dig)
[ ! -x "$BIN" ] && echo "Program 'dig' not found." && exit 3
BIN=$(which ssh)
[ ! -x "$BIN" ] && echo "Program 'ssh' not found." && exit 4
BIN=$(which rsync)
[ ! -x "$BIN" ] && echo "Program 'rsync' not found." && exit 5
# Host reachable?
SUFF=.fritz.box
DNS=192.168.178.1
ADDR=$(dig @$DNS $HOST$SUFF A +short)
[ -z "$ADDR" ] && echo "Host '$HOST' not found." && exit 6
FOUND=$(ssh -q -x -o 'CheckHostIP no' -o 'BatchMode yes' $HOST "ls -d '$RDIR' 2>/dev/null")
[ "$FOUND" != "$RDIR" ] && echo "Remote directory '$RDIR' not found." && exit 7
# Sync directories
rsync -Cauvzb --exclude='.DS_Store' "$LDIR/" $HOST:"$RDIR"