-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·279 lines (245 loc) · 9.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash
#
# 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.
#
# Helper variables
cxdev_bashrc="${HOME}/.bashrc"
cxdev_zshrc="${ZDOTDIR:-${HOME}}/.zshrc"
# Global variables
export CXDEV_DOWNLOAD_URL="https://github.com/sapcxtools/environment/archive/refs/tags/"
export CXDEV_VERSION="1.0.1"
export CXDEV_HASH="b7c94cb2d1eded98fbea2672397207ce"
export CXDEV_INSTALL_DIR="$HOME/.cxdev"
_installCXDEVEnvironment () {
echo " ___ _ _ ____ ____ _ _ "
echo " / __)( \\/ )( \\( __)/ )( \\"
echo "( (__ ) ( ) D ( ) _) \\ \\/ /"
echo " \\___)(_/\\_)(____/(____) \\__/ "
echo " .__ __ ";
echo " ____ _______ _|__|______ ____ ____ _____ ____ _____/ |_ ";
echo "_/ __ \\ / \\ \\/ / \\_ __ \\/ _ \\ / \\ / \\_/ __ \\ / \\ __\\";
echo "\\ ___/| | \\ /| || | \\( <_> ) | \\ Y Y \\ ___/| | \\ | ";
echo " \\___ >___| /\\_/ |__||__| \\____/|___| /__|_| /\\___ >___| /__| ";
echo " \\/ \\/ \\/ \\/ \\/ \\/ ";
echo ""
echo "Welcome to CXDEV environment installer, v${CXDEV_VERSION}"
echo ""
# Check if already installed
if [ -f "$CXDEV_INSTALL_DIR/.version" ]; then
installedVersion=$(cat $CXDEV_INSTALL_DIR/.version)
echo "You already have CXDEV environment installed."
echo "- Path : ${CXDEV_INSTALL_DIR}"
echo "- Version: ${installedVersion}"
echo ""
if [[ "$installedVersion" == "$CXDEV_VERSION" ]]; then
echo "This version is already installed."
exit 0
else
echo -n >&2 "Do you want us to update your CXDEV environment with version ${CXDEV_VERSION}? [y/N] "
read runUpdate
if [[ "Y" != "$runUpdate" && "y" != "$runUpdate" ]]; then
echo "Installer aborted."
exit 1
else
find ${CXDEV_INSTALL_DIR} -type f -not \( -name "dependencies" -prune \) -exec rm -rf {} \;
fi
fi
fi
# Sanity checks
echo "Checking the following dependencies for CXDEV environment:"
declare -i unresolved_dependencies=0
if type md5sum 2>&1 > /dev/null ; then
echo "- md5sum found!"
else
unresolved_dependencies+=1
echo "- md5sum not found!"
fi
if type unzip 2>&1 > /dev/null ; then
echo "- unzip found!"
else
unresolved_dependencies+=1
echo "- unzip not found!"
fi
if type curl 2>&1 > /dev/null ; then
echo "- curl found!"
else
unresolved_dependencies+=1
echo "- curl not found!"
fi
if type sed 2>&1 > /dev/null ; then
echo "- sed found!"
else
unresolved_dependencies+=1
echo "- sed not found!"
fi
if [ ! -z "$SDKMAN_DIR" ] ; then
echo "- SDKman found!"
else
echo "- SDKman not found!"
echo -n >&2 " Do you want us to install SDKman for you? [Y/n] "
read installSDKman
if [[ "n" == "$installSDKman" || "N" == "$installSDKman" ]]; then
echo " SDKman installation skipped!"
unresolved_dependencies+=1
elif ! _installSDKman ; then
unresolved_dependencies+=1
fi
fi
if type nodenv 2>&1 > /dev/null ; then
echo "- nodenv found!"
else
echo "- nodenv not found!"
echo -n >&2 " Do you want us to install nodenv for you? [Y/n] "
read installNodenv
if [[ "n" == "$installNodenv" || "N" == "$installNodenv" ]]; then
echo " nodenv installation skipped!"
unresolved_dependencies+=1
elif ! _installNodEnv; then
unresolved_dependencies+=1
fi
fi
if [ "$unresolved_dependencies" != "0" ]; then
echo "$unresolved_dependencies unresolved dependencies."
echo "Please install all dependencies on your system using your favourite package manager and then restart the installer."
exit
fi
echo ""
echo "Attempt to install CXDEV environment"
echo "- version : ${CXDEV_VERSION}"
echo "- location: ${CXDEV_INSTALL_DIR}"
echo ""
# Create structure
mkdir -p $CXDEV_INSTALL_DIR
mkdir -p $CXDEV_INSTALL_DIR/tmp
# Download
echo "Fetch CXDEV environment from: ${CXDEV_DOWNLOAD_URL}${CXDEV_VERSION}.zip"
cxdev_zip_file="${CXDEV_INSTALL_DIR}/tmp/cxdev-${CXDEV_VERSION}.zip"
curl --fail --location -o "$cxdev_zip_file" "${CXDEV_DOWNLOAD_URL}${CXDEV_VERSION}.zip"
# check integrity
ARCHIVE_OK=$(unzip -qt "$cxdev_zip_file" | grep 'No errors detected in compressed data')
ARCHIVE_INTEGRITY=($(md5sum "$cxdev_zip_file"))
if [[ -z "$ARCHIVE_OK" || "$ARCHIVE_INTEGRITY" != "$CXDEV_HASH" ]]; then
echo "Downloaded ZIP archive is corrupt."
echo "- Are you connected to the internet?"
echo "- Are you using a proxy server?"
echo "- Is the downloaded file valid?"
exit 1
fi
# extract archive
echo "Extract successfully downloaded ZIP archive."
unzip -qo "$cxdev_zip_file" -d "$CXDEV_INSTALL_DIR/tmp"
# copy over files
echo "Copy files to installation location."
cp -r "$CXDEV_INSTALL_DIR/tmp/environment-$CXDEV_VERSION/." "$CXDEV_INSTALL_DIR"
# store version
echo "$CXDEV_VERSION" > "$CXDEV_INSTALL_DIR/.version"
# clean up
echo "Cleaning up temporary files."
rm -rf "$CXDEV_INSTALL_DIR/tmp"
# link in profile
cxdev_init_snippet=$(cat <<-END
# CXDEV Environment
source "$CXDEV_INSTALL_DIR/cxdev.sh"
#export CXDEVSYNCDIR="/mnt/sapartefacts"
END
)
if [ -w $cxdev_zshrc ] && ! grep -q "cxdev.sh" "$cxdev_zshrc"; then
echo "Adding cxdev initialization snippet to: $cxdev_zshrc"
echo -e "\n$cxdev_init_snippet" >> "$cxdev_zshrc"
fi
if [ -w $cxdev_bashrc ] && ! grep -q "cxdev.sh" "$cxdev_bashrc"; then
echo "Adding cxdev initialization snippet to: $cxdev_bashrc"
echo -e "\n$cxdev_init_snippet" >> "$cxdev_bashrc"
fi
echo ""
echo "CXDEV environment setup is done!"
echo ""
echo "Now, you may want to set your CXDEVSYNCDIR in your terminal configuration file (.bashrc or .zshrc) to point to a shared folder (eg. OneDrive)."
echo ""
echo "Afterwards, please open a new terminal, or run the following in the existing one:"
echo ""
echo " source \"${CXDEV_INSTALL_DIR}/cxdev.sh\""
echo ""
echo "Thank you for using CXDEV environment :)"
echo ""
}
_installSDKman () {
echo "==============================================================================="
echo "Trying to install SDKman using installer script"
echo "Executing: curl -s \"https://get.sdkman.io\" | bash"
echo ""
curl -s "https://get.sdkman.io" | bash > >( _indentInstallerOutput )
sdkmanInstallResultCode=$?
if [[ "$sdkmanInstallResultCode" == "0" ]]; then
echo ""
echo "Installation of SDKman was successful."
# link in profile
sdkman_init_snippet=$(cat <<-END
# Initialize SDKMAN
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
END
)
if [ -w $cxdev_zshrc ] && ! grep -q "SDKMAN_DIR" "$cxdev_zshrc"; then
echo "Adding SDKman initialization snippet to: $cxdev_zshrc"
echo -e "\n$sdkman_init_snippet" >> "$cxdev_zshrc"
fi
if [ -w $cxdev_bashrc ] && ! grep -q "SDKMAN_DIR" "$cxdev_bashrc"; then
echo "Adding SDKman initialization snippet to: $cxdev_bashrc"
echo -e "\n$sdkman_init_snippet" >> "$cxdev_bashrc"
fi
echo "==============================================================================="
return 0
else
echo ""
echo "Installation of SDKman not successful (Status: $sdkmanInstallResultCode)."
echo "==============================================================================="
return 1
fi
}
_installNodEnv () {
echo "==============================================================================="
echo "Trying to install nodenv using installer script"
echo "Executing: curl -fsSL \"https://github.com/nodenv/nodenv-installer/raw/HEAD/bin/nodenv-installer\" | bash"
echo ""
curl -fsSL "https://github.com/nodenv/nodenv-installer/raw/HEAD/bin/nodenv-installer" | bash > >( _indentInstallerOutput )
nodenvInstallResultCode=$?
if [[ "$nodenvInstallResultCode" == "0" ]]; then
echo ""
echo "Installation of nodenv was successful."
# link in profile
if [ -w $cxdev_zshrc ] && ! grep -q "nodenv init" "$cxdev_zshrc"; then
echo "Adding nodenv initialization snippet to: $cxdev_zshrc"
echo -e "\n# Initialize NODENV" >> "$cxdev_zshrc"
echo "export PATH=\"${ZDOTDIR:-${HOME}}/.nodenv/bin:$PATH\"" >> "$cxdev_zshrc"
echo 'eval "$(nodenv init - zsh)"' >> "$cxdev_zshrc"
fi
if [ -w $cxdev_bashrc ] && ! grep -q "nodenv init" "$cxdev_bashrc"; then
echo "Adding nodenv initialization snippet to: $cxdev_bashrc"
echo -e "\n# Initialize NODENV" >> "$cxdev_bashrc"
echo "export PATH=\"${ZDOTDIR:-${HOME}}/.nodenv/bin:$PATH\"" >> "$cxdev_bashrc"
echo 'eval "$(nodenv init - bash)"' >> "$cxdev_bashrc"
fi
echo "==============================================================================="
return 0
else
echo ""
echo "Installation of nodenv not successful (Status: $nodenvInstallResultCode)."
echo "==============================================================================="
return 1
fi
}
_indentInstallerOutput () {
sed 's/^/[INSTALLER] /'
}
_installCXDEVEnvironment