-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_sandbox.sh
executable file
·99 lines (86 loc) · 2.4 KB
/
sync_sandbox.sh
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
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
set -x
set -e
# watcher script to replace `vagrant rsync-auto`, which is terribly slow and
# unreliable, cause it frequently hangs in 100% cpu loops
#
# see http://unix.stackexchange.com/a/163816 for the bash-magic included
here="$(pwd)/$(dirname $0)"
# connection to the local dev box
SSH_PORT=2226
SSH_CMD="ssh -p ${SSH_PORT} \
-o User=vagrant \
-o IdentityFile=~/.vagrant.d/insecure_private_key \
-o IdentitiesOnly=yes \
-o ForwardAgent=no \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null"
# definition of sources to sync and appropriate destination dirs in the dev box
SRC_1 = "${here}/../foo/"
DEST_1 = "/srv/foo/"
SRC_2 = "${here}/../bar/"
DEST_2 = "/srv/bar/"
cd "${SRC_1}" && watchexec \
--ignore .git \
--ignore .idea \
--ignore app/cache \
--ignore app/logs \
--ignore vendor \
--ignore uploads \
--exts php,yml,sass,js,css,html,twig \
"time rsync -av \
-e \"${SSH_CMD}\" \
\"${SRC_1}\"/ \
127.0.0.1:${DEST_1} \
--inplace \
--delete \
--omit-dir-times \
--exclude=app/cache \
--exclude=app/logs \
--exclude=app/bootstrap.php.cache \
--exclude=app/config/parameters.yml \
--exclude=tools \
--exclude=vendor \
--exclude=uploads \
--exclude=node_modules \
--exclude=.DS_Store \
--exclude=.idea \
--exclude=.git \
"&
# Storing the background process' PID.
SRC_1_sync_pid=$!
# Trapping SIGINTs so we can send them back to $xx_pid.
trap "kill -2 ${SRC_1_sync_pid}" 2
cd "${SRC_2}" && watchexec \
--ignore .git \
--ignore .idea \
--ignore app/cache \
--ignore app/logs \
--ignore vendor \
--ignore uploads \
--exts php,yml,sass,js,css,html,twig \
"time rsync -av \
-e \"${SSH_CMD}\" \
\"${SRC_2}\"/ \
127.0.0.1:${DEST_2} \
--inplace \
--delete \
--omit-dir-times \
--exclude=app/cache \
--exclude=app/logs \
--exclude=app/bootstrap.php.cache \
--exclude=app/config/parameters.yml \
--exclude=tools \
--exclude=vendor \
--exclude=uploads \
--exclude=node_modules \
--exclude=.DS_Store \
--exclude=.idea \
--exclude=.git \
"&
# Storing the background process' PID.
SRC_2_sync_pid=$!
# Trapping SIGINTs so we can send them back to $xx_pid.
trap "kill -2 ${SRC_2_sync_pid}" 2
# In the meantime, wait for $xx_pid to end.
wait ${SRC_1_sync_pid} ${SRC_2_sync_pid}