Last active
March 25, 2026 11:56
-
-
Save DartPower/01dc44b68c34ad8db84e637d121e592a to your computer and use it in GitHub Desktop.
Custom Hiddify Core Installer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Hiddify Core & CLI Installer | |
| # Minimalistic version for Service functionality | |
| set -e | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' | |
| echo -e "${BLUE}Hiddify Service 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" ;; | |
| riscv64) ARCH="riscv64" ;; | |
| *) echo -e "${RED}Unsupported architecture: $ARCH_RAW${NC}"; exit 1 ;; | |
| esac | |
| # Detect libc | |
| LIBC="" | |
| if [ "$OS" != "openwrt" ]; then | |
| if ldd --version 2>&1 | grep -iq musl; then | |
| LIBC="-musl" | |
| fi | |
| fi | |
| REPO="hiddify/hiddify-core" | |
| TARGET_VERSION="v4.0.3" | |
| WORKDIR=$(mktemp -d) | |
| # Function to download and install binary | |
| install_binary() { | |
| local ARTIFACT_NAME=$1 | |
| local BINARY_NAME=$2 | |
| local DOWNLOAD_URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/$ARTIFACT_NAME" | |
| echo -e "Downloading ${BLUE}$ARTIFACT_NAME${NC}..." | |
| # Try specific libc variant, fallback to generic | |
| if ! curl -L "$DOWNLOAD_URL" -o "$WORKDIR/$ARTIFACT_NAME" 2>/dev/null; then | |
| if [ -n "$LIBC" ]; then | |
| ARTIFACT_NAME="${ARTIFACT_NAME/$LIBC/}" | |
| DOWNLOAD_URL="https://github.com/$REPO/releases/download/$TARGET_VERSION/$ARTIFACT_NAME" | |
| curl -L "$DOWNLOAD_URL" -o "$WORKDIR/$ARTIFACT_NAME" || { echo -e "${RED}Failed to download $ARTIFACT_NAME${NC}"; return 1; } | |
| fi | |
| fi | |
| tar -zxf "$WORKDIR/$ARTIFACT_NAME" -C "$WORKDIR" | |
| # Find the binary (handles subdirectories in tar) | |
| local BIN_PATH=$(find "$WORKDIR" -type f -name "$BINARY_NAME" -o -name "hiddify-cli" | head -n 1) | |
| if [ -n "$BIN_PATH" ]; then | |
| mv "$BIN_PATH" "/usr/bin/$BINARY_NAME" | |
| chmod +x "/usr/bin/$BINARY_NAME" | |
| echo -e "Installed ${GREEN}/usr/bin/$BINARY_NAME${NC}" | |
| else | |
| echo -e "${RED}Binary $BINARY_NAME not found in archive${NC}" | |
| fi | |
| } | |
| # 1. Install Hiddify Core (Required for service) | |
| install_binary "hiddify-core-linux-${ARCH}${LIBC}.tar.gz" "hiddify-core" | |
| # 2. Install HiddifyCli (Required for management) | |
| install_binary "hiddify-cli-linux-${ARCH}${LIBC}.tar.gz" "HiddifyCli" | |
| # Setup Config Directory | |
| 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 | |
| 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 | |
| # 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 | |
| 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" | |
| mkdir -p "$workdir" | |
| procd_open_instance | |
| procd_set_param command "$PROG" run -c "$conffile" -D "$workdir" | |
| procd_set_param file "$conffile" | |
| 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 | |
| # Systemd (Standard Linux) | |
| echo -e "Configuring ${GREEN}systemd${NC} service..." | |
| # HiddifyCli needs to be able to find the core, so we ensure paths are correct | |
| mkdir -p /var/lib/hiddify-core | |
| cat <<EOF > /etc/systemd/system/hiddify-core.service | |
| [Unit] | |
| Description=Hiddify Core Service (Tunnel Engine) | |
| After=network.target nss-lookup.target network-online.target | |
| [Service] | |
| Type=simple | |
| # Запускаем именно ядро. Cli используется отдельно для обновления конфигов. | |
| ExecStart=/usr/bin/hiddify-core run -c /etc/hiddify-core/config.json -D /var/lib/hiddify-core | |
| Restart=on-failure | |
| RestartSec=10s | |
| LimitNOFILE=infinity | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOF | |
| systemctl daemon-reload | |
| systemctl enable hiddify-core | |
| systemctl restart hiddify-core | |
| fi | |
| rm -rf "$WORKDIR" | |
| echo -e "${GREEN}Installation complete!${NC}" | |
| echo -e "Binary (Core): /usr/bin/hiddify-core" | |
| echo -e "Binary (CLI): /usr/bin/HiddifyCli" | |
| echo -e "Config: /etc/hiddify-core/config.json" | |
| if [ "$OS" = "openwrt" ]; then | |
| echo -e "Manage service: /etc/init.d/hiddify-core start/stop" | |
| else | |
| echo -e "Manage service: systemctl start/stop hiddify-core" | |
| fi | |
| echo -e "${BLUE}Usage:${NC} Use 'HiddifyCli' command to manage subscriptions, service runs 'hiddify-core' automatically." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment