2022-02-22 23:41:47 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
PWGEN=`which pwgen`
|
|
|
|
if [ -z "${PWGEN}" ];
|
|
|
|
then
|
2023-11-27 19:37:49 +02:00
|
|
|
echo "Could not find \"pwgen\" binary"
|
2022-02-22 23:41:47 +02:00
|
|
|
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
|
|
|
|
|