-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·178 lines (137 loc) · 5.06 KB
/
install.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
#!/bin/sh
# Color variables
RED='\033[0;31m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
WHITE='\033[1;37m'
CYAN='\033[0;36m'
RESET='\033[0m'
# Check if the script is running as administrator
if [ "$(id -u)" != "0" ]; then
echo "${RED}» This script must be run as root! Restarting.."
# Restart with sudo
echo "${WHITE}"
sudo sh "$0" "$@"
fi
# Join the RevPanel folder
mkdir -p /etc/revpanel
cd /etc/revpanel
# If already installed, exit
if [ -f ".env" ]; then
echo "${RED}» RevPanel is already installed!"
echo "${RED}» If you want to reinstall RevPanel, please uninstall first or remove the /etc/revpanel directory"
echo "${RESET}"
exit 1
fi
# --------------------------------------------
echo "${PURPLE}"
cat << "EOF"
_______ _______ __
| \ | \ | \
| $$$$$$$\ ______ __ __ | $$$$$$$\ ______ _______ ______ | $$
| $$__| $$ / \| \ / \| $$__/ $$| \ | \ / \ | $$
| $$ $$| $$$$$$\\$$\ / $$| $$ $$ \$$$$$$\| $$$$$$$\| $$$$$$\| $$
| $$$$$$$\| $$ $$ \$$\ $$ | $$$$$$$ / $$| $$ | $$| $$ $$| $$
| $$ | $$| $$$$$$$$ \$$ $$ | $$ | $$$$$$$| $$ | $$| $$$$$$$$| $$
| $$ | $$ \$$ \ \$$$ | $$ \$$ $$| $$ | $$ \$$ \| $$
\$$ \$$ \$$$$$$$ \$ \$$ \$$$$$$$ \$$ \$$ \$$$$$$$ \$$
EOF
echo ""
echo ""
echo " ${GREEN}RevPanel Installer v2.0.0"
# --------------------------------------------
# -------------[ #1 DEPENDENCIES ]-------------
echo "${CYAN}» Installing dependencies [1/3]"
sudo apt update
sudo apt install curl openssl certbot python3-certbot-nginx nginx -y
if ! [ -x "$(command -v docker)" ]; then
sudo apt install docker.io docker-compose -y
sudo systemctl enable --now docker
fi
if ! [ -x "$(command -v node)" ]; then
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs -y
fi
corepack enable
npm install -g pm2
echo "${GREEN}» Dependencies installed [1/3]"
# -------------[ #2 WEBSERVER ]-------------
echo "${CYAN}» Setting up WebServer [2/3]"
echo "${WHITE}"
if [[ -z "${DOMAIN}" ]]; then
read -p "Enter your panel domain (e.g panel.example.com): " DOMAIN
fi
sudo certbot certonly --nginx -d ${DOMAIN} -d api.${DOMAIN} --non-interactive --agree-tos -m admin@${DOMAIN}
echo "server {
server_name ${DOMAIN};
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/${DOMAIN}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${DOMAIN}/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
server_name api.${DOMAIN};
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/api.${DOMAIN}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.${DOMAIN}/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if (\$host = ${DOMAIN}) {
return 301 https://\$host\$request_uri;
}
if (\$host = api.${DOMAIN}) {
return 301 https://\$host\$request_uri;
}
listen 80;
server_name ${DOMAIN} api.${DOMAIN};
return 404;
}" > /etc/nginx/sites-available/revpanel
sudo ln -s /etc/nginx/sites-available/revpanel /etc/nginx/sites-enabled/revpanel
sudo systemctl reload nginx
echo "${GREEN}» WebServer setup complete [2/3]"
# -------------[ #3 CONFIGURATION ]-------------
echo "${CYAN}» Configuring the panel [3/3]"
git clone https://github.com/RevPanel/Daemon daemon
git clone https://github.com/RevPanel/Panel panel
POSTGRES_PASSWORD=$(openssl rand -hex 32)
API_TOKEN=$(openssl rand -hex 32)
sudo docker run --name revpanel-postgres -e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} -p 127.0.0.1:5432:5432 --restart always -d postgres:16-alpine
cd daemon
corepack pnpm install
echo "NODE_ENV=production
DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@localhost:5432/daemon
API_TOKEN=${API_TOKEN}" > .env
corepack pnpm run migrate:run
corepack pnpm build
pm2 start dist/main.js --name=revpanel-daemon
cd ../panel
corepack pnpm install
echo "NODE_ENV=production
DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@localhost:5432/panel
APP_URL=https://${DOMAIN}
BACKEND_URL=https://api.${DOMAIN}
ADMIN_KEY=${API_TOKEN}" > .env
corepack pnpm run migrate:run
corepack pnpm build
pm2 start npm --name=revpanel-web -- start
pm2 save
pm2 startup
echo "${GREEN}» Panel configured [3/3]"
echo "${RESET}"