# Common to both the sipx-backup and sipx-restore scripts.

CONFIG_DATABASE_NAME=SIPXCONFIG
CDR_DATABASE_NAME=SIPXCDR
DB_TAR=db.tar
DB_CDR_TAR=db_cdr.tar
SIPX_CERTDB_DIR=/var/sipxdata/certdb

operation_stamp() {
   echo $OPERATION" script invoked at "`date -u`", INTERACTIVE="$INTERACTIVE"."
}

confirm_action() {
  if [ "$INTERACTIVE" = "yes" ]; then
    while :
    do
      echo -n "Is this OK? [y/N] "
      read response
      case $response in
        y* | Y*)
          break
          ;;

        n* | N* | "")
          echo "Cancelled."
          exit
          ;;
      esac
    done
  fi
}

bad_usage() {
  usage
  exit 1
}

postgresql_running() {
  # simply see if there's a postmaster running
  PIDS="$(ps -C postmaster -o pid --noheaders 2>/dev/null)"

  if [ -z "$PIDS" ] ; then
    echo "PostgreSQL does not appear to be running."
	echo "  You must start it in order to $OPERATION."
    exit 2
  fi
}

delete_old_file() {
  if [ -a $1 ]
  then
    echo "Will delete the old $1 file..."
    confirm_action
    rm -rf $1
  fi
}

