-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathinstaller.sh
More file actions
126 lines (104 loc) · 2.95 KB
/
installer.sh
File metadata and controls
126 lines (104 loc) · 2.95 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
#!/bin/bash
set -e
# Detect OS
get_os() {
os=$(uname | tr '[:upper:]' '[:lower:]')
case "$os" in
linux|darwin|freebsd|dragonfly|illumos|aix) echo "$os" ;;
*) echo "Unsupported OS: $os"; 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"; exit 1 ;;
esac
}
# Get latest version from GitHub
get_latest_version() {
curl -s https://api.github.com/repos/esrrhs/pingtunnel/releases/latest \
| grep '"tag_name":' | sed -E 's/.*"v?([^"]+)".*/\1/'
}
# Ensure unzip is available
ensure_unzip() {
if ! command -v unzip >/dev/null 2>&1; then
echo "Installing unzip..."
if command -v apt >/dev/null 2>&1; then
apt update && apt 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() {
OS=$(get_os)
ARCH=$(get_arch)
VERSION=$(get_latest_version)
FILE="pingtunnel_${OS}_${ARCH}.zip"
URL="https://github.com/esrrhs/pingtunnel/releases/download/${VERSION}/${FILE}"
echo "Detected: OS=$OS ARCH=$ARCH"
echo "Downloading: $URL"
mkdir -p /opt/pingtunnel
cd /opt/pingtunnel
curl -fLO "$URL" || { echo "❌ Failed to download $FILE"; exit 1; }
ensure_unzip
unzip -o "$FILE" || { echo "❌ Failed to unzip $FILE"; exit 1; }
chmod +x pingtunnel
rm -f "$FILE"
}
create_service() {
echo "Creating systemd service..."
cat <<EOF > /etc/systemd/system/pingtunnel.service
[Unit]
Description=PingTunnel Server
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/pingtunnel
ExecStart=/opt/pingtunnel/pingtunnel -type server -key ${PINGTUNNEL_KEY}
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable pingtunnel
systemctl restart pingtunnel
echo "✅ pingtunnel service is running."
}
show_final_info() {
SERVER_IP=$(curl -s https://api.ipify.org)
echo ""
echo "✅ Installation complete."
echo "---------------------------"
echo "Server IP : $SERVER_IP"
echo "Password : $PINGTUNNEL_KEY"
echo "---------------------------"
}
main() {
if [ "$(id -u)" -ne 0 ]; then
echo "❌ Please run this script as root (use sudo)"
exit 1
fi
# Prompt user for PingTunnel key
while true; do
read -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