2018-09-13 07:43:21 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-10-19 15:27:33 +00:00
|
|
|
|
|
|
|
if [ $# -lt 1 ]
|
|
|
|
then
|
2018-09-13 07:43:21 +00:00
|
|
|
echo "Usage: $0 <username>"
|
|
|
|
exit 1
|
2014-10-19 15:27:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ $EUID -eq 0 ]
|
|
|
|
then
|
2018-09-13 07:43:21 +00:00
|
|
|
echo "Must be root!" >&2
|
|
|
|
exit 1
|
2014-10-19 15:27:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
USER="$1"
|
|
|
|
PASSWORD="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 64 | xargs)"
|
|
|
|
|
|
|
|
cat <<EOF | mysql --host mysql --user root --password=$(cat /etc/mysql.secret)
|
|
|
|
create database $USER;
|
|
|
|
grant usage on *.* to '$USER'@'%' identified by '$PASSWORD';
|
|
|
|
grant all privileges on $USER.* to '$USER'@'%';
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Password for user $USER is:"
|
|
|
|
echo
|
|
|
|
echo $PASSWORD
|
|
|
|
echo
|