2024-07-01 01:24:28 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Function to create config.cfg based on user input
|
|
|
|
create_config_file() {
|
|
|
|
cat <<EOF > config.cfg
|
|
|
|
[options]
|
|
|
|
database="$1"
|
|
|
|
|
|
|
|
[mysql]
|
|
|
|
mysqlconnect_path="/var/config/mysqlconnect.php"
|
2024-07-01 02:59:14 -04:00
|
|
|
host="$2"
|
|
|
|
username="$3"
|
|
|
|
database="$4"
|
|
|
|
password="$5"
|
2024-07-01 01:24:28 -04:00
|
|
|
|
|
|
|
[sqlite]
|
2024-07-01 02:59:14 -04:00
|
|
|
sqlite_password="$6"
|
2024-07-01 01:24:28 -04:00
|
|
|
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
|
2024-07-01 02:59:14 -04:00
|
|
|
# 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
|
2024-07-01 01:24:28 -04:00
|
|
|
mkdir -p /var/config
|
|
|
|
cp example.mysqlconnect.php /var/config/mysqlconnect.php
|
|
|
|
chmod 755 /var/config/mysqlconnect.php
|
2024-07-01 02:59:14 -04:00
|
|
|
|
|
|
|
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
|
2024-07-01 01:24:28 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Setup complete. Configuration saved in config.cfg."
|