MySQL re-granting
[hcoop/domtool2.git] / src / plugins / domtool-mysql
CommitLineData
68d797e9 1#!/bin/bash -e
ae147938 2
c8cc5b95
AC
3WHERE="'%.hcoop.net'"
4
ae147938
AC
5case $1 in
6 adduser)
53cb7cc1
AC
7 USERNAME=$2
8 PASSWORD=$3
9
c8cc5b95 10 sudo -H mysql -e "CREATE USER '$USERNAME'@$WHERE IDENTIFIED BY '$PASSWORD';"
a431ca34 11 ;;
53cb7cc1 12
86aa5de7
AC
13 passwd)
14 USERNAME=$2
15 PASSWORD=$3
16
c8cc5b95 17 sudo -H mysql -e "SET PASSWORD FOR '$USERNAME'@$WHERE = PASSWORD('$PASSWORD');"
86aa5de7 18 ;;
a431ca34 19
ae147938 20 createdb)
216f7bc5
AC
21 USERNAME=$2
22 DBNAME_BASE=$3
23 DBNAME="${USERNAME}_${DBNAME_BASE}"
68d797e9 24 DIR=/afs/hcoop.net/common/databases/${USERNAME:0:1}/${USERNAME:0:2}/$USERNAME/mysql
216f7bc5
AC
25
26 kinit -k -t /etc/keytabs/root.admin.keytab root/admin
27 aklog
28
68d797e9 29 if [ ! -d $DIR ]; then
2464c83c
DO
30 echo WARNING: $DIR must already exist!
31 fi
32
6ee7d8ef 33 mkdir $DIR/$DBNAME
216f7bc5
AC
34 chown mysql:mysql $DIR/$DBNAME
35 chmod 770 $DIR/$DBNAME
36 ln -sf $DIR/$DBNAME /var/lib/mysql/$DBNAME
4cbaa5a7 37 fs setacl -dir $DIR/$DBNAME/ -acl system:mysql all
99cc4144 38 sudo -H mysql -e "GRANT CREATE,SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE VIEW,SHOW VIEW,LOCK TABLES,GRANT OPTION ON TABLE * TO '$USERNAME'@$WHERE;" $DBNAME
216f7bc5 39
216f7bc5 40 sudo -H mysql -e "FLUSH PRIVILEGES;"
ae147938 41 ;;
5ad00add
AC
42
43 dropdb)
44 USERNAME=$2
45 DBNAME_BASE=$3
46 DBNAME="${USERNAME}_${DBNAME_BASE}"
47
99cc4144
AC
48 sudo -H mysql -e "DROP DATABASE $DBNAME;"
49 ;;
50
51 grant)
52 USERNAME=$2
53 DBNAME_BASE=$3
54 DBNAME="${USERNAME}_${DBNAME_BASE}"
55
56 sudo -H mysql -e "GRANT CREATE,SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE VIEW,SHOW VIEW,LOCK TABLES,GRANT OPTION ON TABLE * TO '$USERNAME'@$WHERE;" $DBNAME
5ad00add
AC
57 ;;
58
ae147938 59 *)
99cc4144 60 echo "Usage: domtool-mysql [adduser <user> <password> | passwd <user> <password> | createdb <user> <db> | dropdb <user> <db> | grant <user> <db>]"
ae147938
AC
61 ;;
62esac