-
Notifications
You must be signed in to change notification settings - Fork 2
/
provision.sh
116 lines (88 loc) · 2.6 KB
/
provision.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
set -x -e;
DOCKER_MACHINE=${DOCKER_MACHINE_NAME:-default}
INSTALLATION_FOLDER=$(pwd)
loadConfig() {
CONGFIGS="$(sed -e 's/:[^:\/\/]/="/g;s/$/"/g;s/ *=/=/g' config.conf)"
eval $(sed -e 's/:[^:\/\/]/="/g;s/$/"/g;s/ *=/=/g' config.conf)
}
selectDockerMachine() {
export DOCKER_MACHINE_IP="$(docker-machine ip $DOCKER_MACHINE)"
}
executeCommand() {
docker-machine ssh $1 $2
}
removeVirtualboxSharedFolders () {
echo "($1) Checking whether /c/Users (vboxsf) is mounted ...";
if [[ $(executeCommand $1 mount | grep c/Users) ]]; then
echo "($1) Removing /c/Users"
executeCommand $1 "sudo umount //c/Users"
fi
}
createDirectory () {
echo "($1) Creating $2 ..."
local command="
[ -d $2 ] || {
sudo mkdir -p $2;
sudo chown docker $2;
}
"
executeCommand $1 "$command"
}
checkAndInstallUnison () {
echo "($1) Checking whether unison is installed ..."
if [[ $(executeCommand $1 "unison -version" | grep "unison version 2.48.3") ]]; then
echo "($1) unison 2.48.3 found."
else
echo "($1) Installing unison ..."
executeCommand $1 "cd // &&
sudo curl -sL https://www.archlinux.org/packages/extra/x86_64/unison/download | sudo tar Jx;"
fi
}
setUpUnison() {
echo "Setting up unison ..."
# create ssh-config file
ssh_config="
Host $DOCKER_MACHINE_IP
User docker
IdentityFile ~/.docker/machine/machines/$DOCKER_MACHINE/id_rsa
"
[ -d .docker-unison ] || mkdir .docker-unison
ssh_config_file="$(pwd)/.docker-unison/ssh-config"
[ -f $ssh_config_file ] || echo "$ssh_config" > $ssh_config_file
if [ -z ${USERPROFILE+x} ]; then
UNISONDIR=$HOME
else
UNISONDIR=$USERPROFILE
fi
cd $UNISONDIR
[ -d .unison ] || mkdir .unison
if [ ! -f ".unison/$UNISON_PROFILE_NAME.prf" ]; then
echo "Creating unison profile ..."
if [ -z ${UNISON_FASTCHECK+x} ]; then
UNISON_FASTCHECK='false' # Fastcheck is disabled by default
fi
profile="
root = $HOST_FOLDER
root = ssh://$DOCKER_MACHINE_IP/$GUEST_FOLDER
ignore = Name $IGNORE
follow = Regex .*
prefer = $HOST_FOLDER
repeat = 2
terse = true
dontchmod = true
perms = 0
fastcheck = $UNISON_FASTCHECK
sshargs = -F $ssh_config_file
"
echo "$profile" > ".unison/$UNISON_PROFILE_NAME.prf"
fi
echo "Done!"
}
loadConfig
selectDockerMachine
removeVirtualboxSharedFolders $DOCKER_MACHINE
createDirectory $DOCKER_MACHINE $GUEST_FOLDER
checkAndInstallUnison $DOCKER_MACHINE
setUpUnison
"$INSTALLATION_FOLDER/bin/unison" $UNISON_PROFILE_NAME