-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINSTALL.sh
315 lines (265 loc) · 10.3 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/bin/bash
FORCE_INTERACTIVE=${FORCE_INTERACTIVE:-0}
set -e
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
LIBYAML_MESSAGE_PRINTED=0
# Function to check if libyaml-dev is installed
check_libyaml_dev() {
local print_message=${1:-0}
# Check using dpkg if available (Debian-based systems)
if command_exists dpkg; then
if dpkg -s libyaml-dev >/dev/null 2>&1; then
[ "$print_message" -eq 1 ] && [ "$LIBYAML_MESSAGE_PRINTED" -eq 0 ] && echo "libyaml-dev is installed. (dpkg check)" && LIBYAML_MESSAGE_PRINTED=1
return 0 # libyaml-dev is installed
fi
fi
if [ -f "/usr/include/yaml.h" ]; then
[ "$print_message" -eq 1 ] && [ "$LIBYAML_MESSAGE_PRINTED" -eq 0 ] && echo "libyaml-dev is installed. (yaml.h check)" && LIBYAML_MESSAGE_PRINTED=1
return 0 # File exists, libyaml-dev is likely installed
elif ldconfig -p | grep -q "libyaml"; then
[ "$print_message" -eq 1 ] && [ "$LIBYAML_MESSAGE_PRINTED" -eq 0 ] && echo "libyaml-dev is installed. (ldconfig check)" && LIBYAML_MESSAGE_PRINTED=1
return 0 # libyaml is in the library cache
else
echo "libyaml-dev is not installed."
return 1 # libyaml-dev is likely not installed
fi
}
check_system_dependencies() {
echo "Checking system dependencies..."
local missing_deps=()
# Check for commands
for cmd in git curl wget dpkg tee; do
if ! command_exists "$cmd"; then
missing_deps+=("$cmd")
fi
done
# Check for libyaml-dev
echo "Checking for libyaml-dev..."
if ! check_libyaml_dev 1; then
sudo apt-get -y install libyaml-dev
fi
# Check again after installing libyaml-dev
if ! check_libyaml_dev 1; then
missing_deps+=("libyaml-dev")
fi
if [ ${#missing_deps[@]} -ne 0 ]; then
echo ""
echo "ERROR: The following dependencies are missing: ${missing_deps[*]}"
echo "Please install them using your distribution's package manager."
echo "For example, on Ubuntu or Debian, you can use:"
echo "sudo apt-get update && sudo apt-get install ${missing_deps[*]}"
exit 1
fi
}
# Function to check if Conda (Miniconda or Anaconda) is installed
conda_check() {
if command_exists conda; then
echo "Conda is already installed."
return 0
elif [ -d "$HOME/miniconda3" ]; then
echo "Miniconda is installed but not in PATH. Adding to PATH..."
export PATH="$HOME/miniconda3/bin:$PATH"
return 0
elif [ -d "$HOME/anaconda3" ]; then
echo "Anaconda is installed but not in PATH. Adding to PATH..."
export PATH="$HOME/anaconda3/bin:$PATH"
return 0
else
return 1
fi
}
# Install Miniconda if not already installed
install_miniconda() {
if conda_check; then
echo "Using existing Conda installation."
else
echo "Installing Miniconda..."
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
bash miniconda.sh -b -p $HOME/miniconda3
export PATH="$HOME/miniconda3/bin:$PATH"
fi
# Initialize conda for bash
conda init bash
# Source the bashrc to apply changes immediately
source $HOME/.bashrc
# Ensure conda command is available
eval "$(conda shell.bash hook)"
}
create_conda_env() {
local env_name="moltiverse"
if conda env list | grep -q "^$env_name "; then
if [ -t 0 ] || [ "$FORCE_INTERACTIVE" = "1" ]; then
echo "Conda environment '$env_name' already exists."
echo "Choose an option:"
echo "1) Remove existing environment and create a new one"
echo "2) Use the existing environment"
echo "3) Use a different name for the new environment"
read -p "Enter your choice (1, 2, or 3): " env_choice
case $env_choice in
1)
echo "Removing existing environment..."
conda env remove -n $env_name -y
;;
2)
echo "Using existing environment..."
;;
3)
read -p "Enter a new name for the Conda environment: " new_env_name
env_name=$new_env_name
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
else
echo "Non-interactive mode: Removing existing environment '$env_name'"
conda env remove -n $env_name -y
fi
fi
if ! conda create -n $env_name -y 2> >(tee /tmp/conda_error.log >&2); then
if grep -q "CondaValueError: prefix already exists:" /tmp/conda_error.log; then
echo "Error: Conda environment directory already exists."
prefix_path=$(grep "CondaValueError: prefix already exists:" /tmp/conda_error.log | awk '{print $NF}')
echo "Removing existing directory at $prefix_path"
rm -rf "$prefix_path"
echo "Retrying environment creation..."
conda create -n $env_name -y
else
echo "Error: Failed to create Conda environment. See error log above."
exit 1
fi
fi
if ! conda env list | grep -q "^$env_name "; then
echo "Error: Failed to create/update environment '$env_name'."
exit 1
fi
# Activate the environment
echo "Activating environment '$env_name'..."
eval "$(conda shell.bash hook)"
conda activate $env_name
}
# Install dependencies
install_dependencies() {
echo "Installing dependencies..."
conda install -c conda-forge ambertools=23 openbabel xtb -y
}
# Install Crystal
install_crystal() {
if command_exists crystal; then
current_version=$(crystal --version | grep Crystal | awk '{print $2}')
echo "Crystal version $current_version is already installed."
if [ -t 0 ] || [ "$FORCE_INTERACTIVE" = "1" ]; then
read -p "Do you want to proceed with the installation of Crystal language? (y/n): " proceed
if [[ $proceed != "y" ]]; then
echo "Skipping Crystal installation."
return
fi
else
echo "Non-interactive mode: Proceeding with Crystal language installation."
fi
# Cleanup previous installation
echo "Cleaning up previous Crystal installation..."
# Remove symbolic links
sudo rm -f /usr/local/bin/crystal
sudo rm -f /usr/local/bin/shards
# Remove old installation directory (if it exists)
if [ -d "/opt/crystal-1.13.1-1" ]; then
echo "Removing old Crystal 1.13.1 installation..."
sudo rm -rf /opt/crystal-1.13.1-1
fi
# Check for and remove any other Crystal installations in /opt
for dir in /opt/crystal-*; do
if [ -d "$dir" ]; then
echo "Removing Crystal installation at $dir..."
sudo rm -rf "$dir"
fi
done
fi
echo "Installing Crystal language"
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
installed_version=$(crystal --version | grep Crystal | awk '{print $2}')
echo "Crystal $installed_version has been installed successfully."
}
# Download and install Moltiverse from the latest release
install_moltiverse_release() {
echo "Installing Moltiverse from the latest release..."
# Get the latest release URL
LATEST_RELEASE_URL=$(curl -s https://api.github.com/repos/ucm-lbqc/moltiverse/releases/latest | grep "tarball_url" | cut -d '"' -f 4)
# Create a temporary directory
TEMP_DIR=$(mktemp -d)
# Download and extract the latest release
curl -L ${LATEST_RELEASE_URL} | tar xz -C ${TEMP_DIR}
# Move to the extracted directory
cd ${TEMP_DIR}/*moltiverse*
# Build Moltiverse with release flag
shards build moltiverse --release
# Move the built binary to a permanent location
mkdir -p $HOME/moltiverse/bin
mv -f bin/moltiverse $HOME/moltiverse/bin/
# Clean up
cd $HOME
rm -rf ${TEMP_DIR}
}
# Clone and build Moltiverse from the main branch
install_moltiverse_main() {
echo "Installing Moltiverse from the main branch..."
# Check if the moltiverse directory exists
if [ -d "$HOME/moltiverse" ]; then
echo "Existing Moltiverse directory found. Removing it..."
rm -rf "$HOME/moltiverse"
fi
# Clone the repository
git clone https://github.com/ucm-lbqc/moltiverse.git "$HOME/moltiverse"
# Change to the moltiverse directory
cd "$HOME/moltiverse"
# Build moltiverse
shards build moltiverse --release
}
# Add Moltiverse to PATH
add_to_path() {
echo 'export PATH="$PATH:$HOME/moltiverse/bin"' >> $HOME/.bashrc
source $HOME/.bashrc
}
# Main installation process
main() {
check_system_dependencies
install_miniconda
create_conda_env
install_dependencies
install_crystal
if [ -t 0 ] || [ "$FORCE_INTERACTIVE" = "1" ]; then
# Interactive mode
echo "Which version of Moltiverse would you like to install?"
echo "1) Latest release version (recommended for stability)"
echo "2) Main branch version (latest development version)"
read -p "Enter your choice (1 or 2): " version_choice
case $version_choice in
1)
install_moltiverse_release
;;
2)
install_moltiverse_main
;;
*)
echo "Invalid choice. Defaulting to main branch version."
install_moltiverse_main
;;
esac
else
# Non-interactive mode
# TO:DO: Add a flag to specify the version to install
# Defaulting to main branch version for now, but in the future the default should be the latest release version.
echo "Non-interactive mode: Installing main branch version of Moltiverse."
install_moltiverse_main
fi
add_to_path
echo " "
echo "=========================================================================="
echo "Moltiverse has been successfully installed!"
echo "Please restart your terminal or run 'source ~/.bashrc' to use Moltiverse."
}
main