修复脚本路径问题
This commit is contained in:
parent
1774606938
commit
a337436c3a
56
run.sh
56
run.sh
@ -1,43 +1,41 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [[ $UID != 0 ]]; then
|
if [[ $UID != 0 ]]; then
|
||||||
echo "请以root权限执行该脚本"
|
echo "请以root权限执行该脚本"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
declare -a function_array
|
declare -a function_array
|
||||||
declare selected_function
|
declare selected_function
|
||||||
declare script_path=$(dirname $0)
|
declare script_path=$(dirname $(readlink -f $0))
|
||||||
script_path="${script_path}/Config"
|
script_path="${script_path}/Config"
|
||||||
declare local_path=$script_path
|
declare local_path=$script_path
|
||||||
declare script_name
|
declare script_name
|
||||||
|
|
||||||
while true
|
while true; do
|
||||||
do
|
# 1. 目录初始化脚本 _init.sh
|
||||||
# 1. 目录初始化脚本 _init.sh
|
if [[ -e "${local_path}/_init.sh" ]]; then
|
||||||
if [[ -e "${local_path}/_init.sh" ]]; then
|
|
||||||
bash "${local_path}/_init.sh"
|
bash "${local_path}/_init.sh"
|
||||||
if [[ $? -eq 1 ]]; then
|
if [[ $? -eq 1 ]]; then
|
||||||
local_path=$script_path
|
local_path=$script_path
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. 完全替代菜单 _menu.sh
|
# 2. 完全替代菜单 _menu.sh
|
||||||
if [[ -e "${local_path}/_menu.sh" ]]; then
|
if [[ -e "${local_path}/_menu.sh" ]]; then
|
||||||
clear
|
clear
|
||||||
bash "${local_path}/_menu.sh" "$local_path"
|
bash "${local_path}/_menu.sh" "$local_path"
|
||||||
local_path=$script_path
|
local_path=$script_path
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 默认菜单逻辑
|
# 默认菜单逻辑
|
||||||
selected_function=0
|
selected_function=0
|
||||||
function_array=()
|
function_array=()
|
||||||
echo "======$(basename $local_path .sh)======"
|
echo "======$(basename $local_path .sh)======"
|
||||||
for i in "${local_path}"/*
|
for i in "${local_path}"/*; do
|
||||||
do
|
script_name=$(awk -F '.' '{print $1}' <<<"$(basename $i)")
|
||||||
script_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
|
|
||||||
# 忽略特殊文件
|
# 忽略特殊文件
|
||||||
if [[ $script_name =~ ^_ ]]; then
|
if [[ $script_name =~ ^_ ]]; then
|
||||||
continue
|
continue
|
||||||
@ -45,14 +43,14 @@ do
|
|||||||
selected_function=$((selected_function + 1))
|
selected_function=$((selected_function + 1))
|
||||||
function_array[$selected_function]=$script_name
|
function_array[$selected_function]=$script_name
|
||||||
echo "${selected_function}.${function_array[$selected_function]}"
|
echo "${selected_function}.${function_array[$selected_function]}"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $local_path != $script_path ]]; then
|
if [[ $local_path != $script_path ]]; then
|
||||||
echo "输入任意返回主页"
|
echo "输入任意返回主页"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -p "请输入要使用的功能:" user_choice
|
read -p "请输入要使用的功能:" user_choice
|
||||||
if [[ "$user_choice" =~ ^[0-9]+$ ]] && [ "$user_choice" -ge 1 ] && [ "$user_choice" -le "${#function_array[*]}" ]; then
|
if [[ "$user_choice" =~ ^[0-9]+$ ]] && [ "$user_choice" -ge 1 ] && [ "$user_choice" -le "${#function_array[*]}" ]; then
|
||||||
clear
|
clear
|
||||||
selected_script="${function_array[$user_choice]}"
|
selected_script="${function_array[$user_choice]}"
|
||||||
|
|
||||||
@ -70,11 +68,11 @@ if [[ "$user_choice" =~ ^[0-9]+$ ]] && [ "$user_choice" -ge 1 ] && [ "$user_choi
|
|||||||
fi
|
fi
|
||||||
local_path=$script_path
|
local_path=$script_path
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ $local_path == $script_path ]]; then
|
if [[ $local_path == $script_path ]]; then
|
||||||
exit
|
exit
|
||||||
|
fi
|
||||||
|
local_path=$script_path
|
||||||
fi
|
fi
|
||||||
local_path=$script_path
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
done
|
Loading…
Reference in New Issue
Block a user