forked from alankent/magento2devbox-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
m2unison.sh
72 lines (55 loc) · 1.89 KB
/
m2unison.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
#!/bin/bash
# Unison can connect over SSH or via a socket. SSH is used be default as there
# have been some reports of the socket mode hanging at times.
USE_SOCKET=0
PROJ=$COMPOSE_PROJECT_NAME
if [[ -z $PROJ ]]; then
PROJ=$(basename $PWD)
fi
M2PROFILE=m2devbox-$PROJ
mkdir -p ~/.unison
LOCAL_ROOT=$(pwd)/shared/www
if [[ $USE_SOCKET == 1 ]]; then
# Fetch the external Docker Unison port number
SSH_ARGS_LINE=
UNISON_PORT=$(docker-compose port unison 5000 | awk -F: '{print $2}')
REMOTE_ROOT=socket://localhost:$UNISON_PORT//var/www
else
SSH_PORT=$(docker-compose port unison 22 | awk -F: '{print $2}')
echo "Testing 'ssh' connection to container..."
ssh -p $SSH_PORT magento2@localhost echo Connection successful
SSH_ARGS_LINE="sshargs = -p $SSH_PORT"
REMOTE_ROOT=ssh://magento2@localhost//var/www
fi
cat << EOF > ~/.unison/$M2PROFILE.prf
# WARNING: This file is automatically generated. Changes may be over-written.
$SSH_ARGS_LINE
# Local root
root = $LOCAL_ROOT
# Remote root (Docker container)
root = $REMOTE_ROOT
# Magento files not worth pulling locally.
ignore = Path magento2/var/cache
ignore = Path magento2/var/composer_home
ignore = Path magento2/var/log
ignore = Path magento2/var/page_cache
ignore = Path magento2/var/session
ignore = Path magento2/var/tmp
ignore = Path magento2/var/.setup_cronjob_status
ignore = Path magento2/var/.update_cronjob_status
# Magento files not worth pushing remotely.
ignore = Path magento2/.git
ignore = Path magento2/.gitignore
ignore = Path magento2/.gitattributes
ignore = Path magento2/.magento
ignore = Name .idea
ignore = Name .*.swp
ignore = Name .unison.*
prefer = $LOCAL_ROOT
preferpartial = Path var -> $REMOTE_ROOT
auto = true
batch = true
EOF
echo "Unison profile '$M2PROFILE' has been created in '~/.unison'."
echo "Now running 'unison -repeat watch $M2PROFILE' for file syncing mode."
unison -repeat watch $M2PROFILE