28 lines
585 B
Bash
Executable File
28 lines
585 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
PWGEN=`which pwgen`
|
|
if [ -z "${PWGEN}" ];
|
|
then
|
|
echo "Could not finf \"pwgen\" binary"
|
|
exit 1
|
|
fi
|
|
|
|
AUTOGEN_PASSWORD=`pwgen -n1 -v 40`
|
|
USERNAME="$1"
|
|
|
|
if [ -z "${USERNAME}" ];
|
|
then
|
|
echo "Missing username"
|
|
exit 1
|
|
fi
|
|
|
|
cat <<EOF
|
|
CREATE USER '${USERNAME}'@'localhost' IDENTIFIED BY '${AUTOGEN_PASSWORD}';
|
|
GRANT ALL PRIVILEGES ON *.* TO '${USERNAME}'@'localhost' WITH GRANT OPTION;
|
|
CREATE USER '${USERNAME}'@'%' IDENTIFIED BY '${AUTOGEN_PASSWORD}';
|
|
GRANT ALL PRIVILEGES ON *.* TO '${USERNAME}'@'%' WITH GRANT OPTION;
|
|
SHOW GRANTS FOR ${USERNAME};
|
|
FLUSH PRIVILEGES;
|
|
EOF
|
|
|