#!/bin/bash
#===============================================================================
# FILE: buildSteps.sh
# USAGE: ./buildSteps.sh --help
# DESCRIPTION: Build Step commands - a multi-tool for different custom make commands
# CREATED: 02/11/2017
#===============================================================================
function BuildSQLStatement()
{
echo "BEGIN TRANSACTION;"
cat "db/tables.csv" | while read TABLE
do
cat "db/$TABLE.csv" |
while read HEAD
do
echo "CREATE TABLE $TABLE($HEAD);"
while read LINE
do
echo "INSERT INTO \"$TABLE\" VALUES($LINE);"
done
done
done
echo "COMMIT;"
}
# Builds a sqlite3 DB from a collection of CSV files
function BuildDB()
{
echo "Building DB started"
rm -rf ./build/gameDB.db
[ ! -d ./build ] && mkdir ./build
BuildSQLStatement | sqlite3 ./build/gameDB.db
echo "Building DB finished"
}
function ShowHelp()
{
echo "Usage"
echo " --buildDB rebuild the SQLite3 DB from the CSV files"
echo " --help show options"
}
# If no options specified, show the help
if [ $# == 0 ]
then
ShowHelp
fi
# Do commands
while [ $# != 0 ]
do
case "$1"
in
--buildDB) BuildDB ; shift ;;
--help) ShowHelp ; shift ;;
*) ShowHelp ; shift ;;
esac
done