-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
start-all.sh
executable file
·151 lines (119 loc) · 4.38 KB
/
start-all.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
#!/bin/bash
# Enable error handling
set -e
# Function to display the menu
menu() {
echo "Choose an option:"
echo "1. Install all (Recommended for first time setup)"
echo "2. Update and install dependencies (For updating existing setup)"
echo "3. Run existing version"
echo "4. Exit"
read -p "Enter your choice (1, 2, 3, or 4): " choice
case $choice in
1) install ;;
2) update_and_run ;;
3) run ;;
4) exit 0 ;;
*) echo "Invalid choice. Please try again."
menu ;;
esac
}
# Function to install all repositories and dependencies
install() {
echo "Cloning repositories..."
echo "Checking app repository..."
if [ ! -d "steadfast-app/.git" ]; then
echo "Cloning app..."
git clone https://github.com/narenkram/steadfast-app.git
else
echo "App repository already exists, skipping clone..."
fi
echo "Checking API repository..."
if [ ! -d "steadfast-api/.git" ]; then
echo "Cloning API..."
git clone https://github.com/narenkram/steadfast-api.git
else
echo "API repository already exists, skipping clone..."
fi
echo "Checking WebSocket repository..."
if [ ! -d "steadfast-websocket/.git" ]; then
echo "Cloning WebSocket..."
git clone https://github.com/narenkram/steadfast-websocket.git
else
echo "WebSocket repository already exists, skipping clone..."
fi
echo "Installing dependencies for all repositories..."
echo "Installing app dependencies..."
cd steadfast-app
npm install || { echo "Error occurred while installing app dependencies."; exit 1; }
cd ..
echo "Installing API dependencies..."
cd steadfast-api
npm install || { echo "Error occurred while installing API dependencies."; exit 1; }
cd ..
echo "Installing WebSocket dependencies..."
cd steadfast-websocket
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies within virtual environment
pip install -r requirements.txt || { echo "Error occurred while installing WebSocket dependencies."; exit 1; }
cd ..
echo "Installing NorenRestApi..."
pip install --no-deps NorenRestApi || { echo "Error occurred while installing NorenRestApi."; exit 1; }
deactivate
echo "Repositories cloned and dependencies installed successfully."
menu
}
# Function to update repositories and install dependencies
update_and_run() {
echo "Updating steadfast-monorepo..."
git pull https://github.com/narenkram/steadfast-monorepo main || { echo "Error updating steadfast-monorepo."; exit 1; }
echo "Updating steadfast-app..."
cd steadfast-app
git pull https://github.com/narenkram/steadfast-app main || { echo "Error updating steadfast-app."; exit 1; }
echo "Installing app dependencies..."
npm install
npm audit fix
cd ..
echo "Updating steadfast-api..."
cd steadfast-api
git pull https://github.com/narenkram/steadfast-api main || { echo "Error updating steadfast-api."; exit 1; }
echo "Installing API dependencies..."
npm install
npm audit fix
cd ..
echo "Updating steadfast-websocket..."
cd steadfast-websocket
git pull https://github.com/narenkram/steadfast-websocket main || { echo "Error updating steadfast-websocket."; exit 1; }
# Activate virtual environment and install dependencies
source venv/bin/activate
pip install -r requirements.txt || { echo "Error occurred while installing WebSocket dependencies."; exit 1; }
deactivate
cd ..
echo "Update complete."
menu
}
# Function to run the existing version
run() {
echo "Starting API..."
bash -c "cd steadfast-api && node server.js & "
echo "Starting app..."
bash -c "cd steadfast-app && npm run dev & "
echo "Starting WebSocket server..."
bash -c "cd steadfast-websocket && source venv/bin/activate && python main.py & "
sleep 5
echo "Opening browser to API's URL..."
xdg-open http://localhost:3000
echo "Opening browser to app's URL..."
xdg-open http://localhost:5173
echo "Services started and browsers opened. Close this window to stop all services."
read -p "Press any key to stop all services..." -n1 -s
echo "Stopping all services..."
pkill -f node
pkill -f python
echo "All services stopped."
menu
}
# Start the menu
menu