From f5de874864423d22a18759a3bc6e1f86889cda9e Mon Sep 17 00:00:00 2001 From: Steven Hobs <47906512+stevenhobs@users.noreply.github.com> Date: Sun, 17 Aug 2025 20:18:03 +0800 Subject: [PATCH] init --- .gitignore | 5 ++ README.md | 3 ++ profiles/default.yaml | 9 ++++ run.sh | 111 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 profiles/default.yaml create mode 100755 run.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dd423e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +data/ +profiles/* +!profiles/default.yaml +ui/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..d4af2ce --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Mihomo-Run + +mihomo代理核心的快速启动脚本 \ No newline at end of file diff --git a/profiles/default.yaml b/profiles/default.yaml new file mode 100644 index 0000000..cc95113 --- /dev/null +++ b/profiles/default.yaml @@ -0,0 +1,9 @@ +# 默认端口(可修改) +port: 7890 +socks-port: 7891 +# 允许局域网连接 +allow-lan: false +# 运行模式(rule-规则模式,global-全局模式,direct-直连模式) +mode: rule +# 日志级别(info/warning/error/debug) +log-level: info \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..e30f7eb --- /dev/null +++ b/run.sh @@ -0,0 +1,111 @@ +#!/bin/bash +MIHOMO_CTL_AUTH="mihomo-run-123321" + +MIHOMO_URL="https://github.com/MetaCubeX/mihomo/releases/download/v1.19.12/mihomo-linux-amd64-v3-v1.19.12.gz" +MIHOMO_UI_URL="https://github.com/MetaCubeX/metacubexd/releases/download/v1.190.1/compressed-dist.tgz" + +echo "mihomo-run (version:1.0)" +MH_DIR=$(dirname "$(readlink -f "$0")") + +# 检查函数:检查核心文件、UI文件和进程状态 +mihomo_check_environment() { + # Core Check + if [ ! -f "$MH_DIR/bin/mihomo" ]; then + echo "=> Mihomo core is not found. Will download..." + mkdir -p "$MH_DIR/bin" + wget --show-progress -q "$MIHOMO_URL" -O "$MH_DIR/bin/mihomo.gz" + if [ $? -eq 0 ]; then + gunzip -f "$MH_DIR/bin/mihomo.gz" + chmod +x "$MH_DIR/bin/mihomo" + else + echo "=> Mihomo core was failed to download!" + exit 1 + fi + fi + + # UI Check + if [ ! -d "$MH_DIR/ui" ]; then + echo "=> UI static files are not found. Will download..." + wget --show-progress -q "$MIHOMO_UI_URL" -O "$MH_DIR/ui.tgz" + if [ $? -eq 0 ]; then + mkdir -p "$MH_DIR/ui" + tar -zxf "$MH_DIR/ui.tgz" -C "$MH_DIR/ui" + rm "$MH_DIR/ui.tgz*" + else + echo "=> Mihomo UI tar was failed to download!" + exit 1 + fi + fi + + # mihomo process Check + if pgrep -f "$MH_DIR/bin/mihomo" >/dev/null; then + echo "=> Mihomo is already running!" + exit 1 + fi +} + +# Args解析 +case "$1" in + "") + # 执行环境检查 + mihomo_check_environment + + # 如果没有任何参数,则应用配置 default + CONFIG_FILE="$MH_DIR/profiles/default.yaml" + if [ ! -f "$CONFIG_FILE" ]; then + echo "=> Default config file not found: $CONFIG_FILE" + exit 1 + fi + echo "=> Starting mihomo with default config..." + "$MH_DIR/bin/mihomo" -d "$MH_DIR/data" -f "$CONFIG_FILE" -ext-ui "$MH_DIR/ui" -ext-ctl 0.0.0.0:19090 -secret "$MIHOMO_CTL_AUTH" + ;; + "use") + # 执行环境检查 + mihomo_check_environment + + # 如果有use则解析$2 ,对应的是profiles中的对应的配置文件(不需要带.yaml 后缀) + if [ -z "$2" ]; then + echo "=> Please specify a profile name" + exit 1 + fi + CONFIG_FILE="$MH_DIR/profiles/$2.yaml" + if [ ! -f "$CONFIG_FILE" ]; then + echo "=> Config file not found: $CONFIG_FILE" + exit 1 + fi + echo "=> Starting mihomo with profile: $2" + "$MH_DIR/bin/mihomo" -d "$MH_DIR/data" -f "$CONFIG_FILE" -ext-ui "$MH_DIR/ui" -ext-ctl 0.0.0.0:19090 -secret "$MIHOMO_CTL_AUTH" + ;; + "list") + # list则为展示所有的profiles + echo "=> Available profiles:" + ls "$MH_DIR/profiles"/*.yaml | sed 's/.*profiles\/\(.*\)\.yaml/\1/' + ;; + "stop") + # stop则是终止mihomo进程 + echo "=> Stopping mihomo..." + pkill -f "$MH_DIR/bin/mihomo" + ;; + "help") + # help 打印帮助信息 + echo "Usage: $0 [command] [options]" + echo "" + echo "Commands:" + echo " (no args) Start mihomo with default config" + echo " use [name] Start mihomo with specified profile" + echo " list List all available profiles" + echo " stop Stop mihomo process" + echo " help Show this help message" + echo "" + echo "Examples:" + echo " $0 Start with default config" + echo " $0 use myconf Start with 'myconf' profile" + echo " $0 list Show all profiles" + echo " $0 stop Stop mihomo" + ;; + *) + echo "Invalid argument: $1" + echo "Use '$0 help' to see available commands" + exit 1 + ;; +esac