head	1.4;
access;
symbols;
locks; strict;
comment	@# @;


1.4
date	2001.06.01.16.53.22;	author stack;	state Exp;
branches;
next	1.3;

1.3
date	2001.06.01.00.56.58;	author stack;	state Exp;
branches;
next	1.2;

1.2
date	2001.05.30.00.26.45;	author stack;	state Exp;
branches;
next	1.1;

1.1
date	2001.05.30.00.22.42;	author stack;	state Exp;
branches;
next	;


desc
@@


1.4
log
@+ Added more thorough check that user has sourced env.sh.
+ Added a prompt asking user if they are sure they want to proceed
w/ the loading of a database.
@
text
@#!/bin/sh
##
## This script picks up all 'issues_*.sql' and 'tigris*.sql' files 
## in the passed in directory and inputs them into the database
## mentioned in the sourcecast env.sh file.  
##
## Be sure of where you are running the insert.  Are you inserting
## atop a production database or a database someone needs?  Check.
##
## $Id: insert_tigris_db.sh,v 1.3 2001/06/01 00:56:58 stack Exp $
##

# Name of this script.
#
this_name="`basename $0`"

db_dir=


## Usage
##
## Function to print out how to use this command
##
function usage
{
    cat <<USAGE
Usage: ${this_name} SRC_DIR

Parameters:
 -h|--help          Prints this usage message and exits.

Read head of this script for details on usage.

USAGE
}

## Check we've sourced a wholesome env.sh
##
function checkEnv
{
    if [ ! -n "${SANDBOX}" \
            -o ! -d "${SANDBOX}" \
            -o ! -e "${SANDBOX}/scripts/env.sh"  ]
    then
        echo "ERROR: SANDBOX is undefined or is not an extant dir."
        exit 1
    fi
    "${SANDBOX}/scripts/env_check" &> /dev/null
    if [ $? -ne 0 ]
    then
        echo "ERROR: ${SANDBOX}/scripts/env_check failed."
        echo "ERROR: Is env.sh set properly?"
        exit 1
    fi
}

## Check that user wants to indeed go ahead w/ this action.
##
function checkAction
{
    echo "WARNING: This script is about to drop the ${DATABASE_NAME} database"
    echo -n "on ${DATABASE_HOST}. Are you sure you want to proceed? [n]: "
    read response
    case "$response" in
        y|Y|yes|YES) ;;
        *) echo "Exiting... Did nothing."; exit 0;;
    esac
}


## Script execution starts here.
## Check environment, read command-line arguments, then for each 
## db, do a drop if it exists and finally, an insert.
##

checkEnv

if [ $# -ne 1 -o ! -d "$1" ];
then 
    echo "ERROR: You must supply a SRC_DIR"
    usage
    exit 1
else
    db_dir=$1
fi

checkAction

echo "Inputting 'issues_%' and 'tigris' into $DATABASE_HOST"
for file in `ls ${db_dir}/issues_*.sql ${db_dir}/tigris*.sql`; do
    echo -n "."
    db=`basename $file | sed "s/\([^.]*\).*/\1/"`
    mysqladmin -f -s -u $DATABASE_ADMIN_USER -p$DATABASE_ADMIN_PASSWORD \
        --host=$DATABASE_HOST --port=$DATABASE_PORT drop ${db} \
        &> /dev/null
    mysqladmin -f -s -u $DATABASE_ADMIN_USER -p$DATABASE_ADMIN_PASSWORD \
        --host=$DATABASE_HOST --port=$DATABASE_PORT create ${db} \
        &> /dev/null
    mysql -u $DATABASE_ADMIN_USER -p$DATABASE_ADMIN_PASSWORD \
        --host=$DATABASE_HOST --port=$DATABASE_PORT ${db} < ${file}
done
echo

@


1.3
log
@Check user has sourced and env.sh before running (Previous I had
hard-coded assumption that env.sh to use was at /usr/local/tigris).
@
text
@d10 1
a10 1
## $Id: insert_tigris_db.sh,v 1.2 2001/05/30 00:26:45 stack Exp $
a12 8
# Check we've sourced an env.sh
#
if [ ! -n "${SANDBOX}" ]
then
    echo "Source a SANDBOX/scripts/env.sh"
    exit 1
fi

d37 40
d87 2
d90 1
a90 1
for file in `ls ${db_dir}/issues_*.sql ${db_dir}/tigris.sql`; do
d92 7
d100 1
a100 1
        --host=$DATABASE_HOST --port=$DATABASE_PORT < $file
@


1.2
log
@Just previous, committed w/o comment.  Here is the comment.

Helper scripts for dumping and inserting tigris databases.
See usage and http://helm.tigris.org/migration/ for details on their usage.
@
text
@d10 1
a10 1
## $Id: insert_tigris_db.sh,v 1.1 2001/05/30 00:22:42 stack Exp $
d13 8
a23 4

# Source in the the scast environment.
#
. /usr/local/tigris/scripts/env.sh
@


1.1
log
@*** empty log message ***
@
text
@a6 1
##
d10 1
a10 1
## $Id$
@

