setupUser shell script added locally
parent
dce5ea1bf3
commit
34b2b34e41
|
@ -145,7 +145,7 @@ actions:
|
|||
- log: Create user for DataBase
|
||||
- cmd [cp]: |-
|
||||
wget ${baseUrl}/configs/sqldb/wordpress.cnf -O /etc/mysql/conf.d/wordpress.cnf &>> /var/log/run.log;
|
||||
wget https://raw.githubusercontent.com/jelastic-jps/mysql-cluster/master/scripts/setupUser.sh -O ~/setupUser.sh &>> /var/log/run.log;
|
||||
wget scripts/setupUser.sh -O ~/setupUser.sh &>> /var/log/run.log;
|
||||
bash ~/setupUser.sh ${globals.DB_USER} ${globals.DB_PASS} &>> /var/log/run.log;
|
||||
jem passwd set -p ${globals.DB_PASS} &>> /var/log/run.log;
|
||||
user: root
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
USER=$1
|
||||
PASSWORD=$2
|
||||
ADMIN_PASSWORD=`pwgen 10 1`
|
||||
JEM=`which jem`
|
||||
MYSQL=`which mysql`
|
||||
cmd="CREATE USER '$USER'@'localhost' IDENTIFIED BY '$PASSWORD'; CREATE USER '$USER'@'%' IDENTIFIED BY '$PASSWORD'; GRANT ALL PRIVILEGES ON *.* TO '$USER'@'localhost' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO '$USER'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;"
|
||||
unset resp;
|
||||
resp=$(mysql -u$USER -p$PASSWORD mysql --execute="SHOW COLUMNS FROM user")
|
||||
[ -z "$resp" ] && {
|
||||
$JEM passwd set -p $ADMIN_PASSWORD
|
||||
$MYSQL -uroot -p${ADMIN_PASSWORD} --execute="$cmd"
|
||||
} || {
|
||||
echo "[Info] User $user has the required access to the database."
|
||||
}
|
Loading…
Reference in New Issue