#!/bin/bash

# Copyright (c) 2000, 2004 IBM Corp. - All Rights Reserved.
# IBM makes no representations or warranties about the suitability of
# this program, either express or implied, including but not limited to
# the implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. 
  


# Sachin Prasad
# Trigo Technologies

# usage: importCompany --company_code=<code> --zipfile_path=<path/to/import/archive>

. ${TOP}/bin/get_params.sh

if [ -z ${_CCD_COMPANY_CODE} ]; then
    echo Company code not specified
    echo "usage: importCompany --company_code=<code> --zipfile_path=<path/to/import/archive>"
    exit
fi

if [ -z ${_CCD_ZIPFILE_PATH} ]; then
    echo Archive file Path not specified
    echo "usage: importCompany --company_code=<code> --zipfile_path=<path/to/import/archive>"
    exit
fi


if [ ! -e ${_CCD_ZIPFILE_PATH} ]; then
    echo "Archive file not found" 
    exit
fi

#FIX for WPC00021775
#zip -T ${_CCD_ZIPFILE_PATH} 1>/dev/null 2>/dev/null
#Removing verification of zip file integrity as certain system might not be having zip utility installed
#if [ $? -ne 0 ]; then 
#   echo "The specified archive file [ ${_CCD_ZIPFILE_PATH} ] is corrupted"
#   exit 
#fi

if [ -e ./importCompany.log ]; then 
    echo "The log file for last importCompany exists and will be overwritten. Continue (y/n)?"
   read res
   if [ "$res" = "n" ]; then
       echo "!! exiting"
       exit
   fi
fi

touch importCompany.log
echo "============================================================"
$JAVA_RT com.ibm.ccd.envexpimp.common.EnvironmentImporter -companycode=${_CCD_COMPANY_CODE} -zipfilepath=${_CCD_ZIPFILE_PATH} | tee importCompany.log
echo 
echo "+++The log file has been created at `pwd`/importCompany.log"
echo "============================================================"
