-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
110 lines (91 loc) · 2.64 KB
/
install.sh
File metadata and controls
110 lines (91 loc) · 2.64 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
#!/bin/bash
# Clone the repository
cd /opt/
if [ -d "Emergency-key" ]; then
cd Emergency-key
else
git clone https://github.com/primeZdev/Emergency-key.git
cd Emergency-key
fi
# Config files
touch keys.txt
cp .env.example .env
read -p "Enter PORT for app (default 3000): " PORT
PORT=${PORT:-3000}
read -p "Enter API_KEY: " API_KEY
read -p "Enter DOMAIN: " DOMAIN
echo "PORT=$PORT" > .env
echo "API_KEY=$API_KEY" >> .env
echo "DOMAIN=$DOMAIN" >> .env
# Install Caddy if not installed
if ! command -v caddy &> /dev/null; then
apt update && apt install -y debian-archive-keyring apt-transport-https curl gnupg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
tee /etc/apt/sources.list.d/caddy-stable.list <<EOF
deb [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main
deb-src [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main
EOF
apt update
apt install -y caddy
fi
# Create systemd service for app
cat <<EOL > /etc/systemd/system/em-key.service
[Unit]
Description=Emergency Key Service
After=network.target
[Service]
WorkingDirectory=/opt/Emergency-key
ExecStart=/opt/Emergency-key/main
Restart=always
[Install]
WantedBy=multi-user.target
EOL
# Create CLI em-keys
cat <<'EOL' > /usr/local/bin/em-keys
#!/bin/bash
SERVICE="em-key"
APP_DIR="/opt/Emergency-key"
case "$1" in
restart)
systemctl restart $SERVICE
;;
update)
cd $APP_DIR && git pull && systemctl restart $SERVICE
;;
edit-keys)
nano $APP_DIR/keys.txt
systemctl restart $SERVICE
;;
stop)
systemctl stop $SERVICE
;;
uninstall)
systemctl stop $SERVICE
systemctl disable $SERVICE
rm -f /etc/systemd/system/${SERVICE}.service
systemctl daemon-reload
rm -rf $APP_DIR
rm -f /usr/local/bin/em-keys
;;
*)
echo "Usage: em-keys {restart|update|edit-keys|stop|uninstall}"
exit 1
;;
esac
EOL
chmod +x /usr/local/bin/em-keys
systemctl daemon-reload
systemctl enable em-key.service
systemctl start em-key.service
# Create Caddyfile
cat <<EOL > /etc/caddy/Caddyfile
$DOMAIN {
reverse_proxy localhost:$PORT
}
EOL
# Restart Caddy to apply configuration
systemctl enable --now caddy
systemctl reload caddy
echo "Installation complete."
echo "Caddy is handling HTTPS on https://$DOMAIN/$API_KEY"
echo "Installation complete. Use 'em-keys edit-keys' to edit your v2ray keys."