* Remove the 'adduser' code which has been moved to create-user script.
[hcoop/domtool2.git] / src / plugins / domtool-mysql
1 #!/bin/sh -e
2
3 case $1 in
4 adduser)
5 echo MySQL user was already created during create-user.
6 ;;
7 passwd)
8 USERNAME=$2
9 PASSWORD=$3
10
11 sudo -H mysql -e "SET PASSWORD FOR '$USERNAME'@'localhost' = PASSWORD('$PASSWORD');"
12 ;;
13 createdb)
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
22 if ! -d $DIR; then
23 echo WARNING: $DIR must already exist!
24 fi
25
26 mkdir $DIR/$DBNAME
27 chown mysql:mysql $DIR/$DBNAME
28 chmod 770 $DIR/$DBNAME
29 ln -sf $DIR/$DBNAME /var/lib/mysql/$DBNAME
30 fs setacl -dir $DIR/$DBNAME/ -acl system:mysql all
31
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
33 sudo -H mysql -e "FLUSH PRIVILEGES;"
34 ;;
35 *)
36 echo "Usage: domtool-mysql [adduser <user> <password> | passwd <user> <password> | createdb <user> <table>]"
37 ;;
38 esac