#!/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="PassMan123!" echo "Password of database user (hint: change this!) [$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 if exists $dbname; drop user if exists '$uname'@'localhost'; END_OF_DROP fi cat >> $script << END_OF_SQL create database $dbname; use $dbname; grant all on *.* to '$uname'@'localhost' identified by '$pword'; create table pm_store ( id int not null auto_increment, description varchar(1024) not null, groupname varchar(512) not null, username varchar(512) not null, password varchar(512) not null, primary key (id) ); END_OF_SQL cat -n $script mysql -u root -p < $script rm -f $script