#/bin/bash
#
# Shell script to set up the MySQL database for testing
#
# It creates two users:
# User: weewx1
# Password: weewx1
#
# User: weewx2
# Password: weewx2
#
# NB: user weewx2 has more restrictive permissions than user weewx1
#
echo "You may get an error 'Operation DROP USER failed' when running this script."
echo "This can be safely ignored."
echo "Give the root password when prompted->"
mysql --force -u root -p << EOF
drop user 'weewx'@'localhost';
drop user 'weewx1'@'localhost';
drop user 'weewx2'@'localhost';
create user 'weewx'@'localhost' identified by 'weewx';
create user 'weewx1'@'localhost' identified by 'weewx1';
create user 'weewx2'@'localhost' identified by 'weewx2';
grant select, update, create, delete, drop, insert on weewx.*          to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test.*           to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_weedb.*     to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_alt_weewx.* to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx.*     to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_sim.*       to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_dbd.*       to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx1.*    to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx2.*    to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx2.*    to 'weewx2'@'localhost';
grant select, update, create, delete, drop, insert on test_weedb.*     to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_alt_weewx.* to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx.*     to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_sim.*       to 'weewx1'@'localhost';
EOF
