-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
executable file
·207 lines (185 loc) · 5.41 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
#!/bin/bash
# Usage:
# chmod +x install.sh
#
# conda init bash
# bash -l install.sh
#
# conda init zsh
# zsh -i install.sh
# region Functions
check_display_server() {
# Function to check for the display server
if [ -z "$DISPLAY" ]; then
echo "No display server found. GUI applications may not run."
return 1
else
echo "Display server is running on $DISPLAY."
return 0
fi
}
add_channels() {
echo -e "\nAdding channels"
conda config --append channels conda-forge
conda config --append channels nvidia
conda config --append channels pytorch
echo -e "... Done"
}
update_base_env() {
echo -e "\nUpdating 'base' environment:"
conda init bash
# conda update -n base -c defaults conda --y
# conda update --a --y
pip install --upgrade pip
pip install poetry
echo -e "... Done"
}
install_on_linux() {
echo -e "\nLinux / WSL"
# Create `mon` env
if [ "$install_type" == "gui" ]; then
env_yml_path="${current_dir}/env/linux_gui.yaml"
elif [ "$install_type" == "console" ]; then
env_yml_path="${current_dir}/env/linux_console.yaml"
else
echo -e "\nInvalid machine type: $install_type"
fi
if { conda env list | grep 'mon'; } >/dev/null 2>&1; then
echo -e "\nUpdating 'mon' environment:"
conda env update --name mon -f "${env_yml_path}"
echo -e "... Done"
else
echo -e "\nCreating 'mon' environment:"
if sudo -n true 2>/dev/null; then
sudo apt-get install gcc g++
else
apt-get install gcc g++
fi
conda env create -f "${env_yml_path}"
echo "conda activate mon" >> ~/.bashrc
source ~/.bashrc
echo -e "... Done"
fi
# Install FFMPEG
if sudo -n true 2>/dev/null; then
sudo apt-get install ffmpeg
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
else
apt-get install ffmpeg
apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
fi
# Cleanup
rm -rf $CONDA_PREFIX/lib/python3.12/site-packages/cv2/qt/plugins
}
install_on_darwin() {
echo -e "\nMacOS"
# Must be called before installing PyTorch Lightning
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1
# Create `mon` env
env_yml_path="${current_dir}/env/macos.yaml"
if { conda env list | grep 'mon'; } >/dev/null 2>&1; then
echo -e "\nUpdating 'mon' environment:"
conda env update --name mon -f "${env_yml_path}"
echo -e "... Done"
else
echo -e "\nCreating 'mon' environment:"
conda env create -f "${env_yml_path}"
echo "conda activate mon" >> ~/.bash_profile
source ~/.bash_profile
echo -e "... Done"
fi
# Install FFMPEG
brew install ffmpeg
# Cleanup
rm -rf $CONDA_PREFIX/lib/python3.12/site-packages/cv2/qt/plugins
}
install_third_party_library() {
echo -e "\nInstall third-party library"
eval "$(conda shell.bash hook)"
conda activate mon
rm -rf poetry.lock
poetry install --extras "dev"
rm -rf poetry.lock
# conda update --a --y
conda clean --a --y
}
setup_data_dir() {
echo -e "\nSetting DATA_DIR"
root_dir=$1
data_dir="${root_dir}/data"
read -e -i "$data_dir" -p "Enter DATA_DIR=" input
data_dir="${input:-$data_dir}"
if [ "$data_dir" != "" ]; then
export DATA_DIR="$data_dir"
conda env config vars set data_dir="$data_dir"
echo -e "\nDATA_DIR has been set to $data_dir."
else
echo -e "\nDATA_DIR has NOT been set."
fi
# if [ -d "$root_dir" ]; then
# echo -e "\nDATA_DIR=$data_dir" > "${root_dir}/pycharm.env"
# fi
echo -e "... Done"
}
setup_resilio_sync() {
rsync_dir="${root_dir}/.sync"
mkdir -p "${rsync_dir}"
cp "env/IgnoreList" "${rsync_dir}/IgnoreList"
echo -e "... Done"
}
# endregion
# region Main
echo "$HOSTNAME"
# Directory
script_path=$(readlink -f "$0")
current_dir=$(dirname "$script_path")
root_dir=$current_dir
# Input
echo -e "Install Options:"
echo -e " - gui : install with GUI libraries (desktop PC)"
echo -e " - console: install without GUI libraries (server without monitor)"
echo -e " - lib : only install/update third-party libraries"
install_type="gui"
read -e -i "$install_type" -p "Choose [gui, console, lib]: " install_type
# Update 'base' env
add_channels
update_base_env
# Install 'mon' env
if [ "$install_type" == "gui" ] || [ "$install_type" == "console" ]; then
echo -e "\nInstalling 'mon' environment:"
case "$OSTYPE" in
linux*)
install_on_linux
;;
darwin*)
install_on_darwin
;;
win*)
echo -e "\nWindows"
;;
msys*)
echo -e "\nMSYS / MinGW / Git Bash"
;;
cygwin*)
echo -e "\nCygwin"
;;
bsd*)
echo -e "\nBSD"
;;
solaris*)
echo -e "\nSolaris"
;;
*)
echo -e "\nunknown: $OSTYPE"
;;
esac
fi
# Install third-party library
install_third_party_library
# Setup environment variables
# shellcheck disable=SC2162
export PYTHONDONTWRITEBYTECODE=1
setup_data_dir "$root_dir"
setup_resilio_sync "$root_dir"
# endregion