-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmac_run.sh
288 lines (251 loc) · 9.39 KB
/
mac_run.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
#!/usr/bin/env bash
set -e
set -o pipefail
echo "Script started at $(date)" > debug.log
echo "----------------------------------------" >> debug.log
PATHFILE="dataset_curation_path.txt"
UPDATE_ENV=false
echo "Use --update on the command line with the run file to update the program!"
echo "Use --update on the command line with the run file to update the program!" >> debug.log
OTHER_ARGS=()
for arg in "$@"; do
if [ "$arg" = "--update" ]; then
UPDATE_ENV=true
else
OTHER_ARGS+=("$arg")
fi
done
echo "Checking if git is available..."
echo "Checking if git is available..." >> debug.log
if ! command -v git >/dev/null 2>&1; then
echo "Git not found. Please install Git from https://git-scm.com/download/mac"
echo "Git not found. Please install Git manually." >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
else
echo "Git is already installed"
echo "Git is already installed" >> debug.log
fi
echo "Checking conda availability..."
echo "Checking conda availability..." >> debug.log
if ! command -v conda >/dev/null 2>&1; then
echo "Miniconda not found. Installing Miniconda..."
echo "Miniconda not found. Installing Miniconda..." >> debug.log
curl -o miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
if [ $? -ne 0 ]; then
echo "Failed to download Miniconda"
echo "Failed to download Miniconda" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
bash miniconda.sh -b -p "$HOME/miniconda"
if [ $? -ne 0 ]; then
echo "Miniconda installation failed"
echo "Miniconda installation failed" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
rm miniconda.sh
export PATH="$HOME/miniconda/bin:$PATH"
conda init bash || true
source ~/.bashrc
echo "Miniconda installed successfully"
echo "Miniconda installed successfully" >> debug.log
else
echo "Miniconda is already installed"
echo "Miniconda is already installed" >> debug.log
export PATH="$HOME/miniconda/bin:$PATH"
source ~/.bashrc
fi
echo "Checking repository path..."
echo "Checking repository path..." >> debug.log
if [ -f "$PATHFILE" ]; then
echo "Found stored path in $PATHFILE"
echo "Found stored path in $PATHFILE" >> debug.log
STORED_PATH=$(sed -e 's/^[[:space:]]*//;s/[[:space:]]*$//' "$PATHFILE")
if [ -z "$STORED_PATH" ]; then
echo "Stored path is empty. Please delete $PATHFILE and run again."
echo "Stored path is empty. Please delete $PATHFILE and run again." >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
cd "$STORED_PATH"
if [ $? -ne 0 ]; then
echo "Failed to change directory to stored path: $STORED_PATH"
echo "Failed to change directory to stored path: $STORED_PATH" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
echo "Changed directory to stored path: $PWD"
echo "Changed directory to stored path: $PWD" >> debug.log
else
echo "No $PATHFILE found, using current directory as parent"
echo "No $PATHFILE found, using current directory as parent" >> debug.log
PARENT_PATH="$PWD"
echo "Using current directory as parent: $PWD"
echo "Using current directory as parent: $PWD" >> debug.log
fi
if [ ! -f "Dataset-Curation-Tool/environment.yml" ]; then
echo "Dataset-Curation-Tool not found in $PWD. Attempting to clone..."
echo "Dataset-Curation-Tool not found in $PWD. Attempting to clone..." >> debug.log
git clone https://github.com/x-CK-x/Dataset-Curation-Tool.git Dataset-Curation-Tool
if [ $? -ne 0 ]; then
echo "Git clone failed"
echo "Git clone failed" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
UPDATE_ENV=true
else
echo "Dataset-Curation-Tool already present"
echo "Dataset-Curation-Tool already present" >> debug.log
fi
cd Dataset-Curation-Tool
if [ $? -ne 0 ]; then
echo "Cloned (if needed) but failed to enter Dataset-Curation-Tool directory"
echo "Cloned (if needed) but failed to enter Dataset-Curation-Tool directory" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
if [ ! -f "environment.yml" ]; then
echo "environment.yml not found inside Dataset-Curation-Tool"
echo "environment.yml not found inside Dataset-Curation-Tool" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
echo "Verified we are inside Dataset-Curation-Tool directory: $PWD"
echo "Verified we are inside Dataset-Curation-Tool directory: $PWD" >> debug.log
cd ..
if [ $? -ne 0 ]; then
echo "Failed to go one directory up to store parent path"
echo "Failed to go one directory up to store parent path" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
echo "$PWD" > "$PATHFILE"
echo "Stored current path $PWD into $PATHFILE."
echo "Stored current path $PWD into $PATHFILE." >> debug.log
cd Dataset-Curation-Tool
if [ $? -ne 0 ]; then
echo "Failed to re-enter Dataset-Curation-Tool directory"
echo "Failed to re-enter Dataset-Curation-Tool directory" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
echo "Deleting old run scripts..."
echo "Deleting old run scripts..." >> debug.log
rm -f linux_run.sh mac_run.sh run.bat
echo "Fetching latest changes and tags..."
echo "Fetching latest changes and tags..." >> debug.log
git fetch
if [ $? -ne 0 ]; then
echo "Failed to fetch from git repository"
echo "Failed to fetch from git repository" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
echo "Determining latest tag..."
echo "Determining latest tag..." >> debug.log
LATEST_TAG=$(git for-each-ref refs/tags --sort=-creatordate --format '%(refname:short)' --count=1)
CURRENT_TAG=$(git describe --tags --exact-match 2> /dev/null || true)
if [ -z "$CURRENT_TAG" ]; then
echo "No current tag found - possibly a detached HEAD"
echo "No current tag found - possibly a detached HEAD" >> debug.log
else
echo "Currently on tag: $CURRENT_TAG. Latest tag: $LATEST_TAG."
echo "Currently on tag: $CURRENT_TAG. Latest tag: $LATEST_TAG." >> debug.log
fi
if [ "$CURRENT_TAG" != "$LATEST_TAG" ]; then
echo "Not on the latest tag. Checking out to $LATEST_TAG."
echo "Not on the latest tag. Checking out to $LATEST_TAG." >> debug.log
git reset HEAD linux_run.sh mac_run.sh run.bat || true
git checkout -- linux_run.sh mac_run.sh run.bat || true
echo "Stashing any user changes..."
echo "Stashing any user changes..." >> debug.log
git stash || true
echo "Removing __pycache__ and pyc files"
echo "Removing __pycache__ and pyc files" >> debug.log
find . -name "__pycache__" -type d -exec rm -r {} +
find . -name "*.pyc" -exec rm -f {} +
echo "Checking out to $LATEST_TAG..."
echo "Checking out to $LATEST_TAG..." >> debug.log
git checkout "tags/$LATEST_TAG"
if [ $? -ne 0 ]; then
echo "Failed to checkout to $LATEST_TAG."
echo "Failed to checkout to $LATEST_TAG." >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
echo "Applying stashed user changes..."
echo "Applying stashed user changes..." >> debug.log
git stash apply || true
UPDATE_ENV=true
else
echo "Already on the latest tag $LATEST_TAG"
echo "Already on the latest tag $LATEST_TAG" >> debug.log
fi
echo "Checking if the conda environment data-curation exists..."
echo "Checking if the conda environment data-curation exists..." >> debug.log
conda info --envs | grep data-curation > /dev/null
if [ $? -ne 0 ]; then
echo "Environment data-curation not found. Creating environment..."
echo "Environment data-curation not found. Creating environment..." >> debug.log
conda env create -f environment.yml
if [ $? -ne 0 ]; then
echo "Failed to create conda environment"
echo "Failed to create conda environment" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
fi
else
if $UPDATE_ENV; then
echo "Environment data-curation exists. Updating environment"
echo "Environment data-curation exists. Updating environment" >> debug.log
conda env update -n data-curation -f environment.yml || true
else
echo "Environment data-curation already exists and up to date"
echo "Environment data-curation already exists and up to date" >> debug.log
fi
fi
echo "Activating data-curation environment..."
echo "Activating data-curation environment..." >> debug.log
conda activate data-curation || {
echo "Failed to activate environment"
echo "Failed to activate environment" >> debug.log
echo "Press any key to exit."
read -rsn1
exit 1
}
echo "Running the python program..."
echo "Running the python program..." >> debug.log
python webui.py "${OTHER_ARGS[@]}" || {
echo "Python program encountered an error"
echo "Python program encountered an error" >> debug.log
echo "Check debug.log for details. Press any key to exit."
read -rsn1
exit 1
}
echo "Starting UI at http://localhost:7860"
echo "Starting UI at http://localhost:7860" >> debug.log
OS=$(uname)
if [ "$OS" = "Linux" ]; then
xdg-open http://localhost:7860 || true
elif [ "$OS" = "Darwin" ]; then
open http://localhost:7860 || true
else
echo "Unsupported OS: $OS"
echo "Unsupported OS: $OS" >> debug.log
fi