From 1215d6adec16072a9d6dd8ab79ec86355fce6e14 Mon Sep 17 00:00:00 2001 From: Akatsukiro Date: Mon, 22 Jan 2024 17:21:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=EF=BC=8C=E5=B9=B6=E5=B0=86=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=86=85=E5=AE=B9=E8=BE=93=E5=87=BA=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index e54632e..db6375b 100644 --- a/install.sh +++ b/install.sh @@ -202,9 +202,6 @@ install_maraidb() { esac } -# TODO -# 自动设置数据库,并将用户名、数据库名与密码打印出来 - install_php install_apache install_maraidb @@ -212,9 +209,24 @@ install_maraidb setup_database() { echo -e "${green}开始配置数据库${plain}" echo -e "${yellow}请无比妥善保存以下信息${plain}" - read -e -r -p "请输入数据库用户名: " db_user - read -e -r -p "请输入数据库名称: " db_name - read -e -r -p "请输入数据库密码: " db_password + echo "自动生成数据库信息请输入1,手动输入请输入2,其他情况自动生成" + read -e -r -p "请输入您的选择: " dbFlag + if [[ $dbFlag == "1" ]]; then + db_user="lsky" + db_name="lsky" + db_password=$(openssl rand -base64 12) + elif [[ $dbFlag == "2" ]]; then + read -e -r -p "请输入数据库用户名: " db_user + read -e -r -p "请输入数据库名称: " db_name + read -e -r -p "请输入数据库密码: " db_password + else + db_user="lsky_$(openssl rand -base64 12 | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)" + db_name="lsky_$(openssl rand -base64 12 | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)" + db_password="$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)" + fi + echo -e "${yellow}数据库用户名: ${db_user}${plain}" + echo -e "${yellow}数据库名称: ${db_name}${plain}" + echo -e "${yellow}数据库密码: ${db_password}${plain}" mysql -e "CREATE DATABASE IF NOT EXISTS ${db_name} DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;" mysql -e "GRANT ALL PRIVILEGES ON ${db_name}.* TO '${db_user}'@'localhost' IDENTIFIED BY '${db_password}';" mysql -e "FLUSH PRIVILEGES;"