Skip to content

Instantly share code, notes, and snippets.

@vinvin27
Created September 17, 2017 13:18
Show Gist options
  • Save vinvin27/e9a41449274b4bf8c280595e16c9ebf2 to your computer and use it in GitHub Desktop.
Save vinvin27/e9a41449274b4bf8c280595e16c9ebf2 to your computer and use it in GitHub Desktop.
DB Credentials generator :D
#!/bin/bash
DOMAIN=$1
if [ -z "${DOMAIN}" ]; then
echo "Syntax: $0 <domain.com>"
exit 1
fi
MYSQL_DB=${DOMAIN}
MYSQL_USER=$(echo ${DOMAIN} | sed 's/[^a-zA-Z0-9]//g' | cut -c1-15)
MYSQL_PASSWORD=$(date +%s | sha256sum | base64 | head -c 16 ; echo)
mysql --defaults-file=/etc/mysql/debian.cnf -e "CREATE DATABASE \`${MYSQL_DB}\`";
mysql --defaults-file=/etc/mysql/debian.cnf -e "GRANT ALL PRIVILEGES ON \`${MYSQL_DB}\`.* TO '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}'";
mysql --defaults-file=/etc/mysql/debian.cnf -e "FLUSH PRIVILEGES;";
echo
echo 'We are ready !'
echo "Point your browser to https://${DOMAIN} and have fun \!"
echo
echo "Database informations:"
echo " > name: ${MYSQL_DB}"
echo " > host: localhost"
echo " > login: ${MYSQL_USER}"
echo " > pass: ${MYSQL_PASSWORD}"
echo
echo "/END of script"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment