-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·80 lines (69 loc) · 2.77 KB
/
setup.sh
File metadata and controls
executable file
·80 lines (69 loc) · 2.77 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
#!/usr/bin/env bash
# Setup Telegram MTProto proxy: copy example.env to .env and generate SECRET.
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
if [[ -f .env ]]; then
echo "'.env' already exists. Remove it first if you want to re-run setup."
exit 1
fi
if [[ ! -f example.env ]]; then
echo "example.env not found."
exit 1
fi
# Generate 32 hex chars (16 bytes) for MTProto proxy secret
SECRET=$(openssl rand -hex 16)
cp example.env .env
if sed --version 2>/dev/null | grep -q GNU; then
sed -i "s/^SECRET=.*/SECRET=$SECRET/" .env
else
sed -i '' "s/^SECRET=.*/SECRET=$SECRET/" .env
fi
# Read ports from .env for the link
source .env 2>/dev/null || true
HTTPS_PORT="${HTTPS_PORT:-443}"
echo "Created .env with a generated SECRET."
echo ""
echo "Start the proxy:"
echo " docker compose up -d"
echo ""
# Prefer real IP for QR so it can be scanned (try local then public)
SERVER_IP=""
if command -v hostname &>/dev/null; then
SERVER_IP=$(hostname -I 2>/dev/null | awk '{print $1}')
fi
if [[ -z "$SERVER_IP" ]] && command -v curl &>/dev/null; then
SERVER_IP=$(curl -s --max-time 2 -4 ifconfig.me 2>/dev/null || true)
fi
if [[ -z "$SERVER_IP" ]]; then
SERVER_IP="YOUR_SERVER_IP"
fi
PROXY_LINK="https://t.me/proxy?server=$SERVER_IP&port=$HTTPS_PORT&secret=$SECRET"
echo "Your proxy link (replace YOUR_SERVER_IP with your server's IP or hostname):"
echo " tg://proxy?server=YOUR_SERVER_IP&port=$HTTPS_PORT&secret=$SECRET"
echo " $PROXY_LINK"
echo ""
# Install qrencode if missing (skip on error)
if ! command -v qrencode &>/dev/null; then
if command -v apt-get &>/dev/null; then
(apt-get update -qq 2>/dev/null && apt-get install -y -qq qrencode 2>/dev/null) || \
(command -v sudo &>/dev/null && sudo apt-get update -qq 2>/dev/null && sudo apt-get install -y -qq qrencode 2>/dev/null) || true
elif command -v apk &>/dev/null; then
(apk add --no-cache qrencode 2>/dev/null) || (command -v sudo &>/dev/null && sudo apk add --no-cache qrencode 2>/dev/null) || true
elif command -v dnf &>/dev/null; then
(dnf install -y qrencode 2>/dev/null) || (command -v sudo &>/dev/null && sudo dnf install -y qrencode 2>/dev/null) || true
elif command -v yum &>/dev/null; then
(yum install -y qrencode 2>/dev/null) || (command -v sudo &>/dev/null && sudo yum install -y qrencode 2>/dev/null) || true
fi
fi
if command -v qrencode &>/dev/null; then
if [[ "$SERVER_IP" != "YOUR_SERVER_IP" ]]; then
echo "QR code (scan with Telegram or camera):"
qrencode -t ansiutf8 -- "$PROXY_LINK"
else
echo "Could not detect server IP; QR not generated. Install qrencode and run:"
echo " echo 'https://t.me/proxy?server=YOUR_IP&port=$HTTPS_PORT&secret=$SECRET' | qrencode -t ansiutf8"
fi
else
echo "Install qrencode to show a QR code: apt install qrencode"
fi