Initial mod_waklog support
[hcoop/domtool2.git] / src / plugins / domtool-mysql
CommitLineData
ae147938
AC
1#!/bin/sh -e
2
3case $1 in
4 adduser)
c773e9e4
AC
5 USERNAME=$2
6 PASSWORD=$3
216f7bc5 7
c773e9e4
AC
8 kinit -k -t /etc/keytabs/root.admin.keytab root/admin
9 aklog
216f7bc5 10
6ee7d8ef
AC
11 if ! vos examine db.$USERNAME >/dev/null 2>/dev/null; then
12 vos create -server afs -partition a -name db.$USERNAME -maxquota 5000
13 fs mkmount -dir /afs/.hcoop.net/common/.databases/$USERNAME -vol db.$USERNAME -rw
a215ab4e 14 vos release common.databases
4cbaa5a7
AC
15 fs setacl -dir /afs/hcoop.net/common/databases/$USERNAME -acl system:postgres l
16 fs setacl -dir /afs/hcoop.net/common/databases/$USERNAME -acl system:mysql l
6ee7d8ef
AC
17 fs setacl -dir /afs/hcoop.net/common/databases/$USERNAME -acl system:backup rl
18 fi
19
216f7bc5 20 sudo -H mysql -e "CREATE USER '$USERNAME'@'localhost' IDENTIFIED BY '$PASSWORD';"
ae147938 21 ;;
86aa5de7
AC
22 passwd)
23 USERNAME=$2
24 PASSWORD=$3
25
26 sudo -H mysql -e "SET PASSWORD FOR '$USERNAME'@'localhost' = PASSWORD('$PASSWORD');"
27 ;;
ae147938 28 createdb)
216f7bc5
AC
29 USERNAME=$2
30 DBNAME_BASE=$3
31 DBNAME="${USERNAME}_${DBNAME_BASE}"
32 DIR=/afs/hcoop.net/common/databases/$USERNAME/mysql
33
34 kinit -k -t /etc/keytabs/root.admin.keytab root/admin
35 aklog
36
37 mkdir -p $DIR
4cbaa5a7 38 fs setacl -dir $DIR -acl system:mysql rlid
216f7bc5 39 fs setacl -dir $DIR -acl system:backup rl
6ee7d8ef 40 mkdir $DIR/$DBNAME
216f7bc5
AC
41 chown mysql:mysql $DIR/$DBNAME
42 chmod 770 $DIR/$DBNAME
43 ln -sf $DIR/$DBNAME /var/lib/mysql/$DBNAME
4cbaa5a7 44 fs setacl -dir $DIR/$DBNAME/ -acl system:mysql all
216f7bc5 45
6ee7d8ef 46 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 47 sudo -H mysql -e "FLUSH PRIVILEGES;"
ae147938
AC
48 ;;
49 *)
86aa5de7 50 echo "Usage: domtool-mysql [adduser <user> <password> | passwd <user> <password> | createdb <user> <table>]"
ae147938
AC
51 ;;
52esac