#!/bin/bash
#
#  cnv.bash - Convert from Progress schema to PostgreSQL schema
#
#  pro2pgsql
#  Copyright (C) 2006  Scott Auge, Amduus Information Works, Inc.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to
#
#  Free Software Foundation, Inc.
#  59 Temple Place, Suite 330
#  Boston, MA  02111-1307  USA
#
# $Id: cnv.bash,v 1.1 2006/07/20 01:46:18 sauge Exp sauge $

##############################################################################
# Get our environment here...                                                #
##############################################################################

#. ./set.bash

##############################################################################
# No arguments means the user needs a reminder of the arguments              #
##############################################################################

if [ $# -eq 0 ]
then

  echo $0
  echo "Convert Progress schema to PostgreSQL schema"
  echo 
  echo "-output      File to put the SQL output into"
  echo "-pf          pf for a single database"
  echo "-dlc         DLC to progress installation"  
  echo "-db          How to call the DB in PostgreSQL"
  echo "-owner       How to call the owner in PostgreSQL"
  echo "-ini         Choose an ini file to use for the run"
  echo
  echo "Example: cnv.bash -dlc /usr/dlc -pf /db/amduus/client.pf -output /tmp/db.sql -db costacct -owner postgres"
  echo 
  echo "You must connect to only one DB at a time."
  echo 
  
  exit 1

fi

##############################################################################
# Interprete arguments into environmental variables we can use OS-GETENV()   #
# against to communicate the user's intention to the 4GL code.               #
##############################################################################

# If you expect to have spaces in your files and directories given as args,
# you may prefer to use this to prevent word splitting:
# for i in "$1" "$2" "$3" "$4" "$5" "$6" ... "${10}" ...

for i in $@
do

  ########################################################################
  # Handle our argumentless switches                                     #
  ########################################################################

#  case $i in
#
#     -start)
#       export PRCCMD="start"
#       ;;
#
#  esac

  ########################################################################
  # Handle our switches with arguments                                   #
  ########################################################################

  case $lastcmd in

     -output)
       export OUTPUTFILE=$i
       ;;

     -pf)
       export PFFILE=$i
       ;;
       
     -dlc)
       export DLC=$i
       ;;       
       
     -owner)
       export OWNER=$i
       ;;            
       
     -db)
       export DBNAME=$i
       ;;       
       
     -ini)
       export CONFIGINI=$i
       ;;     
       
  esac

  lastcmd=$i

done

##############################################################################
# Hit the conversion procedure to implement what is requested.               #
##############################################################################

$DLC/bin/pro -pf $PFFILE -p bat_cnv2pgsql.p
#$DLC/bin/mpro -pf $PFFILE -p bat_cnv2pgsql.p
