Update diy.sh

菜单添加非空判断。
This commit is contained in:
悟空的日常镜像仓库 2023-12-15 22:53:30 +08:00
parent 70e14154e6
commit efdf7a012f
1 changed files with 17 additions and 10 deletions

View File

@ -56,6 +56,12 @@ InitBanner() {
echo -e "" echo -e ""
} }
# 定义红色文本
RED='\033[0;31m'
# 无颜色
NC='\033[0m'
GREEN='\033[0;32m'
# 函数:检查并启动 SSH # 函数:检查并启动 SSH
enable_ssh() { enable_ssh() {
# 检查 openssh-server 是否安装 # 检查 openssh-server 是否安装
@ -261,11 +267,6 @@ install_fcitx5_chewing() {
# 设置开机自启动虚拟机virtualbox # 设置开机自启动虚拟机virtualbox
set_vm_autostart() { set_vm_autostart() {
# 定义红色文本
RED='\033[0;31m'
# 无颜色
NC='\033[0m'
GREEN='\033[0;32m'
# 显示带有红色文本的提示信息 # 显示带有红色文本的提示信息
echo -e echo -e
@ -427,8 +428,7 @@ menu_options=(
"安装常用办公必备软件(office、QQ、微信、远程桌面等)" "安装常用办公必备软件(office、QQ、微信、远程桌面等)"
"安装虚拟机VirtualBox 7" "安装虚拟机VirtualBox 7"
"安装虚拟机VirtualBox 7扩展包" "安装虚拟机VirtualBox 7扩展包"
"设置虚拟机开机无头自启动" "设置虚拟机开机自启动(headless)"
"卸载虚拟机"
"虚拟机一键格式转换(img2vdi)" "虚拟机一键格式转换(img2vdi)"
"准备CasaOS的使用环境" "准备CasaOS的使用环境"
"安装CasaOS(包含Docker)" "安装CasaOS(包含Docker)"
@ -436,6 +436,7 @@ menu_options=(
"卸载 CasaOS" "卸载 CasaOS"
"配置docker为国内镜像" "配置docker为国内镜像"
"安装btop资源监控工具" "安装btop资源监控工具"
"卸载虚拟机"
) )
commands=( commands=(
@ -443,7 +444,7 @@ commands=(
["安装虚拟机VirtualBox 7"]="install_virtualbox" ["安装虚拟机VirtualBox 7"]="install_virtualbox"
["安装虚拟机VirtualBox 7扩展包"]="install_virtualbox_extpack" ["安装虚拟机VirtualBox 7扩展包"]="install_virtualbox_extpack"
["虚拟机一键格式转换(img2vdi)"]="convert_vm_format" ["虚拟机一键格式转换(img2vdi)"]="convert_vm_format"
["设置虚拟机开机无头自启动"]="set_vm_autostart" ["设置虚拟机开机自启动(headless)"]="set_vm_autostart"
["卸载虚拟机"]="uninstall_vm" ["卸载虚拟机"]="uninstall_vm"
["准备CasaOS的使用环境"]="patch_os_release" ["准备CasaOS的使用环境"]="patch_os_release"
["安装CasaOS(包含Docker)"]="install_casaos" ["安装CasaOS(包含Docker)"]="install_casaos"
@ -453,7 +454,6 @@ commands=(
["安装常用办公必备软件(office、QQ、微信、远程桌面等)"]="install_need_apps" ["安装常用办公必备软件(office、QQ、微信、远程桌面等)"]="install_need_apps"
["安装注音输入法(新酷音输入法)"]="install_fcitx5_chewing" ["安装注音输入法(新酷音输入法)"]="install_fcitx5_chewing"
["安装btop资源监控工具"]="enable_btop" ["安装btop资源监控工具"]="enable_btop"
) )
show_menu() { show_menu() {
@ -482,6 +482,11 @@ show_menu() {
handle_choice() { handle_choice() {
local choice=$1 local choice=$1
# 检查输入是否为空
if [[ -z $choice ]]; then
echo -e "${RED}输入不能为空,请重新选择。${NC}"
return
fi
if [ -z "${menu_options[$choice - 1]}" ] || [ -z "${commands[${menu_options[$choice - 1]}]}" ]; then if [ -z "${menu_options[$choice - 1]}" ] || [ -z "${commands[${menu_options[$choice - 1]}]}" ]; then
echo "无效选项,请重新选择。" echo "无效选项,请重新选择。"
@ -491,12 +496,14 @@ handle_choice() {
"${commands[${menu_options[$choice - 1]}]}" "${commands[${menu_options[$choice - 1]}]}"
} }
# 主逻辑
while true; do while true; do
clear
show_menu show_menu
read -p "请输入选项的序号(输入q退出): " choice read -p "请输入选项的序号(输入q退出): " choice
if [[ $choice == 'q' ]]; then if [[ $choice == 'q' ]]; then
break break
fi fi
handle_choice $choice handle_choice $choice
echo "按任意键继续..."
read -n 1 # 等待用户按键
done done