-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwpsync
executable file
·91 lines (75 loc) · 2.21 KB
/
wpsync
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#! /bin/bash
# ssh parameters are stored in
# ~/.ssh/config
# initializing options
evtdry=""
del=""
custom_arg=""
# checker (array) for pull or push to avoid pull and push together
checker=()
# source from full bash getopts:
# http://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
#
# Usage ./myscript.sh -e conf -s /etc -l /usr/lib /etc/hosts
#
# Use -gt 1 to consume two arguments per pass in the loop (e.g. each
# argument has a corresponding value to go with it).
# Use -gt 0 to consume one or more arguments per pass in the loop (e.g.
# some arguments don't have a corresponding value to go with it such
# as in the --default example).
# note: if this is set to -gt 0 the /etc/hosts part is not recognized ( may be a bug )
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
pull|--pull)
sourcefolder="test.valentinoberson.ch/"
dest="/home/walo/code_the_web/wp/test.valentinoberson.ch"
checker+=('pull')
;;
push|--push)
sourcefolder="/home/walo/code_the_web/wp/test.valentinoberson.ch/"
dest="test.valentinoberson.ch"
checker+=('push')
;;
-n|--dry-run)
evtdry="--dry-run"
;;
--delete)
del="--delete"
;;
-C|--custom-arg)
custom_arg="$2"
shift
;;
*)
unknown=$1
{ echo "Unknown option:\"$unknown\". Too dangerous. Aboarding..."; exit 1; } # unknown option
;;
esac
shift
done
if [[ ${#checker[@]} == 2 ]] ; then
{ echo "Usage of --pull and --push together is not permitted"; exit 1; }
fi
if [[ "${checker[0]}" = "pull" ]] ; then
sourcefolder="test.valentinoberson.ch/"
dest="/home/walo/code_the_web/wp/test.valentinoberson.ch"
rsync -avz $evtdry --rsh=ssh [email protected]:/$sourcefolder $dest $del
else
dest="test.valentinoberson.ch"
sourcefolder="/home/walo/code_the_web/wp/test.valentinoberson.ch/"
if [[ "$del" = "--delete" ]] ; then
read -p "Deleting on a push rsync can broke the entire site. Are you sure? (Y/n) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Y]$ ]] ; then
rsync -avz $evtdry $sourcefolder [email protected]:/$dest $del
else
echo "Aborded"
fi
else
rsync -avz $evtdry --rsh=ssh $sourcefolder [email protected]:/$dest
fi
fi
echo "checker: ${checker[@]}"
echo ${checker[@]}