#!/bin/bash

dbPass='postgres'
dbPort='5432'
pgCfg='postgresql.conf'
while [ $# -gt 0 ]; do
  COMMAND=$1
  case $COMMAND in
    -dataDir)
      dataDir=$2
      shift 2
      ;;
    -dbPass)
      dbPass=$2
      shift 2
      ;;
    -dbPort)
      dbPort=$2
      shift 2
      ;;
    -instName)
      instName=$2
      shift 2
      ;;
    *)
      break
      ;;
  esac
done

if [ -e pg14Rpm.tar ]; then
  echo 'file exist, skip download'
else
  echo "download tar"
  wget http://tool.epm2demo.cn/pg/pg14Rpm.tar
  tar zxf pg14Rpm.tar
fi
echo "install"
yum install -y *.rpm

/usr/pgsql-14/bin/postgresql-14-setup initdb
systemctl enable postgresql-14
echo "host    all             all             192.168.124.41/16           trust" >> /var/lib/pgsql/14/data/pg_hba.conf
wget http://tool.epm2demo.cn/pg/conf/postgresql.conf.simple -O /var/lib/pgsql/14/data/postgresql.conf 

systemctl start postgresql-14