vmail: show documentation on hcoop wiki
[hcoop/domtool2.git] / src / plugins / domtool-mysql
CommitLineData
68d797e9 1#!/bin/bash -e
ae147938 2
c8cc5b95
AC
3WHERE="'%.hcoop.net'"
4
ae147938
AC
5case $1 in
6 adduser)
53cb7cc1
AC
7 USERNAME=$2
8 PASSWORD=$3
9
c8cc5b95 10 sudo -H mysql -e "CREATE USER '$USERNAME'@$WHERE IDENTIFIED BY '$PASSWORD';"
a431ca34 11 ;;
53cb7cc1 12
86aa5de7
AC
13 passwd)
14 USERNAME=$2
15 PASSWORD=$3
16
c8cc5b95 17 sudo -H mysql -e "SET PASSWORD FOR '$USERNAME'@$WHERE = PASSWORD('$PASSWORD');"
86aa5de7 18 ;;
a431ca34 19
ae147938 20 createdb)
216f7bc5
AC
21 USERNAME=$2
22 DBNAME_BASE=$3
23 DBNAME="${USERNAME}_${DBNAME_BASE}"
0a97b78a 24 DIR=/srv/databases/${USERNAME:0:1}/${USERNAME:0:2}/$USERNAME/mysql
216f7bc5 25
68d797e9 26 if [ ! -d $DIR ]; then
2464c83c
DO
27 echo WARNING: $DIR must already exist!
28 fi
29
6ee7d8ef 30 mkdir $DIR/$DBNAME
216f7bc5
AC
31 chown mysql:mysql $DIR/$DBNAME
32 chmod 770 $DIR/$DBNAME
33 ln -sf $DIR/$DBNAME /var/lib/mysql/$DBNAME
0a97b78a 34 chmod g+rw -R $DIR/$DBNAME/
fd53df8f 35 sudo -H mysql -e "GRANT CREATE,CREATE TEMPORARY TABLES,SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE VIEW,SHOW VIEW,LOCK TABLES,GRANT OPTION ON TABLE * TO '$USERNAME'@$WHERE;" $DBNAME
216f7bc5 36
216f7bc5 37 sudo -H mysql -e "FLUSH PRIVILEGES;"
ae147938 38 ;;
5ad00add
AC
39
40 dropdb)
41 USERNAME=$2
42 DBNAME_BASE=$3
43 DBNAME="${USERNAME}_${DBNAME_BASE}"
44
99cc4144
AC
45 sudo -H mysql -e "DROP DATABASE $DBNAME;"
46 ;;
47
48 grant)
49 USERNAME=$2
50 DBNAME_BASE=$3
51 DBNAME="${USERNAME}_${DBNAME_BASE}"
52
53 sudo -H mysql -e "GRANT CREATE,SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE VIEW,SHOW VIEW,LOCK TABLES,GRANT OPTION ON TABLE * TO '$USERNAME'@$WHERE;" $DBNAME
5ad00add
AC
54 ;;
55
ae147938 56 *)
99cc4144 57 echo "Usage: domtool-mysql [adduser <user> <password> | passwd <user> <password> | createdb <user> <db> | dropdb <user> <db> | grant <user> <db>]"
ae147938
AC
58 ;;
59esac