fix: 修复 curl|sh 方式运行时无法找到子脚本的问题
This commit is contained in:
75
main.sh
75
main.sh
@@ -12,6 +12,7 @@ light_yellow() { echo -e "\033[93m\033[01m$1\033[0m"; }
|
|||||||
cyan() { echo -e "\033[38;2;0;255;255m$1\033[0m"; }
|
cyan() { echo -e "\033[38;2;0;255;255m$1\033[0m"; }
|
||||||
|
|
||||||
HTTP_HOST="https://cafe.cpolar.cn/wkdaily/gl/raw/branch/main"
|
HTTP_HOST="https://cafe.cpolar.cn/wkdaily/gl/raw/branch/main"
|
||||||
|
SCRIPT_DIR="/tmp/gl-scripts"
|
||||||
|
|
||||||
##获取软路由型号信息
|
##获取软路由型号信息
|
||||||
get_router_name() {
|
get_router_name() {
|
||||||
@@ -19,6 +20,22 @@ get_router_name() {
|
|||||||
echo "$model_info"
|
echo "$model_info"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## 下载并运行脚本
|
||||||
|
download_and_run_script() {
|
||||||
|
local script_name="$1"
|
||||||
|
mkdir -p "$SCRIPT_DIR"
|
||||||
|
local script_path="$SCRIPT_DIR/$script_name"
|
||||||
|
|
||||||
|
green "正在下载 $script_name..."
|
||||||
|
wget -O "$script_path" "$HTTP_HOST/$script_name" 2>/dev/null || {
|
||||||
|
red "下载 $script_name 失败"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
chmod +x "$script_path"
|
||||||
|
green "正在启动 $script_name..."
|
||||||
|
sh "$script_path"
|
||||||
|
}
|
||||||
|
|
||||||
## 自动检测路由器型号并调用对应脚本
|
## 自动检测路由器型号并调用对应脚本
|
||||||
auto_detect_and_run() {
|
auto_detect_and_run() {
|
||||||
gl_name=$(get_router_name)
|
gl_name=$(get_router_name)
|
||||||
@@ -26,42 +43,33 @@ auto_detect_and_run() {
|
|||||||
|
|
||||||
case "$gl_name" in
|
case "$gl_name" in
|
||||||
*BE6500* | *be6500*)
|
*BE6500* | *be6500*)
|
||||||
green "正在启动 BE6500 脚本..."
|
download_and_run_script "be6500.sh"
|
||||||
sh "$(dirname "$0")/be6500.sh"
|
|
||||||
;;
|
;;
|
||||||
*BE3600* | *be3600*)
|
*BE3600* | *be3600*)
|
||||||
green "正在启动 BE3600 脚本..."
|
download_and_run_script "be3600.sh"
|
||||||
sh "$(dirname "$0")/be3600.sh"
|
|
||||||
;;
|
;;
|
||||||
*MT5000* | *mt5000*)
|
*MT5000* | *mt5000*)
|
||||||
green "正在启动 MT5000 脚本..."
|
download_and_run_script "mt5000.sh"
|
||||||
sh "$(dirname "$0")/mt5000.sh"
|
|
||||||
;;
|
;;
|
||||||
*MT3600* | *mt3600*)
|
*MT3600* | *mt3600*)
|
||||||
green "正在启动 MT3600 脚本..."
|
download_and_run_script "mt3600.sh"
|
||||||
sh "$(dirname "$0")/mt3600.sh"
|
|
||||||
;;
|
;;
|
||||||
*MT-3000* | *mt3000* | *MT3000*)
|
*MT-3000* | *mt3000* | *MT3000*)
|
||||||
if grep -q "OP24" /etc/openwrt_release 2>/dev/null; then
|
if grep -q "OP24" /etc/openwrt_release 2>/dev/null; then
|
||||||
green "正在启动 MT-3000 OP24 脚本..."
|
download_and_run_script "gl-inet-op24.sh"
|
||||||
sh "$(dirname "$0")/gl-inet-op24.sh"
|
|
||||||
else
|
else
|
||||||
green "正在启动 MT-3000 脚本..."
|
download_and_run_script "gl-inet.sh"
|
||||||
sh "$(dirname "$0")/gl-inet.sh"
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*MT-6000* | *mt6000* | *MT6000*)
|
*MT-6000* | *mt6000* | *MT6000*)
|
||||||
if grep -q "OP24" /etc/openwrt_release 2>/dev/null; then
|
if grep -q "OP24" /etc/openwrt_release 2>/dev/null; then
|
||||||
green "正在启动 MT-6000 OP24 脚本..."
|
download_and_run_script "gl-inet-op24.sh"
|
||||||
sh "$(dirname "$0")/gl-inet-op24.sh"
|
|
||||||
else
|
else
|
||||||
green "正在启动 MT-6000 脚本..."
|
download_and_run_script "gl-inet.sh"
|
||||||
sh "$(dirname "$0")/gl-inet.sh"
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*MT-2500* | *mt2500* | *MT2500*)
|
*MT-2500* | *mt2500* | *MT2500*)
|
||||||
green "正在启动 MT-2500A 脚本..."
|
download_and_run_script "gl-inet.sh"
|
||||||
sh "$(dirname "$0")/gl-inet.sh"
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
red "抱歉,暂不支持该机型: $gl_name"
|
red "抱歉,暂不支持该机型: $gl_name"
|
||||||
@@ -96,41 +104,28 @@ select_model() {
|
|||||||
|
|
||||||
case $choice in
|
case $choice in
|
||||||
1)
|
1)
|
||||||
sh "$(dirname "$0")/be6500.sh"
|
download_and_run_script "be6500.sh"
|
||||||
;;
|
;;
|
||||||
2)
|
2)
|
||||||
sh "$(dirname "$0")/be3600.sh"
|
download_and_run_script "be3600.sh"
|
||||||
;;
|
;;
|
||||||
3)
|
3)
|
||||||
sh "$(dirname "$0")/mt5000.sh"
|
download_and_run_script "mt5000.sh"
|
||||||
;;
|
;;
|
||||||
4)
|
4)
|
||||||
sh "$(dirname "$0")/mt3600.sh"
|
download_and_run_script "mt3600.sh"
|
||||||
;;
|
;;
|
||||||
5 | 6 | 7)
|
5 | 6 | 7)
|
||||||
sh "$(dirname "$0")/gl-inet.sh"
|
download_and_run_script "gl-inet.sh"
|
||||||
;;
|
;;
|
||||||
8)
|
8 | 9)
|
||||||
sh "$(dirname "$0")/gl-inet-op24.sh"
|
download_and_run_script "gl-inet-op24.sh"
|
||||||
;;
|
|
||||||
9)
|
|
||||||
sh "$(dirname "$0")/gl-inet-op24.sh"
|
|
||||||
;;
|
;;
|
||||||
10)
|
10)
|
||||||
if [ -f "$(dirname "$0")/mt-3000/mt3000.sh" ]; then
|
download_and_run_script "mt-3000/mt3000.sh"
|
||||||
sh "$(dirname "$0")/mt-3000/mt3000.sh"
|
|
||||||
else
|
|
||||||
wget -O "$(dirname "$0")/mt-3000.sh" "$HTTP_HOST/mt-3000/mt3000.sh" && chmod +x "$(dirname "$0")/mt-3000.sh"
|
|
||||||
sh "$(dirname "$0")/mt-3000.sh"
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
11)
|
11)
|
||||||
if [ -f "$(dirname "$0")/docker/do_docker.sh" ]; then
|
download_and_run_script "docker/do_docker.sh"
|
||||||
sh "$(dirname "$0")/docker/do_docker.sh"
|
|
||||||
else
|
|
||||||
wget -O "$(dirname "$0")/do_docker.sh" "$HTTP_HOST/docker/do_docker.sh" && chmod +x "$(dirname "$0")/do_docker.sh"
|
|
||||||
sh "$(dirname "$0")/do_docker.sh"
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
q | Q)
|
q | Q)
|
||||||
echo "退出"
|
echo "退出"
|
||||||
|
|||||||
Reference in New Issue
Block a user