添加proxy快捷函数,添加controller提示信息

This commit is contained in:
Steven Hobs
2025-08-23 00:13:15 +08:00
parent f5de874864
commit ea68743d89
2 changed files with 103 additions and 89 deletions

180
run.sh
View File

@@ -5,107 +5,109 @@ MIHOMO_URL="https://github.com/MetaCubeX/mihomo/releases/download/v1.19.12/mihom
MIHOMO_UI_URL="https://github.com/MetaCubeX/metacubexd/releases/download/v1.190.1/compressed-dist.tgz"
echo "mihomo-run (version:1.0)"
echo "ui controller: http://localhost:19090/ui"
echo "ui secret: $MIHOMO_CTL_AUTH"
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
# 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
# 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
# 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
"")
# 执行环境检查
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
# 如果没有任何参数,则应用配置 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
;;
# 如果有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