-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdosxer_sync_setup
executable file
·105 lines (94 loc) · 3.26 KB
/
dosxer_sync_setup
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
100
101
102
103
104
105
#!/usr/bin/env bash
script_dir="$( dirname "${BASH_SOURCE[0]}" )"
brew_check=0
function check_for_brew {
if [[ ${brew_check} -eq 1 ]]; then
return
fi
echo -ne " Checking Homebrew\r"
command -v brew >/dev/null 2>&1 || {
echo -e "\x1b[0;31m✝ \x1b[0mChecking Homebrew"
echo >&2 "Homebrew is not installed. Please install."
exit 1
}
brew_check=1
echo -e "\x1b[0;32m✓ \x1b[0mChecking Homebrew"
}
function install_brew_prerequisites {
local cmd=$1
command -v ${cmd} >/dev/null 2>&1 || {
check_for_brew
echo -ne " Installing ${cmd}\r"
brew install ${cmd} >/dev/null 2>&1
echo -e "\x1b[0;32m✓ \x1b[0mInstalling ${cmd}"
}
}
function install_pip_prerequisites {
local package=$1
pip show ${package} >/dev/null 2>&1
if [[ $? -eq 1 ]]; then
echo -ne " Installing ${package}\r"
pip install ${package} >/dev/null 2>&1
echo -e "\x1b[0;32m✓ \x1b[0mInstalling ${package}"
fi
}
function install_unox_prerequisites {
local cmd_name="unison-fsmonitor"
local cmd="/usr/local/bin/unison-fsmonitor"
if [[ ! -f ${cmd} ]]; then
echo -ne " Installing ${cmd_name}\r"
# TODO Check hash to avoid security issues.
curl -o ${cmd} -L https://raw.githubusercontent.com/hnsl/unox/master/unox.py >/dev/null 2>&1
chmod +x ${cmd} >/dev/null 2>&1
echo -e "\x1b[0;32m✓ \x1b[0mInstalling ${cmd_name}"
fi
}
function install_to_path {
while true; do
read -p "Do you wish to install dosxer_sync to /usr/local/bin? (y/N) " yn
case ${yn} in
[Yy]* ) ln -nfs `pwd`/dosxer_sync /usr/local/bin/dosxer_sync; break;;
[Nn]* ) exit;;
* ) exit;;
esac
done
}
# Needed for the sync itself
install_brew_prerequisites unison
# Mainly installed to be able to display errors while syncing
install_brew_prerequisites terminal-notifier
# File system watcher components on the host
install_pip_prerequisites MacFSEvents
install_unox_prerequisites
# Install to user accessible path
install_to_path
# Output some data to the user
terminal-notifier -title "Dosxer sync" -activate "com.apple.Terminal" -message "
✓ Setup has finished. Please see terminal output for more.
"
# Detail output when finished with some quickstart infos
echo -e "
\x1b[0;32mAll prerequisites are present or installed successfully.\x1b[0m
Now you can use the Docker sync.
In your 'docker-compose-dev.yml' add something like this:
\x1b[0;33m
app:
volumes_from:
- unison
unison:
container_name: angular_sync_unison
image: onnimonni/unison:latest
environment:
- UNISON_DIR=/var/www/html
- UNISON_UID=501 # Default UID of the OSX user; might be overwritten with an .env file
volumes:
- /var/www/html
ports:
- \"5000\"
\x1b[0m
Then issue the sync command:
\x1b[0;33m
./dosxer_sync
\x1b[0m
For the first time the \x1b[0;33mdocker-compose\x1b[0m command might partially fail b/c there was no initial sync yet. Just start the sync with the \x1b[0;33munison\x1b[0m command and re-issue the \x1b[0;33mdocker-compose\x1b[0m command after the sync was done.
The initial sync might depending on the project size take a while. After that you will have a proper and fast two-way sync."