Add setsa in default Makefile target
[hcoop/domtool2.git] / src / plugins / domtool-mysql
dissimilarity index 71%
index 9d02fc4..5873ec9 100755 (executable)
@@ -1,13 +1,43 @@
-#!/bin/sh -e
-
-case $1 in
-       adduser)
-               echo "I would create MySQL user $2."
-       ;;
-       createdb)
-               echo "I would create MySQL table $2_$3 for user $2."
-       ;;
-       *)
-               echo "Usage: domtool-mysql [adduser <user> | createdb <user> <table>]"
-       ;;
-esac
+#!/bin/sh -e
+
+case $1 in
+       adduser)
+               USERNAME=$2
+               PASSWORD=$3
+
+               kinit -k -t /etc/keytabs/root.admin.keytab root/admin
+               aklog
+
+               vos create -server afs -partition a -name db.$USERNAME -maxquota 5000
+               fs mkmount -dir /afs/.hcoop.net/common/.databases/$USERNAME -vol db.$USERNAME -rw
+               vos release common.databases
+               fs setacl -dir /afs/hcoop.net/common/databases/$USERNAME -acl databases l
+               fs setacl -dir /afs/hcoop.net/common/databases/$USERNAME -acl system:backup rl
+               sudo -H mysql -e "CREATE USER '$USERNAME'@'localhost' IDENTIFIED BY '$PASSWORD';"
+       ;;
+       createdb)
+               USERNAME=$2
+               DBNAME_BASE=$3
+               DBNAME="${USERNAME}_${DBNAME_BASE}"
+               DIR=/afs/hcoop.net/common/databases/$USERNAME/mysql
+
+               kinit -k -t /etc/keytabs/root.admin.keytab root/admin
+               aklog
+
+               mkdir -p $DIR
+               fs setacl -dir $DIR -acl mysql rlid
+               fs setacl -dir $DIR -acl databases none
+               fs setacl -dir $DIR -acl system:backup rl
+               mkdir $DIR/$DBNAME || exit
+               chown mysql:mysql $DIR/$DBNAME
+               chmod 770 $DIR/$DBNAME
+               ln -sf $DIR/$DBNAME /var/lib/mysql/$DBNAME
+               fs setacl -dir $DIR/$DBNAME/ -acl mysql all
+
+               sudo -H mysql -e "GRANT CREATE,DROP,SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE VIEW,SHOW VIEW,GRANT OPTION ON * TO '$USERNAME'@'localhost';" $DBNAME
+               sudo -H mysql -e "FLUSH PRIVILEGES;"
+       ;;
+       *)
+               echo "Usage: domtool-mysql [adduser <user> <password> | createdb <user> <table>]"
+       ;;
+esac