From 87bbd53dbeb987e7cdd125a6ef15a48712a95368 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 21 Jun 2018 15:31:26 +0000 Subject: Started SQL creation script. --- sql/INSTALL | 1 + sql/create_db.sh | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 sql/INSTALL create mode 100755 sql/create_db.sh (limited to 'sql') 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 -- cgit v1.2.3