Repository navigation
Expand file tree
/
Copy pathinstaller.sh
More file actions
187 lines (154 loc) · 4.45 KB
/
Copy pathinstaller.sh
File metadata and controls
187 lines (154 loc) · 4.45 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
set -e
# Fixed PingTunnel version
VERSION="2.8"
# Detect OS
get_os() {
os=$(uname | tr '[:upper:]' '[:lower:]')
case "$os" in
linux|darwin|freebsd|dragonfly|illumos|aix) echo "$os" ;;
*) echo "Unsupported OS: $os" >&2; exit 1 ;;
esac
}
# Detect architecture
get_arch() {
arch=$(uname -m)
case "$arch" in
x86_64) echo "amd64" ;;
i386|i686) echo "386" ;;
armv7l|armv6l) echo "arm" ;;
aarch64|arm64) echo "arm64" ;;
riscv64) echo "riscv64" ;;
ppc64) echo "ppc64" ;;
*) echo "Unsupported architecture: $arch" >&2; exit 1 ;;
esac
}
# Ensure unzip is available
ensure_unzip() {
if ! command -v unzip >/dev/null 2>&1; then
echo "Installing unzip..."
if command -v apt-get >/dev/null 2>&1; then
apt-get update
apt-get install -y unzip
elif command -v dnf >/dev/null 2>&1; then
dnf install -y unzip
elif command -v yum >/dev/null 2>&1; then
yum install -y unzip
else
echo "❌ Please install unzip manually."
exit 1
fi
fi
}
# Install PingTunnel v2.8
install_pingtunnel() {
OS=$(get_os)
ARCH=$(get_arch)
FILE="pingtunnel_${OS}_${ARCH}.zip"
URL="https://github.com/esrrhs/pingtunnel/releases/download/${VERSION}/${FILE}"
echo "--------------------------------"
echo "Installing PingTunnel v${VERSION}"
echo "Detected OS: $OS"
echo "Detected Architecture: $ARCH"
echo "--------------------------------"
ensure_unzip
mkdir -p /opt/pingtunnel
cd /opt/pingtunnel
echo "Downloading: $URL"
if ! curl -fL --retry 3 -o "$FILE" "$URL"; then
echo "❌ Failed to download PingTunnel v${VERSION}"
exit 1
fi
echo "Extracting PingTunnel..."
if ! unzip -o "$FILE"; then
echo "❌ Failed to extract $FILE"
exit 1
fi
if [ ! -f pingtunnel ]; then
echo "❌ PingTunnel binary not found after extraction."
exit 1
fi
chmod +x pingtunnel
rm -f "$FILE"
echo "✅ PingTunnel v${VERSION} installed successfully."
}
# Create systemd service
create_service() {
echo "Creating systemd service..."
cat <<EOF > /etc/systemd/system/pingtunnel.service
[Unit]
Description=PingTunnel Server v${VERSION}
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=/opt/pingtunnel
ExecStart=/opt/pingtunnel/pingtunnel -type server -key ${PINGTUNNEL_KEY}
Restart=on-failure
RestartSec=5
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable pingtunnel
systemctl restart pingtunnel
if systemctl is-active --quiet pingtunnel; then
echo "✅ PingTunnel service is running."
else
echo "❌ PingTunnel service failed to start."
systemctl status pingtunnel --no-pager || true
exit 1
fi
}
# Show installation information
show_final_info() {
SERVER_IP=$(curl -fsS --max-time 10 https://api.ipify.org || echo "Unknown")
echo ""
echo "================================"
echo "✅ PingTunnel Installation Complete"
echo "================================"
echo "Version : ${VERSION}"
echo "Server IP : ${SERVER_IP}"
echo "Password : ${PINGTUNNEL_KEY}"
echo "Service : pingtunnel"
echo "Status : $(systemctl is-active pingtunnel)"
echo "================================"
echo ""
echo "Useful commands:"
echo " systemctl status pingtunnel"
echo " systemctl restart pingtunnel"
echo " systemctl stop pingtunnel"
echo " journalctl -u pingtunnel -f"
echo ""
}
# Main function
main() {
if [ "$(id -u)" -ne 0 ]; then
echo "❌ Please run this script as root (use sudo)."
exit 1
fi
# systemd is required
if ! command -v systemctl >/dev/null 2>&1; then
echo "❌ This installer requires systemd."
exit 1
fi
# Check curl
if ! command -v curl >/dev/null 2>&1; then
echo "❌ curl is required. Please install curl first."
exit 1
fi
# Prompt user for PingTunnel key
while true; do
read -r -p "Enter a Password (Key) for PingTunnel (-key, numbers only): " PINGTUNNEL_KEY
if [[ "$PINGTUNNEL_KEY" =~ ^[0-9]+$ ]]; then
break
else
echo "❌ Please enter numbers only."
fi
done
install_pingtunnel
create_service
show_final_info
}
main