mdserver-web/plugins/postgresql/versions/14/install.sh

129 lines
3.1 KiB
Bash
Raw Permalink Normal View History

2022-08-07 08:46:40 -04:00
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#https://www.postgresql.org/ftp/source/
curPath=`pwd`
rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
sysName=`uname`
postgreDir=${serverPath}/source/postgresql
2025-07-16 23:15:34 -04:00
VERSION=14.18
2022-08-07 08:46:40 -04:00
2022-11-21 12:03:20 -05:00
# su - postgres -c "/www/server/postgresql/bin/pg_ctl start -D /www/server/postgresql/data"
2022-11-21 11:27:37 -05:00
2022-08-07 08:46:40 -04:00
Install_App()
{
mkdir -p ${postgreDir}
2024-11-30 08:44:09 -05:00
echo '正在安装脚本文件...'
2022-08-07 08:46:40 -04:00
2022-08-10 10:08:03 -04:00
if id postgres &> /dev/null ;then
2022-11-21 11:09:41 -05:00
echo "postgres uid is `id -u postgres`"
echo "postgres shell is `grep "^postgres:" /etc/passwd |cut -d':' -f7 `"
2022-08-07 08:46:40 -04:00
else
2022-08-10 10:08:03 -04:00
groupadd postgres
useradd -g postgres postgres
2022-08-07 08:46:40 -04:00
fi
2022-11-21 11:09:41 -05:00
if [ ! -d /home/postgres ];then
mkdir -p /home/postgres
fi
2024-07-28 23:55:13 -04:00
# if [ "$sysName" != "Darwin" ];then
# mkdir -p /var/log/mariadb
# touch /var/log/mariadb/mariadb.log
# fi
2022-08-07 08:46:40 -04:00
# ----- cpu start ------
if [ -z "${cpuCore}" ]; then
cpuCore="1"
fi
2022-08-07 11:07:43 -04:00
if [ -f /proc/cpuinfo ];then
2022-08-07 08:46:40 -04:00
cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l`
2022-08-07 11:07:43 -04:00
fi
2022-08-07 08:46:40 -04:00
MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}')
if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then
if [ "${cpuCore}" -gt "${MEM_INFO}" ];then
cpuCore="${MEM_INFO}"
fi
else
cpuCore="1"
fi
2022-08-07 11:04:53 -04:00
# for stable installation
if [ "$cpuCore" -gt "1" ];then
cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'`
fi
2022-08-07 08:46:40 -04:00
# ----- cpu end ------
if [ ! -f ${postgreDir}/postgresql-${VERSION}.tar.bz2 ];then
wget --no-check-certificate -O ${postgreDir}/postgresql-${VERSION}.tar.bz2 --tries=3 https://ftp.postgresql.org/pub/source/v${VERSION}/postgresql-${VERSION}.tar.bz2
fi
if [ ! -d ${postgreDir}/postgresql-${VERSION} ];then
2022-08-07 10:55:23 -04:00
cd ${postgreDir} && tar -jxvf ${postgreDir}/postgresql-${VERSION}.tar.bz2
2022-08-07 08:46:40 -04:00
fi
if [ ! -d $serverPath/postgresql ];then
cd ${postgreDir}/postgresql-${VERSION} && ./configure \
2022-08-10 14:08:20 -04:00
--prefix=$serverPath/postgresql \
--with-openssl
2022-08-07 08:46:40 -04:00
# --with-pgport=33206
echo "cd ${postgreDir}/postgresql-${VERSION} && ./configure \
2022-08-10 14:08:20 -04:00
--prefix=$serverPath/postgresql \
--with-openssl"
2022-08-07 08:46:40 -04:00
# --with-pgport=33206
make -j${cpuCore} && make install && make clean
fi
if [ -d $serverPath/postgresql ];then
2022-08-07 10:55:59 -04:00
echo "${VERSION}" > $serverPath/postgresql/version.pl
2024-07-28 23:57:35 -04:00
echo '安装postgresql成功'
2022-08-07 08:46:40 -04:00
else
2024-07-28 23:57:35 -04:00
echo '安装postgresql失败'
rm -rf ${postgreDir}/postgresql-${VERSION}.tar.bz2
2022-08-07 08:46:40 -04:00
fi
}
Uninstall_App()
{
2024-09-13 03:25:26 -04:00
if [ -f /usr/lib/systemd/system/postgresql.service ];then
systemctl stop postgresql
systemctl disable postgresql
rm -rf /usr/lib/systemd/system/postgresql.service
systemctl daemon-reload
fi
if [ -f /lib/systemd/system/postgresql.service ];then
systemctl stop postgresql
systemctl disable postgresql
rm -rf /lib/systemd/system/postgresql.service
systemctl daemon-reload
fi
if [ -f $serverPath/postgresql/initd/postgresql ];then
$serverPath/postgresql/initd/postgresql stop
fi
if [ -d $serverPath/postgresql ];then
rm -rf $serverPath/postgresql
fi
2024-09-13 03:31:28 -04:00
echo '卸载[postgresql]完成'
2022-08-07 08:46:40 -04:00
}
action=$1
if [ "${1}" == "install" ];then
Install_App
else
Uninstall_App
fi