Commit f82bed65 authored by Chris Croome's avatar Chris Croome

Quick script to create a ~/.my.cnf file

parent 50bd50d1
Pipeline #12947 failed with stage
in 1 minute and 18 seconds
#!/usr/bin/env bash
# Set username to $1
if [[ "${1}" ]]; then
MYSQL_USER="${1}"
else
echo "A username needs to be provided as the first argument"
exit 1
fi
# Set password to $2
if [[ "${2}" ]]; then
MYSQL_PASSWD="${2}"
else
echo "A pasword needs to be provided as the second argument"
exit 1
fi
# Check if the file exists
if [[ -f "/home/${MYSQL_USER}/.my.cnf" ]]; then
echo "/home/${MYSQL_USER}/.my.cnf already exists, best edit it manually"
exit 1
else
echo "# Manually created" > /home/${MYSQL_USER}/.my.cnf
echo "" >> /home/${MYSQL_USER}/.my.cnf
echo "[client]" >> /home/${MYSQL_USER}/.my.cnf
echo "user=\"${MYSQL_USER}\"" >> /home/${MYSQL_USER}/.my.cnf
echo "password=\"${MYSQL_PASSWORD}\"" >> /home/${MYSQL_USER}/.my.cnf
chown ${MYSQL_USER}:${MYSQL_USER} /home/${MYSQL_USER}/.my.cnf
chmod 600 /home/${MYSQL_USER}/.my.cnf
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment