diff --git a/bin/vhost-mysql-db-add.sh b/bin/vhost-mysql-db-add.sh index 32a8e50..a868495 100755 --- a/bin/vhost-mysql-db-add.sh +++ b/bin/vhost-mysql-db-add.sh @@ -18,7 +18,8 @@ help() echo " -d Domain name of VirtualHost to remove." echo " -u Username for accessing the database. Optional, autogenerated if none specified." echo " -p 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 "" 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 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 chown $vhost_username:$vhost_username /home/$vhost_username/.my.cnf chmod 640 /home/$vhost_username/.my.cnf - echo "[client]" > /home/$vhost_username/.my.cnf - echo "host=127.0.0.1" >> /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 + echo "#[client]" > /home/$vhost_username/.my.cnf + echo '!include' "/srv/www/$domain/.my.cnf" >> /home/$vhost_username/.my.cnf fi if [[ -n $verbose ]]; then