-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·205 lines (165 loc) · 5.84 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
#!/bin/bash
### CONFIGURATIONS
### SCRIPT BODY
success_echo() {
echo -e "\033[1;32m$1\033[0m"
}
warning_echo() {
echo -e "\033[1;33m$1\033[0m"
}
info_echo() {
echo -e "\033[1;34m$1\033[0m"
}
confirm_prompt() {
read -p "${1} (y/n) " -n 1 -r
echo
[[ $REPLY =~ ^[Yy]$ ]]
}
# Get metaenv home dir (where this script is located)
METAENV_SRC_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/src"
# $1 default path
# $2 prompt
# $3 has to be writable
install_path=""
get_install_folder() {
while true; do
install_path="${1}"
read -p "${2} (${1}): " user_path
if [[ ! -z ${user_path} ]]; then
install_path=${user_path}
fi
if [[ -w ${install_path} ]] || [[ $3 -eq 0 ]]; then
break
else
echo "Directory \"${install_path}\" does not exist or it is not writable! Restarting..."
fi
done
}
# Get installation folder (idealy user's home directory)
# Sets install_path global variable!
INSTALL_PATH=${HOME}
get_install_folder "${INSTALL_PATH}" "In which home directory do you want to install scripts?:" 1
if [[ $? -ne 0 ]]; then
exit 1
fi
metaenv_install_path="${install_path}"
# Install Metacentrum recommendations scripts!
# Copy all ".bash*" files from `METAENV_SRC_DIR/src/meta_ref` to install_path (promt user if file already exists)
echo
info_echo "Installing Metacentrum recommendations scripts..."
warning_echo "Please note that this will overwrite your existing \`~/.bash*\` files! Skip this step of backup your files first!"
meta_ref_dir="${METAENV_SRC_DIR}/meta_ref"
for file in ${meta_ref_dir}/.bash*; do
target_file="${install_path}/$(basename ${file})"
if [[ -f ${target_file} ]]; then
confirm_prompt "File \`${target_file}\` already exists. Do you want to rewrite it?"
if [[ $? -ne 0 ]]; then
echo "Skipping file \"$(basename ${file})\"..."
continue
fi
fi
cp ${file} ${target_file}
done
success_echo "OK!"
# Install Metaenv user configuration script
echo
info_echo "Installing Metaenv user configuration file..."
USER_CONFIG_FILE=".metaenv_user_conf"
target_config_file="${install_path}/${USER_CONFIG_FILE}"
if [[ -f ${target_config_file} ]]; then
confirm_prompt "File \`${target_config_file} already exists. Are you really sure you want to rewrite it?!"
if [[ $? -ne 0 ]]; then
echo "Skipping user configuration file..."
target_config_file=""
fi
fi
if [[ ! -z ${target_config_file} ]]; then
cp "${METAENV_SRC_DIR}/${USER_CONFIG_FILE}" "${target_config_file}"
fi
# write `target_config_file` back either way so it can be used in other part of the script
target_config_file="${install_path}/${USER_CONFIG_FILE}"
success_echo "OK!"
# Add block to user's .bashrc file (source scripts from `INSTALL_SCRIPTS` array)
# Rewrite exising source block if exists (decorate using `# metaenv` comment)
INSTALL_SCRIPTS=(
"metaenv.sh"
"env_vars.sh"
"aliases.sh"
"modules.sh"
"containers.sh"
"jobs.sh"
)
BASHRC_FILE="${install_path}/.bashrc"
SOURCE_BLOCK_DELIMITER="# metaenv stuff"
echo
info_echo "Adding metaenv sources to your \`${BASHRC_FILE}\`..."
# create source block
source_block="${SOURCE_BLOCK_DELIMITER} \n"
for script in ${INSTALL_SCRIPTS[@]}; do
source_block="${source_block}source ${METAENV_SRC_DIR}/${script}\n"
done
source_block="${source_block}${SOURCE_BLOCK_DELIMITER}"
# add source block to user's `.bashrc` file
if grep -q "${SOURCE_BLOCK_DELIMITER}" ${BASHRC_FILE}; then
sed -i "/${SOURCE_BLOCK_DELIMITER}/,/${SOURCE_BLOCK_DELIMITER}/d" ${BASHRC_FILE}
fi
echo -e "\n${source_block}" >> ${BASHRC_FILE}
success_echo "OK!"
# Install custom 3rd party software
echo
info_echo "Installing custom 3rd party software..."
# Install VS Code CLI
VSCODE_INSTALL_PATH="tools/code-cli"
confirm_prompt "Do you want to install VS Code CLI?"
if [[ $? -eq 0 ]]; then
echo "Installing VS Code CLI..."
# Get install folder for VS Code CLI
# function sets global variable install_path
get_install_folder "${metaenv_install_path}/${VSCODE_INSTALL_PATH}" "In which directory do you want to VS Code CLI?" 0
if [[ $? -ne 0 ]]; then
exit 1
fi
mkdir -p "${install_path}"
if [[ $? -ne 0 ]]; then
echo_error "Error while creating ${install_path} folder..."
exit 1
fi
cd "${install_path}"
curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz &> /dev/null
tar -xf vscode_cli.tar.gz
rm -f vscode_cli.tar.gz
vscode_path="${install_path}/code"
if [[ ! -x "${vscode_path}" ]]; then
echo_error "VS Code CLI was not successful... check https://code.visualstudio.com/docs/remote/tunnels for more details."
exit 1
fi
# Add install_path to PATH array
sed -i "/^EXTRA_PATH_DIRS=(.*/a \ \ \ \ \"${install_path}\" # vscode-cli installation folder" "${target_config_file}"
fi
# Install Conda
MINICONDA_INSTALL_PATH="tools/miniconda"
echo
info_echo "Installing Miniconda..."
confirm_prompt "Do you want to install Miniconda?"
if [[ $? -eq 0 ]]; then
echo "installing Miniconda..."
# Get install folder for Miniconda
# function sets global variable install_path
get_install_folder "${metaenv_install_path}/${MINICONDA_INSTALL_PATH}" "In which directory do you want to install Miniconda?" 0
if [[ $? -ne 0 ]]; then
exit 1
fi
mkdir -p "${install_path}"
if [[ $? -ne 0 ]]; then
echo_error "Error while creating ${install_path} folder..."
exit 1
fi
cd "${install_path}"
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
bash miniconda.sh -b -u -p "${install_path}"
rm -f miniconda.sh
# initialize conda
"${install_path}/bin/conda" init bash
fi
echo
success_echo "Installation completed! Have a nice day!"