generated from google-gemini/aistudio-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
117 lines (97 loc) · 3.6 KB
/
install.sh
File metadata and controls
117 lines (97 loc) · 3.6 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
#!/bin/bash
# OpenGate One-Line Installer
# Usage: bash <(curl -s https://raw.githubusercontent.com/ehsanking/OpenGate/main/install.sh)
set -e
echo -e "\n\033[1;32m[+] Starting OpenGate Installation...\033[0m\n"
# Check root
if [ "$EUID" -ne 0 ]; then
echo -e "\033[1;31m[-] Please run as root (sudo bash ...)\033[0m"
exit 1
fi
# Prompt for Domain
echo -e "\033[1;36m[?] Enter your domain name for SSL/DoH (e.g., opengate.example.com).\033[0m"
echo -e "\033[1;33m[!] Leave blank to skip SSL/Nginx setup (access via IP only).\033[0m"
read -p "Domain: " DOMAIN
# Update and install dependencies
echo -e "\033[1;34m[*] Installing system dependencies...\033[0m"
apt-get update -y
apt-get install -y curl git build-essential
# Install Node.js (v20)
if ! command -v node &> /dev/null; then
echo -e "\033[1;34m[*] Installing Node.js...\033[0m"
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
fi
# Clone repository
INSTALL_DIR="/opt/OpenGate"
if [ -d "$INSTALL_DIR" ]; then
echo -e "\033[1;34m[*] Updating existing installation...\033[0m"
cd "$INSTALL_DIR"
git pull
else
echo -e "\033[1;34m[*] Cloning repository...\033[0m"
git clone https://github.com/ehsanking/OpenGate.git "$INSTALL_DIR"
cd "$INSTALL_DIR"
fi
# Install npm packages and build
echo -e "\033[1;34m[*] Installing NPM dependencies and building...\033[0m"
npm install
npm run build
# Setup systemd service
echo -e "\033[1;34m[*] Setting up systemd service...\033[0m"
cat > /etc/systemd/system/opengate.service << EOF
[Unit]
Description=OpenGate Server
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=$INSTALL_DIR
Environment=NODE_ENV=production
ExecStart=/usr/bin/npm run dev
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable opengate
systemctl restart opengate
# Setup Nginx and SSL if domain is provided
if [ -n "$DOMAIN" ]; then
echo -e "\033[1;34m[*] Setting up Nginx and SSL for $DOMAIN...\033[0m"
apt-get install -y nginx certbot python3-certbot-nginx
# Create Nginx config
cat > /etc/nginx/sites-available/opengate << EOF
server {
listen 80;
server_name $DOMAIN;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF
ln -sf /etc/nginx/sites-available/opengate /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-enabled/default
systemctl restart nginx
echo -e "\033[1;34m[*] Obtaining SSL certificate via Let's Encrypt...\033[0m"
certbot --nginx -d "$DOMAIN" --non-interactive --agree-tos -m admin@$DOMAIN || echo -e "\033[1;31m[-] Certbot failed. Check if your domain points to this server's IP.\033[0m"
# Ensure auto-renewal is active (Certbot installs a systemd timer automatically)
systemctl enable certbot.timer
systemctl start certbot.timer
echo -e "\n\033[1;32m[+] Installation Complete!\033[0m"
echo -e "\033[1;32m[+] OpenGate is running securely at: https://$DOMAIN\033[0m"
echo -e "\033[1;32m[+] Your DoH Resolver: https://$DOMAIN/dns-query\033[0m"
else
echo -e "\n\033[1;32m[+] Installation Complete!\033[0m"
echo -e "\033[1;32m[+] OpenGate is running on port 3000\033[0m"
echo -e "\033[1;32m[+] Access it via: http://$(curl -s ifconfig.me):3000\033[0m"
echo -e "\033[1;33m[!] Note: You skipped SSL setup. DoH requires HTTPS to function securely.\033[0m"
fi
echo -e "\n"