添加proxy快捷函数,添加controller提示信息
This commit is contained in:
12
activate
Normal file
12
activate
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
echo "=> Mihomo proxy functions activated"
|
||||||
|
function setproxy() {
|
||||||
|
local host=${1:-127.0.0.1} # 更改IP为您的代理软件监听IP, 默认127.0.0.1
|
||||||
|
local port=${2:-7890} # 更改端口为您的代理软件监听端口, 默认7890
|
||||||
|
export http_proxy=http://$host:$port && export https_proxy=$http_proxy
|
||||||
|
export no_proxy=localhost,127.0.0.1,::1,.localdomain
|
||||||
|
echo "- You've set the network proxy! Info: $http_proxy"
|
||||||
|
}
|
||||||
|
function unsetproxy() {
|
||||||
|
unset http_proxy && unset https_proxy && unset no_proxy
|
||||||
|
echo "- You've unset the network proxy!"
|
||||||
|
}
|
180
run.sh
180
run.sh
@@ -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"
|
MIHOMO_UI_URL="https://github.com/MetaCubeX/metacubexd/releases/download/v1.190.1/compressed-dist.tgz"
|
||||||
|
|
||||||
echo "mihomo-run (version:1.0)"
|
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")")
|
MH_DIR=$(dirname "$(readlink -f "$0")")
|
||||||
|
|
||||||
# 检查函数:检查核心文件、UI文件和进程状态
|
# 检查函数:检查核心文件、UI文件和进程状态
|
||||||
mihomo_check_environment() {
|
mihomo_check_environment() {
|
||||||
# Core Check
|
# Core Check
|
||||||
if [ ! -f "$MH_DIR/bin/mihomo" ]; then
|
if [ ! -f "$MH_DIR/bin/mihomo" ]; then
|
||||||
echo "=> Mihomo core is not found. Will download..."
|
echo "=> Mihomo core is not found. Will download..."
|
||||||
mkdir -p "$MH_DIR/bin"
|
mkdir -p "$MH_DIR/bin"
|
||||||
wget --show-progress -q "$MIHOMO_URL" -O "$MH_DIR/bin/mihomo.gz"
|
wget --show-progress -q "$MIHOMO_URL" -O "$MH_DIR/bin/mihomo.gz"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
gunzip -f "$MH_DIR/bin/mihomo.gz"
|
gunzip -f "$MH_DIR/bin/mihomo.gz"
|
||||||
chmod +x "$MH_DIR/bin/mihomo"
|
chmod +x "$MH_DIR/bin/mihomo"
|
||||||
else
|
else
|
||||||
echo "=> Mihomo core was failed to download!"
|
echo "=> Mihomo core was failed to download!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# UI Check
|
# UI Check
|
||||||
if [ ! -d "$MH_DIR/ui" ]; then
|
if [ ! -d "$MH_DIR/ui" ]; then
|
||||||
echo "=> UI static files are not found. Will download..."
|
echo "=> UI static files are not found. Will download..."
|
||||||
wget --show-progress -q "$MIHOMO_UI_URL" -O "$MH_DIR/ui.tgz"
|
wget --show-progress -q "$MIHOMO_UI_URL" -O "$MH_DIR/ui.tgz"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
mkdir -p "$MH_DIR/ui"
|
mkdir -p "$MH_DIR/ui"
|
||||||
tar -zxf "$MH_DIR/ui.tgz" -C "$MH_DIR/ui"
|
tar -zxf "$MH_DIR/ui.tgz" -C "$MH_DIR/ui"
|
||||||
rm "$MH_DIR/ui.tgz*"
|
rm "$MH_DIR/ui.tgz*"
|
||||||
else
|
else
|
||||||
echo "=> Mihomo UI tar was failed to download!"
|
echo "=> Mihomo UI tar was failed to download!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# mihomo process Check
|
# mihomo process Check
|
||||||
if pgrep -f "$MH_DIR/bin/mihomo" >/dev/null; then
|
if pgrep -f "$MH_DIR/bin/mihomo" >/dev/null; then
|
||||||
echo "=> Mihomo is already running!"
|
echo "=> Mihomo is already running!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Args解析
|
# Args解析
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"")
|
"")
|
||||||
# 执行环境检查
|
# 执行环境检查
|
||||||
mihomo_check_environment
|
mihomo_check_environment
|
||||||
|
|
||||||
# 如果没有任何参数,则应用配置 default
|
# 如果没有任何参数,则应用配置 default
|
||||||
CONFIG_FILE="$MH_DIR/profiles/default.yaml"
|
CONFIG_FILE="$MH_DIR/profiles/default.yaml"
|
||||||
if [ ! -f "$CONFIG_FILE" ]; then
|
if [ ! -f "$CONFIG_FILE" ]; then
|
||||||
echo "=> Default config file not found: $CONFIG_FILE"
|
echo "=> Default config file not found: $CONFIG_FILE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "=> Starting mihomo with default config..."
|
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"
|
"$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")
|
"use")
|
||||||
# 执行环境检查
|
# 执行环境检查
|
||||||
mihomo_check_environment
|
mihomo_check_environment
|
||||||
|
|
||||||
# 如果有use则解析$2 ,对应的是profiles中的对应的配置文件(不需要带.yaml 后缀)
|
# 如果有use则解析$2 ,对应的是profiles中的对应的配置文件(不需要带.yaml 后缀)
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
echo "=> Please specify a profile name"
|
echo "=> Please specify a profile name"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
CONFIG_FILE="$MH_DIR/profiles/$2.yaml"
|
CONFIG_FILE="$MH_DIR/profiles/$2.yaml"
|
||||||
if [ ! -f "$CONFIG_FILE" ]; then
|
if [ ! -f "$CONFIG_FILE" ]; then
|
||||||
echo "=> Config file not found: $CONFIG_FILE"
|
echo "=> Config file not found: $CONFIG_FILE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "=> Starting mihomo with profile: $2"
|
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"
|
"$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")
|
||||||
# list则为展示所有的profiles
|
# list则为展示所有的profiles
|
||||||
echo "=> Available profiles:"
|
echo "=> Available profiles:"
|
||||||
ls "$MH_DIR/profiles"/*.yaml | sed 's/.*profiles\/\(.*\)\.yaml/\1/'
|
ls "$MH_DIR/profiles"/*.yaml | sed 's/.*profiles\/\(.*\)\.yaml/\1/'
|
||||||
;;
|
;;
|
||||||
"stop")
|
"stop")
|
||||||
# stop则是终止mihomo进程
|
# stop则是终止mihomo进程
|
||||||
echo "=> Stopping mihomo..."
|
echo "=> Stopping mihomo..."
|
||||||
pkill -f "$MH_DIR/bin/mihomo"
|
pkill -f "$MH_DIR/bin/mihomo"
|
||||||
;;
|
;;
|
||||||
"help")
|
"help")
|
||||||
# help 打印帮助信息
|
# help 打印帮助信息
|
||||||
echo "Usage: $0 [command] [options]"
|
echo "Usage: $0 [command] [options]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " (no args) Start mihomo with default config"
|
echo " (no args) Start mihomo with default config"
|
||||||
echo " use [name] Start mihomo with specified profile"
|
echo " use [name] Start mihomo with specified profile"
|
||||||
echo " list List all available profiles"
|
echo " list List all available profiles"
|
||||||
echo " stop Stop mihomo process"
|
echo " stop Stop mihomo process"
|
||||||
echo " help Show this help message"
|
echo " help Show this help message"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " $0 Start with default config"
|
echo " $0 Start with default config"
|
||||||
echo " $0 use myconf Start with 'myconf' profile"
|
echo " $0 use myconf Start with 'myconf' profile"
|
||||||
echo " $0 list Show all profiles"
|
echo " $0 list Show all profiles"
|
||||||
echo " $0 stop Stop mihomo"
|
echo " $0 stop Stop mihomo"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid argument: $1"
|
echo "Invalid argument: $1"
|
||||||
echo "Use '$0 help' to see available commands"
|
echo "Use '$0 help' to see available commands"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
Reference in New Issue
Block a user