directus db 3

This commit is contained in:
Valentin 2024-02-23 18:05:07 +01:00
parent ea5ae902bb
commit 363db01044
1 changed files with 31 additions and 8 deletions

View File

@ -4,6 +4,15 @@ PURPLE='\033[35m'
BOLD='\033[1m'
RESET='\033[0m'
install_expect() {
if ! command -v expect &> /dev/null; then
sudo apt install -y expect
echo -e "${PURPLE}${BOLD}expect installed${RESET}"
else
echo -e "${PURPLE}${BOLD}expect already installed${RESET}"
fi
}
echo -e "${PURPLE}${BOLD}Deployment Debian + Caddy + Directus + Nuxt${RESET}"
if [ "$EUID" -ne 0 ]; then
@ -98,7 +107,7 @@ if [[ "$answer" == "y" ]]; then
echo -e "${PURPLE}${BOLD}Enter the MariaDB root password : ${RESET}"
read -s db_root_password
echo
apt -y install expect
install_expect
SECURE_MYSQL=$(expect -c "
set timeout 3
spawn mysql_secure_installation
@ -138,10 +147,24 @@ if [[ "$answer" == "y" ]]; then
echo -e "${PURPLE}${BOLD}Enter the MariaDB Directus password : ${RESET}"
read -s db_directus_password
echo
mysql -u root -p <<EOF
CREATE USER 'directus'@'localhost' IDENTIFIED BY '${db_password}';
CREATE DATABASE directus;
GRANT ALL PRIVILEGES ON directus.* TO 'directus'@'localhost' IDENTIFIED BY '${db_password}';
FLUSH PRIVILEGES;
EOF
fi
if [[ -z "$db_root_password" ]]; then
echo -e "${PURPLE}${BOLD}Enter the MariaDB root password : ${RESET}"
read -s db_root_password
echo
fi
install_expect
spawn mariadb -u root -p
expect "Enter password:"
send "$db_root_password\r"
expect "mysql>"
send "CREATE USER 'directus'@'localhost' IDENTIFIED BY '${db_directus_password}';\r"
send "CREATE DATABASE directus;\r"
send "GRANT ALL PRIVILEGES ON directus.* TO 'directus'@'localhost' IDENTIFIED BY '${db_directus_password}';\r"
send "FLUSH PRIVILEGES;\r"
expect "mysql>"
send "exit\r"
wait
fi
# TODO REMOVE EXPECT IF IT IS INSTALLED