-
Notifications
You must be signed in to change notification settings - Fork 21
/
install_cosicorr.sh
executable file
·161 lines (140 loc) · 4.56 KB
/
install_cosicorr.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
#!/bin/bash
INSTALL_CONDA=false
INSTALL_DOCKER=false
OVERWRITE=false
DOCKERFILE_PATH="Dockerfile"
BASE_IMAGE_NAME="ghcr.io/saifaati/geospatial-cosicorr3d/base_cosicorr3d_image"
BASE_IMAGE_TAG="base.1.1"
show_help() {
echo "Usage: $0 [OPTION]"
echo "Options:"
echo " --conda Install Miniconda and set up the geoCosiCorr3D environment."
echo " --docker Install Docker."
echo " --overwrite Overwrite the existing geoCosiCorr3D environment if it exists (only valid with --conda)."
echo " -h, --help Show this help message and exit."
exit 0
}
while (( "$#" )); do
case "$1" in
--conda)
INSTALL_CONDA=true
shift
;;
--docker)
INSTALL_DOCKER=true
shift
;;
--overwrite)
OVERWRITE=true
shift
;;
-h|--help)
show_help
;;
*)
echo "Error: Unknown option '$1'"
show_help
;;
esac
done
# Check if no operation was selected
if [ "$INSTALL_CONDA" = false ] && [ "$INSTALL_DOCKER" = false ]; then
echo "Error: No operation selected. You must specify either --conda or --docker."
show_help
fi
install_conda() {
export LD_LIBRARY_PATH=$(pwd)/lib/:$LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH
# Check if Miniconda is installed by looking for the ~/miniconda3 directory
if ! [ -d ~/miniconda3 ]; then
echo "Miniconda is not installed. Installing now..."
mkdir -p cosicorr_tmp_install
cd cosicorr_tmp_install
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
cd ..
rm -rf cosicorr_tmp_install
. ~/miniconda3/etc/profile.d/conda.sh
else
echo "Miniconda is already installed."
. ~/miniconda3/etc/profile.d/conda.sh
fi
# Check if the geoCosiCorr3D environment already exists
if conda env list | grep -q 'geoCosiCorr3D'; then
if [ "$OVERWRITE" = true ]; then
echo "The geoCosiCorr3D environment exists but will be deleted and recreated as per --overwrite option."
conda remove --name geoCosiCorr3D --all
conda env update --file geoCosiCorr3D.yml --prune
else
echo "The geoCosiCorr3D environment is already installed. To activate it, enter the cmd: conda activate geoCosiCorr3D"
fi
else
echo "The geoCosiCorr3D environment does not exist. Creating it..."
conda env update --file geoCosiCorr3D.yml --prune
. ~/miniconda3/etc/profile.d/conda.sh
fi
}
init_docker() {
echo "Installing Docker..."
sudo apt-get update
sudo apt-get install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
echo "Docker installed and started successfully."
}
start_docker() {
echo "Starting Docker service..."
sudo systemctl start docker
echo "Docker service started."
}
check_dockerfile_exists() {
if [ ! -f "$DOCKERFILE_PATH" ]; then
echo "Error: Dockerfile '$DOCKERFILE_PATH' does not exist. Please check the file path."
exit 1
else
echo "Dockerfile '$DOCKERFILE_PATH' exists."
fi
}
pulling_base_image() {
# Check if Docker is installed
if ! command -v docker &> /dev/null
then
echo "Docker is not installed."
init_docker
else
echo "Docker is installed."
# Check if Docker service is running
DOCKER_STATUS=$(systemctl is-active docker)
if [ "${DOCKER_STATUS}" = "active" ]; then
echo "Docker service is active and running."
else
echo "Docker service is not running."
start_docker
fi
fi
if ! docker image ls | grep -q "${BASE_IMAGE_NAME}.*${BASE_IMAGE_TAG}"; then
echo "Base Image does not exist locally. Attempting to pull..."
# Pull the Docker image from GCR
docker pull ${BASE_IMAGE_NAME}:${BASE_IMAGE_TAG}
if [ $? -eq 0 ]; then
echo "Docker image pulled successfully."
else
echo "Failed to pull the Base Docker image."
fi
else
echo "Base Docker image already exists locally."
fi
}
install_docker() {
echo "Installing Docker version ..."
echo 'Building cosicorr3D base image '
check_dockerfile_exists
pulling_base_image
docker-compose -f docker-compose.yml build geocosicorr3d
}
if [ "$INSTALL_CONDA" = true ]; then
install_conda
fi
if [ "$INSTALL_DOCKER" = true ]; then
install_docker
fi