-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
132 lines (115 loc) · 3.14 KB
/
install.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
info() {
echo INFO: $*
}
bullet() {
echo "INFO: -" "$@"
}
has_curl() {
hash curl 2>/dev/null
}
has_docker() {
if hash docker 2>/dev/null; then
local version=$(docker -v | sed 's/^Docker version \([^,]*\),.*/\1/')
local versionMax=$(printf "$version\n1.9.1" | sort -V | tail -1)
if [ "$versionMax" = "1.9.1" ]; then
bullet "docker v1.10+ (missing - $version is too old)"
return 1
else
bullet "docker v1.10+ (found)"
return 0
fi
else
bullet "docker v1.10+ (missing)"
return 1
fi
}
has_docker_compose() {
if hash docker-compose 2>/dev/null; then
# this comparison should keep working for a while
local version=$(docker-compose -v | sed 's/^docker-compose version \([^,]*\),.*/\1/')
local versionMax=$(printf "$version\n1.5.2" | sort -V | tail -1)
if [ "$versionMax" = "1.5.2" ]; then
bullet "docker-compose v1.6+ (missing - $version is too old)"
return 1
else
bullet "docker-compose v1.6+ (found)"
return 0
fi
else
bullet "docker-compose v1.6+ (missing)"
return 1
fi
}
has_docker_group() {
groups $user | grep &>/dev/null '\bdocker\b'
}
install_curl() {
info Installing curl...
sudo apt-get update
sudo apt-get install -y curl
}
install_docker() {
info "It's coffee time 'cause this will take a while"
curl -sSL https://get.docker.com | sudo sh
}
install_docker_compose() {
bullet "installing docker-compose"
local release=$(curl -fL https://api.github.com/repos/docker/compose/releases/latest -H 'accept: application/json' 2> /dev/null)
if [ $? -ne 0 ]; then
bullet "docker-compose install failed: unable to query for latest available version"
return 1
fi
local latest=$(echo "$release" | grep tag_name | sed -e 's/.*"tag_name":[^"]*"\([^"]*\)".*/\1/')
if [ "$latest" == "" ]; then
bullet "docker-compose install failed: unable to determine latest available version"
return 1
fi
curl -L https://github.com/docker/compose/releases/download/$latest/docker-compose-`uname -s`-`uname -m` > /tmp/docker-compose 2> /dev/null
sudo mv /tmp/docker-compose /usr/local/bin/
sudo chmod +x /usr/local/bin/docker-compose
}
install_docker_group() {
info "Granting $user access to run docker commands without sudo. You'll need to re-login for changes to take affect."
sudo usermod -a -G docker $user
}
tt_install() {
local user=${SUDO_USER:-$USER}
local queue=""
info "checking dependencies:"
if has_curl; then
bullet "curl (found)"
else
bullet "curl (missing)"
queue="curl"
fi
if ! has_docker; then
queue="$queue docker"
fi
if ! has_docker_compose; then
queue="$queue docker_compose"
fi
if has_docker_group; then
bullet "user is part of 'docker' group (found)"
else
bullet "user is part of 'docker' group (missing)"
queue="$queue docker_group"
fi
if [ ! -z "$queue" ]; then
echo
# skip the read (effectively saying "yes") if in a CI environment
if [ "$CI" != "true" ]; then
read -n 1 -p "Install missing dependencies? (Y/n)" CONFIRM
fi
if [ "$CONFIRM" == "n" -o "$CONFIRM" == "N" ]; then
echo
info "You chose not to install required dependencies, there be dragons."
else
echo
for dep in $queue; do
echo
"install_$dep"
done
fi
fi
}