-
-
Notifications
You must be signed in to change notification settings - Fork 628
/
install.sh
executable file
·251 lines (221 loc) · 8.18 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/bash
#
# Copyright 2012 Marco Vermeulen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Global variables
GVM_SERVICE="@GVM_SERVICE@"
GVM_VERSION="@GVM_VERSION@"
GVM_DIR="$HOME/.gvm"
# Local variables
gvm_bin_folder="${GVM_DIR}/bin"
gvm_src_folder="${GVM_DIR}/src"
gvm_tmp_folder="${GVM_DIR}/tmp"
gvm_stage_folder="${gvm_tmp_folder}/stage"
gvm_zip_file="${gvm_tmp_folder}/res-${GVM_VERSION}.zip"
gvm_ext_folder="${GVM_DIR}/ext"
gvm_etc_folder="${GVM_DIR}/etc"
gvm_config_file="${gvm_etc_folder}/config"
gvm_bash_profile="${HOME}/.bash_profile"
gvm_profile="${HOME}/.profile"
gvm_bashrc="${HOME}/.bashrc"
gvm_zshrc="${HOME}/.zshrc"
gvm_platform=$(uname -o)
gvm_init_snippet=$( cat << EOF
#THIS MUST BE AT THE END OF THE FILE FOR GVM TO WORK!!!
[[ -s "${GVM_DIR}/bin/gvm-init.sh" && -z \$(which gvm-init.sh | grep '/gvm-init.sh') ]] && source "${GVM_DIR}/bin/gvm-init.sh"
EOF
)
# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
case "`uname`" in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
esac
echo ' '
echo 'Thanks for using '
echo ' '
echo '_____/\\\\\\\\\\\\__/\\\________/\\\__/\\\\____________/\\\\_ '
echo ' ___/\\\//////////__\/\\\_______\/\\\_\/\\\\\\________/\\\\\\_ '
echo ' __/\\\_____________\//\\\______/\\\__\/\\\//\\\____/\\\//\\\_ '
echo ' _\/\\\____/\\\\\\\__\//\\\____/\\\___\/\\\\///\\\/\\\/_\/\\\_ '
echo ' _\/\\\___\/////\\\___\//\\\__/\\\____\/\\\__\///\\\/___\/\\\_ '
echo ' _\/\\\_______\/\\\____\//\\\/\\\_____\/\\\____\///_____\/\\\_ '
echo ' _\/\\\_______\/\\\_____\//\\\\\______\/\\\_____________\/\\\_ '
echo ' _\//\\\\\\\\\\\\/_______\//\\\_______\/\\\_____________\/\\\_ '
echo ' __\////////////__________\///________\///______________\///__'
echo ' '
echo ' Will now attempt installing...'
echo ' '
# Sanity checks
echo "Looking for a previous installation of GVM..."
if [ -d "${GVM_DIR}" ]; then
echo "GVM found."
echo ""
echo "======================================================================================================"
echo " You already have GVM installed."
echo " GVM was found at:"
echo ""
echo " ${GVM_DIR}"
echo ""
echo " Please consider running the following if you need to upgrade."
echo ""
echo " $ gvm selfupdate"
echo ""
echo "======================================================================================================"
echo ""
exit 0
fi
echo "Looking for JAVA_HOME..."
if [ -z "${JAVA_HOME}" ]; then
echo "Not found."
echo ""
echo "======================================================================================================"
echo " Please ensure that you have a Java SDK installed and that JAVA_HOME environment variable is set."
echo " accordingly."
echo ""
echo " Java can be found here:"
echo " http://www.oracle.com/technetwork/java/javase/downloads/index.html"
echo ""
echo " Set JAVA_HOME by editing your ~/.profile file and adding:"
echo " export JAVA_HOME=\"/path/to/my/jdk\""
echo "======================================================================================================"
echo ""
exit 0
fi
echo "Validating JAVA_HOME..."
if [ ! -f "${JAVA_HOME}/bin/java" ]; then
echo "Invalid."
echo ""
echo "======================================================================================================"
echo " Please ensure that your JAVA_HOME points to a valid Java SDK."
echo " You are currently pointing to:"
echo ""
echo " ${JAVA_HOME}"
echo ""
echo " This does not seem to be valid. Please rectify and restart."
echo "======================================================================================================"
echo ""
exit 0
fi
echo "Looking for unzip..."
if [ -z $(which unzip) ]; then
echo "Not found."
echo "======================================================================================================"
echo " Please install unzip on your system using your favourite package manager."
echo ""
echo " Restart after installing unzip."
echo "======================================================================================================"
echo ""
exit 0
fi
echo "Looking for curl..."
if [ -z $(which curl) ]; then
echo "Not found."
echo ""
echo "======================================================================================================"
echo " Please install curl on your system using your favourite package manager."
echo ""
echo " GVM uses curl for crucial interactions with it's backend server."
echo ""
echo " Restart after installing curl."
echo "======================================================================================================"
echo ""
exit 0
fi
echo "Installing gvm scripts..."
# Create directory structure
echo "Create distribution directories..."
mkdir -p "${gvm_bin_folder}"
mkdir -p "${gvm_src_folder}"
mkdir -p "${gvm_tmp_folder}"
mkdir -p "${gvm_stage_folder}"
mkdir -p "${gvm_ext_folder}"
mkdir -p "${gvm_etc_folder}"
echo "Create candidate directories..."
mkdir -p "${GVM_DIR}/groovy"
mkdir -p "${GVM_DIR}/grails"
mkdir -p "${GVM_DIR}/griffon"
mkdir -p "${GVM_DIR}/gradle"
mkdir -p "${GVM_DIR}/vertx"
echo "Prime the config file..."
touch "${gvm_config_file}"
echo "Download script archive..."
curl -s "${GVM_SERVICE}/res?platform=${gvm_platform}&purpose=install" > "${gvm_zip_file}"
echo "Extract script archive..."
if [[ "${cygwin}" == 'true' ]]; then
echo "Cygwin detected - normalizing paths for unzip..."
unzip -qo $(cygpath -w "${gvm_zip_file}") -d $(cygpath -w "${gvm_stage_folder}")
else
unzip -qo "${gvm_zip_file}" -d "${gvm_stage_folder}"
fi
echo "Install scripts..."
mv "${gvm_stage_folder}/gvm-init.sh" "${gvm_bin_folder}"
mv "${gvm_stage_folder}"/gvm-* "${gvm_src_folder}"
echo "Make init script executable..."
chmod +x "${gvm_bin_folder}/gvm-init.sh"
echo "Attempt update of bash profiles..."
if [ ! -f "${gvm_bash_profile}" -a ! -f "${gvm_profile}" ]; then
echo "#!/bin/bash" > "${gvm_bash_profile}"
echo "${gvm_init_snippet}" >> "${gvm_bash_profile}"
echo "Created and initialised ${gvm_bash_profile}"
else
if [ -f "${gvm_bash_profile}" ]; then
if [[ -z `grep 'gvm-init.sh' "${gvm_bash_profile}"` ]]; then
echo -e "\n${gvm_init_snippet}" >> "${gvm_bash_profile}"
echo "Updated existing ${gvm_bash_profile}"
fi
fi
if [ -f "${gvm_profile}" ]; then
if [[ -z `grep 'gvm-init.sh' "${gvm_profile}"` ]]; then
echo -e "\n${gvm_init_snippet}" >> "${gvm_profile}"
echo "Updated existing ${gvm_profile}"
fi
fi
fi
if [ ! -f "${gvm_bashrc}" ]; then
echo "#!/bin/bash" > "${gvm_bashrc}"
echo "${gvm_init_snippet}" >> "${gvm_bashrc}"
echo "Created and initialised ${gvm_bashrc}"
else
if [[ -z `grep 'gvm-init.sh' "${gvm_bashrc}"` ]]; then
echo -e "\n${gvm_init_snippet}" >> "${gvm_bashrc}"
echo "Updated existing ${gvm_bashrc}"
fi
fi
echo "Attempt update of zsh profiles..."
if [ ! -f "${gvm_zshrc}" ]; then
echo "${gvm_init_snippet}" >> "${gvm_zshrc}"
echo "Created and initialised ${gvm_zshrc}"
else
if [[ -z `grep 'gvm-init.sh' "${gvm_zshrc}"` ]]; then
echo -e "\n${gvm_init_snippet}" >> "${gvm_zshrc}"
echo "Updated existing ${gvm_zshrc}"
fi
fi
echo -e "\n\n\nAll done!\n\n"
echo "Please open a new terminal, or run the following in the existing one:"
echo ""
echo " source \"${GVM_DIR}/bin/gvm-init.sh\""
echo ""
echo "Then issue the following command:"
echo ""
echo " gvm help"
echo ""
echo "Enjoy!!!"