根据公司软件版本进行shell脚本安装, 希望有志同道合的朋友提出改进意见
#!/bin/bash
SOFTWARE_PATH='/root/'
PG__INSTALL_PATH='/data/mat'
PG_VERSION='postgresql-9.6.2'
if [ -d $PG_INSTALL_PATH ]
then
mkdir -p /data/mat
fi
rpm -q gcc
if [ $? != 0 ]
then
echo "Readline package not found. Installing it...."
yum install gcc -y
fi
#tar -zxf /$SOFTWARE_PATH/$PG_VERSION.tar.gz -C $PG__INSTALL_PATH
cd /data/mat/postgresql-9.6.2/
echo ""
echo "Building installer from source coude...."
sleep 1s
./configure --prefix=/usr/local/postgresql --without-readline
make
sleep 2s
echo ""
:<<!
echo "Installer built. Installing it now...."
make install
sleep 1s
id -a postgres
if [ $? != 0 ]
then
echo "postgres user not found. Adding it...."
groupadd postgres
useradd -g postgres postgres
else
echo "postgres user already exists. Proceeding to next step...."
fi
echo ""
echo "Configuring PostgreSQL...."
mkdir -p /data/mat/data/postgresql
chown -R postgres:postgres /data/mat/data/postgresql
echo ""
echo "Defining data directory for Postgre & starting it...."
su - postgres -c "/usr/local/postgresql/bin/initdb -D /data/mat/data/postgresql; sleep 2s; /usr/local/postgresql/bin/pg_ctl -D /data/mat/data/postgresql -l /data/mat/data/postgresql/logfile start"
if [ $? -eq 0 ]
then
echo "start postgresql sucess"
else
echo "strart postgresql failed!"
!
```