diff options
author | Ian C <ianc@noddybox.co.uk> | 2018-06-21 15:31:26 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2018-06-21 15:31:26 +0000 |
commit | 87bbd53dbeb987e7cdd125a6ef15a48712a95368 (patch) | |
tree | 74aaaf4e677129052f280566e5c3cc929cb58093 /sql | |
parent | ddbae2d762e6807cf93989b9cd1c533cc3de05e6 (diff) |
Started SQL creation script.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/INSTALL | 1 | ||||
-rwxr-xr-x | sql/create_db.sh | 71 |
2 files changed, 72 insertions, 0 deletions
diff --git a/sql/INSTALL b/sql/INSTALL new file mode 100644 index 0000000..e78334c --- /dev/null +++ b/sql/INSTALL @@ -0,0 +1 @@ +Run the ./create_db.sh shell script to create the database. diff --git a/sql/create_db.sh b/sql/create_db.sh new file mode 100755 index 0000000..5b3fe17 --- /dev/null +++ b/sql/create_db.sh @@ -0,0 +1,71 @@ +Â#!/bin/sh + +drop="y" +echo "Drop existing database and user? (y/n) [$drop]" +read x + +if [ "$x" ] ; then + drop=$x +fi + +dbname="PassMan" +echo "Name of database to create [$dbname]:" +read x + +if [ "$x" ] ; then + dbname=$x +fi + +uname="PassMan" +echo "Name of database user to create [$uname]:" +read x + +if [ "$x" ] ; then + uname=$x +fi + +pword="PassMan" +echo "Password of database user [$pword]:" +read x + +if [ "$x" ] ; then + pword=$x +fi + +script=/tmp/$$ +rm -f $script +touch $script + +if [ "$drop" = "y" ] ; then + cat >> $script << END_OF_DROP +drop database $dbname; +delete from mysql.user where username='$uname'; +END_OF_DROP +fi + +cat >> $script << END_OF_SQL + +create database $dbname; +grant all on $dbname to '$uname'@'localhost' identified by '$pword'; +use $dbname; + +create table pm_user +( + name varchar(256) not null, + password varchar(256) not null, + constraint pk_pm_user primary key(name) +); + +create table pm_store +( + name varchar(256) not null, + description varchar(1024) not null, + username varchar(256) not null, + password varchar(256) not null + constraint pk_pm_user primary key(name, description) +); + +END_OF_SQL + +cat $script +rm -f $script |