#! /bin/sh

main() {

##### 引数取得 #####
MODULES_DIR=$1
DEST_DIR=$2
POSTGRES_HOME=$3
OPENSTANDIA_HOME=$4

##### 初期処理 #####
MODULES_DIR=${MODULES_DIR}/
DEST_DIR=${DEST_DIR}/
POSTGRES_HOME=${POSTGRES_HOME}/
OPENSTANDIA_HOME=${OPENSTANDIA_HOME}/

##### サーバー停止を試みる #####
sudo -u postgres ${POSTGRES_HOME}/bin/pg_ctl -m immediate -D ${INSTALL_DIR}/data stop 2>/dev/nul

##### アンインストール #####
#cd "${MODULES_DIR}/${DEST_DIR}"
#make uninstall
rm -Rf "${POSTGRES_HOME}bin"
rm -Rf "${POSTGRES_HOME}doc"
rm -Rf "${POSTGRES_HOME}include"
rm -Rf "${POSTGRES_HOME}lib"
rm -Rf "${POSTGRES_HOME}man"
rm -Rf "${POSTGRES_HOME}share"
rm -Rf "${MODULES_DIR}${DEST_DIR}"
rm -f ${OPENSTANDIA_HOME}postgres-start.sh
rm -f ${OPENSTANDIA_HOME}postgres-stop.sh

}

main $*
