-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_env_run.sh
executable file
·92 lines (69 loc) · 1.91 KB
/
setup_env_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
#!/bin/bash
# Check Python version and existence
check_python(){
if ! [[ -x "$(command -v python3)" ]]; then
echo "Error:
Python 3 is required for Cinematica API.
Please install the latest version of Python 3 from: https://www.python.org/downloads/installing-python/" >&2
exit 1
fi
}
# Creates virtual environment
create_virtual_venv(){
if [ -d "src/$1" ]; then
echo "A virtual environment named $1 already exists in the src directory!"
echo "Skipping virtual environment creation."
else
python3 -m venv src/$1
echo "Virtual environment $1 created in the src directory!"
fi
}
# Activates virtual environment
activate_virtual_venv(){
source src/$1/bin/activate
}
# Upgrades to the latest version of pip
upgrade_pip(){
pip install --upgrade pip
}
# Install requirements and dependencies
install_requirements(){
pip install -r $1
}
# Create .env file with required environment variables
create_env_file(){
cat <<EOT >> .env
DATABASE_URL="postgresql+psycopg2://cinematica_dbuser:cinematica888@localhost:5432/cinematica_db"
SECRET_KEY="the_most_secret_key"
EOT
}
# Resets the database before running the API
reset_database(){
flask db drop
flask db create
flask db seed
echo "Database reset complete!"
}
# Main execution of bash script
echo "Welcome! Let's get you set up for Cinematica API!"
sleep 2
clear
check_python
create_virtual_venv .venv
activate_virtual_venv .venv
echo "Virtual environment created and activated in the src directory!"
# Change to the src directory
cd src
sleep 2
upgrade_pip
clear
install_requirements requirements.txt
create_env_file
echo "Requirements and dependencies installed. .env file created in src directory!"
sleep 2
clear
reset_database
sleep 2
clear
echo "Setup complete! Virtual environment initialised, dependencies installed. Starting the Cinematica API now..."
flask run