-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup.sh
More file actions
executable file
·102 lines (90 loc) · 3.13 KB
/
startup.sh
File metadata and controls
executable file
·102 lines (90 loc) · 3.13 KB
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
#!/bin/bash
# Function to prompt user for OPENAI_API_KEY
prompt_api_key() {
echo "Please enter your OpenAI API key:"
read -r api_key
echo "export OPENAI_API_KEY='$api_key'" >> "$HOME/.bash_profile"
echo "API key set successfully. Please restart your terminal or run 'source ~/.bash_profile'."
}
# Check if OPENAI_API_KEY environment variable is set
if [ -z "$OPENAI_API_KEY" ]; then
echo "OPENAI_API_KEY is not set."
prompt_api_key
else
echo "OPENAI_API_KEY is set: $OPENAI_API_KEY"
fi
# Place the rest of your script here
# Sends contents from logo.txt to the console
cat boot_utilities/logo.txt
echo
condapath="$HOME/miniconda3/bin/activate"
envname="Text2Map"
repopath="$(pwd)"
spacy_model="en_core_web_trf"
# Check if conda is system installation or user installation
if [ -f "$condapath" ]; then
echo "Conda found in user directory"
elif [ -d "/usr/local/miniconda3" ]; then
condapath="/usr/local/miniconda3/bin/activate"
echo "Conda found in system directory"
else
echo "Conda not found"
exit 1
fi
# Check if front and backend folders exist
if [ ! -d "$repopath/frontend" ]; then
echo "Frontend folder not found"
exit 1
fi
if [ ! -d "$repopath/backend" ]; then
echo "Backend folder not found"
exit 1
fi
# Check if .env.local file exists
if [ ! -f "$repopath/frontend/.env.local" ]; then
bash boot_utilities/create_env.sh
fi
# Try to start conda base environment
source "$condapath" base
if [ $? -eq 0 ]; then
echo "Conda base environment is now active."
else
echo "Conda base environment could not be activated/start or does not exist."
exit 1
fi
# Check if Conda environment exists
if conda info --envs | grep -q "\<$envname\>"; then
# Environment exists, activate it
echo "Activating existing Conda environment: $envname"
source "$condapath" $envname
else
# Environment doesn't exist, create and activate it
echo "Creating and activating new Conda environment: $envname"
conda create --name $envname python=3.8 -y
source "$condapath" $envname
conda install -q --yes yarn
conda install -q --yes pip
fi
echo "Conda environment $envname is now active."
# Check if spaCy model is installed, if not, download it
if ! python -c "import spacy; nlp = spacy.load('$spacy_model')"; then
echo "Downloading spaCy model: $spacy_model"
python -m spacy download $spacy_model
fi
# Start the frontend and backend in separate Terminal windows
osascript -e 'tell application "Terminal" to do script "source '$condapath' '$envname' && cd '$repopath/frontend' && yarn install -s && yarn dev"'
osascript -e 'tell application "Terminal" to do script "source '$condapath' '$envname' && cd '$repopath/backend' && pip install --quiet -r requirements.txt && uvicorn main:app --reload"'
# Check if server is running every second. If not successful after 20 seconds, exit. If successful, open browser
count=0
while [ $count -lt 20 ]; do
sleep 1
count=$((count+1))
curl -s http://localhost:3000 >/dev/null
if [ $? -eq 0 ]; then
open "http://localhost:8000/docs"
open "http://localhost:3000"
exit 0
fi
done
echo "Server could not be started"
exit 1