* Remove the 'adduser' code which has been moved to create-user script.
[hcoop/domtool2.git] / src / plugins / domtool-mysql
CommitLineData
ae147938
AC
1#!/bin/sh -e
2
3case $1 in
4 adduser)
2464c83c 5 echo MySQL user was already created during create-user.
ae147938 6 ;;
86aa5de7
AC
7 passwd)
8 USERNAME=$2
9 PASSWORD=$3
10
11 sudo -H mysql -e "SET PASSWORD FOR '$USERNAME'@'localhost' = PASSWORD('$PASSWORD');"
12 ;;
ae147938 13 createdb)
216f7bc5
AC
14 USERNAME=$2
15 DBNAME_BASE=$3
16 DBNAME="${USERNAME}_${DBNAME_BASE}"
17 DIR=/afs/hcoop.net/common/databases/$USERNAME/mysql
18
19 kinit -k -t /etc/keytabs/root.admin.keytab root/admin
20 aklog
21
2464c83c
DO
22 if ! -d $DIR; then
23 echo WARNING: $DIR must already exist!
24 fi
25
6ee7d8ef 26 mkdir $DIR/$DBNAME
216f7bc5
AC
27 chown mysql:mysql $DIR/$DBNAME
28 chmod 770 $DIR/$DBNAME
29 ln -sf $DIR/$DBNAME /var/lib/mysql/$DBNAME
4cbaa5a7 30 fs setacl -dir $DIR/$DBNAME/ -acl system:mysql all
216f7bc5 31
6ee7d8ef 32 sudo -H mysql -e "GRANT CREATE,SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE VIEW,SHOW VIEW,GRANT OPTION ON TABLE * TO '$USERNAME'@'localhost';" $DBNAME
216f7bc5 33 sudo -H mysql -e "FLUSH PRIVILEGES;"
ae147938
AC
34 ;;
35 *)
86aa5de7 36 echo "Usage: domtool-mysql [adduser <user> <password> | passwd <user> <password> | createdb <user> <table>]"
ae147938
AC
37 ;;
38esac