re-worked writing db info

This commit is contained in:
Matthew Saunders Brown 2021-10-23 13:44:21 -07:00
parent e6639b04ce
commit 1b55808270

View File

@ -18,7 +18,8 @@ help()
echo " -d <domain> Domain name of VirtualHost to remove." echo " -d <domain> Domain name of VirtualHost to remove."
echo " -u <username> Username for accessing the database. Optional, autogenerated if none specified." echo " -u <username> Username for accessing the database. Optional, autogenerated if none specified."
echo " -p <password> Password for username. Optional, random password generated if none specified." echo " -p <password> Password for username. Optional, random password generated if none specified."
echo " -w Write db info to /home/username/.my.cnf. Warning! This inlcudes the unencrypted password." echo " -w Write db info to /srv/www/domain/.my.cnf and create include in"
echo " /home/username/.my.cnf. Warning! This includes the unencrypted password."
echo " -v Verbose - output newly created db info to console." echo " -v Verbose - output newly created db info to console."
echo "" echo ""
echo " MySQL database names is based on virtualhost with . replaced by the word 'dot'" echo " MySQL database names is based on virtualhost with . replaced by the word 'dot'"
@ -73,14 +74,19 @@ mysqladmin flush-privileges
# save mysql db info to file # save mysql db info to file
if [[ -n $write ]]; then if [[ -n $write ]]; then
touch /srv/www/$domain/.my.cnf
chown $vhost_username:$vhost_username /srv/www/$domain/.my.cnf
chmod 640 /srv/www/$domain/.my.cnf
echo '[client]' > /srv/www/$domain/.my.cnf
echo "host=127.0.0.1" >> /srv/www/$domain/.my.cnf
echo "database=$database" >> /srv/www/$domain/.my.cnf
echo "user=$username" >> /srv/www/$domain/.my.cnf
echo "password=$password" >> /srv/www/$domain/.my.cnf
touch /home/$vhost_username/.my.cnf touch /home/$vhost_username/.my.cnf
chown $vhost_username:$vhost_username /home/$vhost_username/.my.cnf chown $vhost_username:$vhost_username /home/$vhost_username/.my.cnf
chmod 640 /home/$vhost_username/.my.cnf chmod 640 /home/$vhost_username/.my.cnf
echo "[client]" > /home/$vhost_username/.my.cnf echo "#[client]" > /home/$vhost_username/.my.cnf
echo "host=127.0.0.1" >> /home/$vhost_username/.my.cnf echo '!include' "/srv/www/$domain/.my.cnf" >> /home/$vhost_username/.my.cnf
echo "database=$database" >> /home/$vhost_username/.my.cnf
echo "user=$username" >> /home/$vhost_username/.my.cnf
echo "password=$password" >> /home/$vhost_username/.my.cnf
fi fi
if [[ -n $verbose ]]; then if [[ -n $verbose ]]; then