Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
156 lines (134 loc) · 5.15 KB
/
Copy pathsetup.sh
File metadata and controls
156 lines (134 loc) · 5.15 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
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
#!/bin/bash
info() {
printf "\033[1;37m[INFO]\033[0m %s\n" "$1"
}
success() {
printf "\033[1;97m[SUCCESS]\033[0m %s\n" "$1"
}
error() {
printf "\033[1;97m[ERROR]\033[0m %s\n" "$1"
}
highlight() {
printf "\033[1;97m%s\033[0m\n" "$1"
}
separator() {
printf "\033[1;37m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m\n"
}
clear
highlight " █ █░ ▄▄▄ ██▒ █▓▓█████ ██████ ██████ ▓█████▄▄▄█████▓ █ ██ ██▓███"
highlight "▓█░ █ ░█░▒████▄ ▓██░ █▒▓█ ▀ ▒██ ▒ ▒██ ▒ ▓█ ▀▓ ██▒ ▓▒ ██ ▓██▒▓██░ ██▒"
highlight "▒█░ █ ░█ ▒██ ▀█▄▓██ █▒░▒███ ░ ▓██▄ ░ ▓██▄ ▒███ ▒ ▓██░ ▒░▓██ ▒██░▓██░ ██▓▒"
highlight "░█░ █ ░█ ░██▄▄▄▄██▒██ █░░▒▓█ ▄ ▒ ██▒ ▒ ██▒▒▓█ ▄░ ▓██▓ ░ ▓▓█ ░██░▒██▄█▓▒ ▒"
highlight "░░██▒██▓ ▓█ ▓██▒▒▀█░ ░▒████▒▒██████▒▒ ▒██████▒▒░▒████▒ ▒██▒ ░ ▒▒█████▓ ▒██▒ ░ ░"
highlight " ░ ▓░▒ ▒ ▒▒ ▓▒█░░ ▐░ ░░ ▒░ ░▒ ▒▓▒ ▒ ░ ▒ ▒▓▒ ▒ ░░░ ▒░ ░ ▒ ░░ ░▒▓▒ ▒ ▒ ▒▓▒░ ░ ░"
highlight " ▒ ░ ░ ▒ ▒▒ ░░ ░░ ░ ░ ░░ ░▒ ░ ░ ░ ░▒ ░ ░ ░ ░ ░ ░ ░░▒░ ░ ░ ░▒ ░"
highlight " ░ ░ ░ ▒ ░░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░░░ ░ ░ ░░ "
highlight " ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░"
separator
info "Starting the setup process..."
separator
info "Checking if Node.js and npm are installed..."
if ! dpkg-query -l | grep -q nodejs; then
info "Node.js not found. Installing..."
sudo apt update -y > /dev/null 2>&1
sudo apt install -y nodejs npm > /dev/null 2>&1
success "Node.js and npm installed successfully."
else
success "Node.js and npm are already installed."
fi
separator
info "Checking if Caddy is installed..."
if ! dpkg-query -l | grep -q caddy; then
info "Caddy not found. Installing..."
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https > /dev/null 2>&1
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg > /dev/null 2>&1
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/deb.debian.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list > /dev/null
sudo apt update -y > /dev/null 2>&1
sudo apt install -y caddy > /dev/null 2>&1
success "Caddy installed successfully."
else
success "Caddy is already installed."
fi
separator
info "Creating Caddyfile..."
cat <<EOF | sudo tee /etc/caddy/Caddyfile > /dev/null
{
email sefiicc@gmail.com
}
:443 {
tls {
on_demand
}
reverse_proxy http://localhost:3000
encode gzip zstd
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains"
X-Frame-Options "ALLOWALL"
X-Content-Type-Options "nosniff"
X-XSS-Protection "1; mode=block"
Referrer-Policy "no-referrer"
}
}
:80 {
reverse_proxy http://localhost:3000
}
EOF
separator
h
info "Testing Caddy configuration..."
sudo caddy fmt /etc/caddy/Caddyfile > /dev/null 2>&1
if [ $? -eq 0 ]; then
success "Caddyfile is valid."
else
error "Caddyfile test failed. Exiting."
exit 1
fi
info "Starting Caddy..."
if ! sudo systemctl restart caddy > /dev/null 2>&1; then
error "Failed to start Caddy."
exit 1
fi
success "Caddy started."
separator
info "Checking if PM2 is installed..."
PM2_PATH=$(which pm2 2>/dev/null)
if [ "$PM2_PATH" = "/usr/local/bin/pm2" ]; then
success "PM2 is already installed."
else
info "PM2 not found or not in the expected path. Installing..."
sudo npm install -g pm2 > /dev/null 2>&1
if [ $? -eq 0 ]; then
success "PM2 installed successfully."
else
error "Failed to install PM2."
exit 1
fi
fi
separator
info "Installing dependencies..."
npm install > /dev/null 2>&1
success "Dependencies installed."
separator
info "Starting the server with PM2..."
pm2 start index.mjs > /dev/null 2>&1
pm2 save > /dev/null 2>&1
success "Server started and saved with PM2."
separator
info "Setting up Git auto-update..."
nohup bash -c "
while true; do
git fetch origin
LOCAL=\$(git rev-parse main)
REMOTE=\$(git rev-parse origin/main)
if [ \$LOCAL != \$REMOTE ]; then
git pull origin main > /dev/null 2>&1
pm2 restart index.mjs > /dev/null 2>&1
pm2 save > /dev/null 2>&1
fi
sleep 1
done
" > /dev/null 2>&1 &
success "Git auto-update setup completed."
separator
success "Setup completed."
separator