forked from Hemanthkumar2k04/CodeRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·89 lines (75 loc) · 2.09 KB
/
setup.sh
File metadata and controls
executable file
·89 lines (75 loc) · 2.09 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
#!/bin/bash
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${BLUE}🚀 Starting CodeRunner Setup...${NC}"
# Get the original user if running with sudo
if [ "$EUID" -eq 0 ]; then
ORIGINAL_USER=$SUDO_USER
if [ -z "$ORIGINAL_USER" ]; then
echo -e "${YELLOW}⚠️ Could not detect original user${NC}"
exit 1
fi
echo -e "${BLUE}📌 Running with sudo as user: $ORIGINAL_USER${NC}"
else
ORIGINAL_USER=$(whoami)
fi
# Check and load nvm if available
if [ -s "$HOME/.nvm/nvm.sh" ]; then
. "$HOME/.nvm/nvm.sh"
echo -e "${BLUE}📌 Using NVM to manage Node.js versions...${NC}"
nvm use
fi
# Clean up any node_modules with permission issues
echo -e "\n${BLUE}🧹 Cleaning up old node_modules...${NC}"
rm -rf server/node_modules client/node_modules
# 1. Install Server Dependencies
echo -e "\n${BLUE}📦 Installing Server Dependencies...${NC}"
cd server || exit 1
if [ "$EUID" -eq 0 ]; then
sudo -u "$ORIGINAL_USER" npm ci
else
npm ci
fi
cd ..
# 2. Install Client Dependencies
echo -e "\n${BLUE}📦 Installing Client Dependencies...${NC}"
cd client || exit 1
if [ "$EUID" -eq 0 ]; then
sudo -u "$ORIGINAL_USER" npm ci
else
npm ci
fi
cd ..
# 3. Build Docker Runtimes
echo -e "\n${BLUE}🐳 Building Docker Runtimes...${NC}"
# Python
echo -e "${GREEN}Building Python Runtime...${NC}"
cd runtimes/python || exit 1
docker build -t python-runtime .
cd ../..
# C++
echo -e "${GREEN}Building C++ Runtime...${NC}"
cd runtimes/cpp || exit 1
docker build -t cpp-runtime .
cd ../..
# Java
echo -e "${GREEN}Building Java Runtime...${NC}"
cd runtimes/java || exit 1
docker build -t java-runtime .
cd ../..
# Node.js
echo -e "${GREEN}Building Node.js Runtime...${NC}"
cd runtimes/javascript || exit 1
docker build -t node-runtime .
cd ../..
# MySQL
echo -e "${GREEN}Building MySQL Runtime...${NC}"
cd runtimes/mysql || exit 1
docker build -t mysql-runtime .
cd ../..
echo -e "\n${GREEN}✅ Setup Complete!${NC}"
echo -e "To start the server: ${BLUE}cd server && npm run dev${NC}"
echo -e "To start the client: ${BLUE}cd client && npm run dev${NC}"