-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathlinux_create_venv.sh
108 lines (86 loc) · 3.86 KB
/
linux_create_venv.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
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
# Function to print big messages
print_big_message() {
echo
echo "*******************************************************************"
for msg in "$@"; do
echo "* $msg"
done
echo "*******************************************************************"
echo
}
# Move to the script's directory
cd "$(dirname "$0")"
# Check for spaces in the current directory path
if [[ "$PWD" =~ \ ]]; then
echo "This script relies on Miniconda which cannot be silently installed under a path with spaces."
exit 1
fi
# Check for special characters in the installation path
if [[ "$PWD" =~ [!\#\$\%\&\(\)\*\+,\;\<\=\>\?\@\[\]\^\`\{\|\}\~] ]]; then
# if [[ "$PWD" =~ [!#\$%&\(\)\*\+,\;<=>\?@\[\]\^\`\{\|\}\~] ]]; then
SPCHARMESSAGE=("WARNING: Special characters were detected in the installation path!"
"This can cause the installation to fail!")
print_big_message "${SPCHARMESSAGE[@]}"
fi
# Configuration
INSTALL_DIR="$PWD/installer_files"
CONDA_ROOT_PREFIX="$INSTALL_DIR/conda"
INSTALL_ENV_DIR="$INSTALL_DIR/env"
MINICONDA_DOWNLOAD_URL="https://repo.anaconda.com/miniconda/Miniconda3-py310_23.3.1-0-Linux-x86_64.sh"
MINICONDA_CHECKSUM="aef279d6baea7f67940f16aad17ebe5f6aac97487c7c03466ff01f4819e5a651"
# Check if conda exists
conda_exists=false
if [[ -x "$CONDA_ROOT_PREFIX/bin/conda" ]]; then
conda_exists=true
fi
# If necessary, install conda into a contained environment
if [[ "$conda_exists" == false ]]; then
echo "Downloading Miniconda from $MINICONDA_DOWNLOAD_URL to $INSTALL_DIR/miniconda_installer.sh"
mkdir -p "$INSTALL_DIR"
curl -L "$MINICONDA_DOWNLOAD_URL" -o "$INSTALL_DIR/miniconda_installer.sh" || { echo "Miniconda failed to download."; exit 1; }
# Verify checksum
checksum=$(sha256sum "$INSTALL_DIR/miniconda_installer.sh" | awk '{print $1}')
if [[ "$checksum" != "$MINICONDA_CHECKSUM" ]]; then
echo "The checksum verification for miniconda_installer.sh has failed."
rm "$INSTALL_DIR/miniconda_installer.sh"
exit 1
else
echo "The checksum verification for miniconda_installer.sh has passed successfully."
fi
echo "Installing Miniconda to $CONDA_ROOT_PREFIX"
bash "$INSTALL_DIR/miniconda_installer.sh" -b -f -p "$CONDA_ROOT_PREFIX"
# Test the conda binary
echo "Miniconda version:"
"$CONDA_ROOT_PREFIX/bin/conda" --version || { echo "Miniconda not found."; exit 1; }
# Delete the Miniconda installer
rm "$INSTALL_DIR/miniconda_installer.sh"
fi
# Create the installer environment
if [[ ! -d "$INSTALL_ENV_DIR" ]]; then
echo "Creating conda environment with Python 3.10.9"
"$CONDA_ROOT_PREFIX/bin/conda" create -y -k --prefix "$INSTALL_ENV_DIR" python=3.10.9 || { echo "Conda environment creation failed."; exit 1; }
fi
# Check if conda environment was actually created
if [[ ! -x "$INSTALL_ENV_DIR/bin/python" ]]; then
echo "Conda environment is empty."
exit 1
fi
# Environment isolation
export PYTHONNOUSERSITE=1
unset PYTHONPATH
unset PYTHONHOME
# Activate installer environment
source "$CONDA_ROOT_PREFIX/bin/activate" "$INSTALL_ENV_DIR" || { echo "Conda activation failed."; exit 1; }
echo "Conda environment activated with Python 3.10.9"
# To activate this environment, use
#
# $ conda activate /home/lon/Dev/Linguflex/Linguflex/installer_files/env
#
# To deactivate an active environment, use
#
# $ conda deactivate
# Your further setup can go here
# Keep the shell open
exec "$SHELL"