Repository navigation
Expand file tree
/
Copy pathinstaller.sh
More file actions
238 lines (211 loc) · 7.58 KB
/
Copy pathinstaller.sh
File metadata and controls
238 lines (211 loc) · 7.58 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/bash
# Hiddify Core Universal Installer
# Supports OpenWrt, Ubuntu, Debian, CentOS, and other Linux distributions.
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}Hiddify Core Universal Installer${NC}"
# Check for root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run as root${NC}"
exit 1
fi
# Detect OS
OS="linux"
if [ -f /etc/openwrt_release ]; then
OS="openwrt"
echo -e "Detected OS: ${GREEN}OpenWrt${NC}"
elif [ -f /etc/os-release ]; then
. /etc/os-release
OS_NAME=$ID
echo -e "Detected OS: ${GREEN}$OS_NAME${NC}"
else
echo -e "Detected OS: ${GREEN}Generic Linux${NC}"
fi
# Detect Architecture
ARCH_RAW=$(uname -m)
case "$ARCH_RAW" in
x86_64) ARCH="amd64" ;;
i386|i686) ARCH="386" ;;
aarch64) ARCH="arm64" ;;
armv7*) ARCH="armv7" ;;
armv6*) ARCH="armv6" ;;
armv5*) ARCH="armv5" ;;
mips64el) ARCH="mips64le" ;;
mips64) ARCH="mips64" ;;
mipsel) ARCH="mipsle" ;;
mips) ARCH="mips" ;;
riscv64) ARCH="riscv64" ;;
ppc64le) ARCH="ppc64le" ;;
s390x) ARCH="s390x" ;;
*) echo -e "${RED}Unsupported architecture: $ARCH_RAW${NC}"; exit 1 ;;
esac
# Check for libc type (glibc vs musl) for Linux
LIBC=""
if [ "$OS" != "openwrt" ]; then
if ldd --version 2>&1 | grep -iq musl; then
LIBC="-musl"
elif ldd --version 2>&1 | grep -iq glibc; then
LIBC="-glibc"
fi
fi
# OpenWrt: the release ships a package for every OpenWrt architecture, in the format the router's
# package manager reads (opkg: .ipk, apk: .apk). The package brings the procd service, the UCI
# config and the sysupgrade keep list; running this installer again brings the next version. The
# tarball below is the fallback for an architecture with no package.
install_openwrt_package() {
local tag="$1" manager arch pkg url
if command -v apk >/dev/null 2>&1 && [ -d /etc/apk ]; then
manager=apk
arch=$(apk --print-arch 2>/dev/null)
elif command -v opkg >/dev/null 2>&1; then
manager=opkg
arch=$(opkg print-architecture 2>/dev/null | awk '{print $2}' | tail -n1)
else
return 1
fi
[ -n "$arch" ] || return 1
local version="${tag#v}"
case "$manager" in
# apk versions: 5.3.0 -> 5.3.0-r0, 5.3.0-beta.2 -> 5.3.0_beta2-r0 (as release/openwrt/build-apk.sh)
apk) pkg="hiddify-core-$(echo "$version" | sed -E 's/-([a-z]+)\.?([0-9]+)/_\1\2/; s/\.dev$/_pre0/')-r0_${arch}.apk" ;;
opkg) pkg="hiddify-core_${version}_${arch}.ipk" ;;
esac
url="https://github.com/$REPO/releases/download/$tag/$pkg"
echo -e "Installing ${BLUE}$pkg${NC} with $manager..."
if ! curl -fL "$url" -o "$WORKDIR/$pkg"; then
echo -e "No $manager package for ${arch} in $tag; falling back to the archive."
return 1
fi
case "$manager" in
apk) apk add --allow-untrusted "$WORKDIR/$pkg" ;;
opkg) opkg install "$WORKDIR/$pkg" ;;
esac || return 1
/etc/init.d/hiddify-core enable
/etc/init.d/hiddify-core restart
echo -e "${GREEN}Installation successful!${NC}"
echo -e "Config: /etc/hiddify-core/config.json (uci: /etc/config/hiddify-core)"
echo -e "Service: /etc/init.d/hiddify-core Logs: logread -e hiddify-core"
echo -e "Update: run this installer again"
return 0
}
# Determine artifact name
# Note: For OpenWrt, we usually prefer generic or musl.
# For standard Linux, we use the specific libc variant if available, otherwise generic.
ARTIFACT="hiddify-core-linux-${ARCH}${LIBC}.tar.gz"
# Fetch latest version
echo -e "Fetching latest version information..."
REPO="hiddify/hiddify-core"
LATEST_TAG=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST_TAG" ]; then
echo -e "${RED}Failed to fetch latest version tag. Attempting fallback...${NC}"
LATEST_TAG="v4.0.4" # Fallback
fi
WORKDIR=$(mktemp -d)
if [ "$OS" = "openwrt" ] && install_openwrt_package "$LATEST_TAG"; then
rm -rf "$WORKDIR"
exit 0
fi
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_TAG/$ARTIFACT"
echo -e "Downloading ${BLUE}$ARTIFACT${NC} ($LATEST_TAG)..."
curl -L "$DOWNLOAD_URL" -o "$WORKDIR/$ARTIFACT" || {
# If specific libc variant fails, try generic
if [ -n "$LIBC" ]; then
echo -e "Libc-specific artifact not found, trying generic..."
ARTIFACT="hiddify-core-linux-${ARCH}.tar.gz"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_TAG/$ARTIFACT"
curl -L "$DOWNLOAD_URL" -o "$WORKDIR/$ARTIFACT"
fi
}
# Install Binary
echo -e "Installing binary to /usr/bin/hiddify-core..."
tar -zxf "$WORKDIR/$ARTIFACT" -C "$WORKDIR"
# Find the binary in the tarball (it might be in a subdir or renamed)
BIN_PATH=$(find "$WORKDIR" -type f -name "hiddify*" -executable | head -n 1)
mv "$BIN_PATH" /usr/bin/hiddify-core
chmod +x /usr/bin/hiddify-core
# Setup Config
mkdir -p /etc/hiddify-core
if [ ! -f /etc/hiddify-core/config.json ]; then
echo -e "Creating default configuration..."
cat <<EOF > /etc/hiddify-core/config.json
{
"log": { "level": "info" },
"dns": { "servers": [{ "address": "tls://8.8.8.8" }] },
"inbounds": [{ "type": "shadowsocks", "listen": "::", "listen_port": 8080, "network": "tcp", "method": "2022-blake3-aes-128-gcm", "password": "Gn1JUS14bLUHgv1cWDDp4A==", "multiplex": { "enabled": true, "padding": true } }],
"outbounds": [{ "type": "direct" }, { "type": "dns", "tag": "dns-out" }],
"route": { "rules": [{ "port": 53, "outbound": "dns-out" }] }
}
EOF
fi
# Service Configuration
if [ "$OS" = "openwrt" ]; then
echo -e "Configuring ${GREEN}OpenWrt procd${NC} service..."
# UCI Config
if [ ! -f /etc/config/hiddify-core ]; then
cat <<EOF > /etc/config/hiddify-core
config hiddify-core 'main'
option enabled '1'
option conffile '/etc/hiddify-core/config.json'
option workdir '/usr/share/hiddify-core'
option log_stderr '1'
EOF
fi
# Init Script
cat <<'EOF' > /etc/init.d/hiddify-core
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=99
PROG="/usr/bin/hiddify-core"
start_service() {
config_load "hiddify-core"
local enabled conffile workdir log_stderr
config_get_bool enabled "main" "enabled" "0"
[ "$enabled" -eq "1" ] || return 0
config_get conffile "main" "conffile" "/etc/hiddify-core/config.json"
config_get workdir "main" "workdir" "/usr/share/hiddify-core"
config_get_bool log_stderr "main" "log_stderr" "1"
mkdir -p "$workdir"
procd_open_instance
procd_set_param command "$PROG" run -c "$conffile" -D "$workdir"
procd_set_param file "$conffile"
procd_set_param stderr "$log_stderr"
procd_set_param respawn
procd_close_instance
}
EOF
chmod +x /etc/init.d/hiddify-core
/etc/init.d/hiddify-core enable
/etc/init.d/hiddify-core restart
else
echo -e "Configuring ${GREEN}systemd${NC} service..."
# Systemd Service
cat <<EOF > /etc/systemd/system/hiddify-core.service
[Unit]
Description=hiddify-core service
After=network.target nss-lookup.target network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/hiddify-core -D /var/lib/hiddify-core run -c /etc/hiddify-core/config.json
Restart=on-failure
RestartSec=10s
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
EOF
mkdir -p /var/lib/hiddify-core
systemctl daemon-reload
systemctl enable hiddify-core
systemctl restart hiddify-core
fi
echo -e "${GREEN}Installation successful!${NC}"
echo -e "Binary: /usr/bin/hiddify-core"
echo -e "Config: /etc/hiddify-core/config.json"
if [ "$OS" = "openwrt" ]; then
echo -e "Service: /etc/init.d/hiddify-core"
else
echo -e "Service: systemctl status hiddify-core"
fi
rm -rf "$WORKDIR"