Change MySQL script to follow multi-level directory scheme
[hcoop/domtool2.git] / src / plugins / domtool-mysql
CommitLineData
68d797e9 1#!/bin/bash -e
ae147938
AC
2
3case $1 in
4 adduser)
53cb7cc1
AC
5 USERNAME=$2
6 PASSWORD=$3
7
8 sudo -H mysql -e "CREATE USER '$USERNAME'@'localhost' IDENTIFIED BY '$PASSWORD';"
a431ca34 9 ;;
53cb7cc1 10
86aa5de7
AC
11 passwd)
12 USERNAME=$2
13 PASSWORD=$3
14
15 sudo -H mysql -e "SET PASSWORD FOR '$USERNAME'@'localhost' = PASSWORD('$PASSWORD');"
16 ;;
a431ca34 17
ae147938 18 createdb)
216f7bc5
AC
19 USERNAME=$2
20 DBNAME_BASE=$3
21 DBNAME="${USERNAME}_${DBNAME_BASE}"
68d797e9 22 DIR=/afs/hcoop.net/common/databases/${USERNAME:0:1}/${USERNAME:0:2}/$USERNAME/mysql
216f7bc5
AC
23
24 kinit -k -t /etc/keytabs/root.admin.keytab root/admin
25 aklog
26
68d797e9 27 if [ ! -d $DIR ]; then
2464c83c
DO
28 echo WARNING: $DIR must already exist!
29 fi
30
6ee7d8ef 31 mkdir $DIR/$DBNAME
216f7bc5
AC
32 chown mysql:mysql $DIR/$DBNAME
33 chmod 770 $DIR/$DBNAME
34 ln -sf $DIR/$DBNAME /var/lib/mysql/$DBNAME
4cbaa5a7 35 fs setacl -dir $DIR/$DBNAME/ -acl system:mysql all
216f7bc5 36
6ee7d8ef 37 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 38 sudo -H mysql -e "FLUSH PRIVILEGES;"
ae147938
AC
39 ;;
40 *)
86aa5de7 41 echo "Usage: domtool-mysql [adduser <user> <password> | passwd <user> <password> | createdb <user> <table>]"
ae147938
AC
42 ;;
43esac