29 lines
510 B
Bash
Executable File
29 lines
510 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
if [ $# -lt 1 ]
|
|
then
|
|
echo "Usage: $0 <username>"
|
|
exit 1
|
|
fi
|
|
|
|
if ! [ $EUID -eq 0 ]
|
|
then
|
|
echo "Must be root!" >&2
|
|
exit 1
|
|
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
|