deployment-dcdn/bin/setup_directus_db.sh

35 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2024-05-02 23:54:06 +02:00
#!/bin/bash
. bin/variables.sh
. bin/functions.sh
if ! dpkg -s mariadb-server >/dev/null 2>&1; then
. bin/install_mariadb.sh
fi
echo -e "${ORANGE}${BOLD}Generate and store the password somewhere safe${RESET}"
echo -e "${PURPLE}${BOLD}Enter the MariaDB Directus password : ${RESET}"
read -s DB_DIRECTUS_PASSWORD
echo
if [[ -z "$DB_ROOT_PASSWORD" ]]; then
echo -e "${PURPLE}${BOLD}Enter the MariaDB root password : ${RESET}"
read -s DB_ROOT_PASSWORD
echo
fi
install_pkg expect
create_directus_db=$(expect -c "
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 \"quit;\r\"
expect eof
")
echo "${create_directus_db}" >& /dev/null
echo -e "${PURPLE}Directus database created${RESET}"