给查询和删除增加空判断

This commit is contained in:
lsy 2024-09-27 14:45:16 +08:00
parent 3e26629bc6
commit 778fb6ec59
3 changed files with 40 additions and 11 deletions

View File

@ -17,13 +17,26 @@ fi
case $pick in case $pick in
'1') '1')
echo "该系统安装了以下脚本" declare -a script_arr
declare script_name
declare script_number=0
for i in "$path"/* ; do for i in "$path"/* ; do
if [[ $i == "${path}/*" ]];then if [[ $i == "${path}/*" ]];then
echo "该地址不存在脚本" echo "该地址不存在脚本"
exit
fi fi
basename $i script_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
if [[ $script_name == "linuxtool" ]]; then
continue
fi
script_number=$(( script_number+1 ))
echo "${script_number}.${script_name}"
script_arr[$script_number]=$script_name
done done
if [ ${#script_arr[@]} == 0 ]; then
echo "该地址不存在脚本"
exit
fi
;; ;;
'2') '2')
declare -a script_arr declare -a script_arr
@ -42,9 +55,13 @@ case $pick in
echo "${script_number}.${script_name}" echo "${script_number}.${script_name}"
script_arr[$script_number]=$script_name script_arr[$script_number]=$script_name
done done
if [ ${#script_arr[@]} == 0 ]; then
echo "该地址不存在脚本"
exit
fi
read -p "请输入要删除的序号,多个用 空格 隔开:" script_name read -p "请输入要删除的序号,多个用 空格 隔开:" script_name
for i in $script_name ; do for i in $script_name ; do
if [[ $i =~ [1-${#script_arr[*]}] ]]; then if [[ $i =~ [1-${#script_arr[@]}] ]]; then
echo "开始删除 ${script_arr[$i]}" echo "开始删除 ${script_arr[$i]}"
(crontab -l 2>/dev/null | grep -v "${script_arr[$i]}") | crontab - && echo "已经删除脚本的自动任务" (crontab -l 2>/dev/null | grep -v "${script_arr[$i]}") | crontab - && echo "已经删除脚本的自动任务"
rm -rf "$path/${script_arr[$i]}" &> /dev/null rm -rf "$path/${script_arr[$i]}" &> /dev/null

View File

@ -20,6 +20,10 @@ case $pick in
print_arr[$print_number]=$print_name print_arr[$print_number]=$print_name
echo "${print_number}.${print_name}" echo "${print_number}.${print_name}"
done done
if [ ${#print_arr[@]} == 0 ]; then
echo "暂时没有安装证书"
exit
fi
read -p "请输入要查看证书详细信息的序号:" pick read -p "请输入要查看证书详细信息的序号:" pick
if [[ $pick =~ [1-${#print_arr[@]}] ]]; then if [[ $pick =~ [1-${#print_arr[@]}] ]]; then
bash "${HOME}/.acme.sh/acme.sh -info -d ${print_arr[$pick]}" bash "${HOME}/.acme.sh/acme.sh -info -d ${print_arr[$pick]}"

View File

@ -19,6 +19,10 @@ case $pick in
echo "${site_number}.${site_name}" echo "${site_number}.${site_name}"
site_arr[$site_number]=$site_name site_arr[$site_number]=$site_name
done done
if [ ${#site_arr[@]} == 0 ]; then
echo "暂时没有配置文件"
exit
fi
;; ;;
'2') '2')
declare -a site_arr declare -a site_arr
@ -34,6 +38,10 @@ case $pick in
echo "${site_number}.${site_name}" echo "${site_number}.${site_name}"
site_arr[$site_number]=$site_name site_arr[$site_number]=$site_name
done done
if [ ${#site_arr[@]} == 0 ]; then
echo "暂时没有配置文件"
exit
fi
read -p "请输入要删除的序号,多个用 空格 隔开:" site_name read -p "请输入要删除的序号,多个用 空格 隔开:" site_name
for i in $site_name ; do for i in $site_name ; do
if [[ $i =~ [1-${#site_arr[*]}] ]]; then if [[ $i =~ [1-${#site_arr[*]}] ]]; then