#!/bin/bash # Function to create config.cfg based on user input create_config_file() { cat < config.cfg [options] database="$1" [mysql] mysqlconnect_path="/var/config/mysqlconnect.php" host="$2" username="$3" database="$4" password="$5" [sqlite] sqlite_password="$6" EOF } # Prompt user for database type echo "Do you want to use sqlite or mysql? (default: sqlite)" read -t 5 -p "Enter your choice: " db_choice # Set default value if no input is given db_choice=${db_choice:-sqlite} if [ "$db_choice" = "mysql" ]; then # Prompt user for MySQL options read -p "Enter MySQL host (default: localhost): " mysql_host mysql_host=${mysql_host:-localhost} read -p "Enter MySQL username (default: dbUser): " mysql_user mysql_user=${mysql_user:-dbUser} read -p "Enter MySQL database name (default: dbName): " mysql_db mysql_db=${mysql_db:-dbName} read -s -p "Enter MySQL password (default: dbPassword): " mysql_pass mysql_pass=${mysql_pass:-dbPassword} echo # Move to a new line after reading the password # Create config.cfg for MySQL create_config_file $db_choice $mysql_host $mysql_user $mysql_db $mysql_pass "" # Create directory for mysql configuration mkdir -p /var/config cp example.mysqlconnect.php /var/config/mysqlconnect.php chmod 755 /var/config/mysqlconnect.php elif [ "$db_choice" = "sqlite" ]; then # Prompt user for SQLite password read -s -p "Enter SQLite password (default: CHANGE_ME!): " sqlite_pass sqlite_pass=${sqlite_pass:-CHANGE_ME!} echo # Move to a new line after reading the password # Create config.cfg for SQLite create_config_file $db_choice "" "" "" "" $sqlite_pass # Create empty sqlite database php initialize_sqlite.php # Ensure the database directory and file have the correct permissions chmod 777 db chmod 777 config.cfg chmod 666 db/ddd_db.sqlite fi echo "Setup complete. Configuration saved in config.cfg."