From 5fb58476bae9534365ee6f66670b8b74268ae7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Tue, 26 Sep 2023 00:41:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20PostgreSQL=20?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/postgresql/install.sh | 1 - scripts/postgresql/update.sh | 100 ++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 scripts/postgresql/update.sh diff --git a/scripts/postgresql/install.sh b/scripts/postgresql/install.sh index fec82b507a..27591a4c46 100644 --- a/scripts/postgresql/install.sh +++ b/scripts/postgresql/install.sh @@ -25,7 +25,6 @@ downloadUrl="https://dl.cdn.haozi.net/panel/postgresql" setupPath="/www" postgresqlPath="${setupPath}/server/postgresql" postgresqlVersion="" -postgresqlPassword=$(cat /dev/urandom | head -n 16 | md5sum | head -c 16) cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l) if [[ "${1}" == "15" ]]; then diff --git a/scripts/postgresql/update.sh b/scripts/postgresql/update.sh new file mode 100644 index 0000000000..4f71b6515c --- /dev/null +++ b/scripts/postgresql/update.sh @@ -0,0 +1,100 @@ +#!/bin/bash +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH + +: ' +Copyright 2022 HaoZi Technology Co., Ltd. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +' + +HR="+----------------------------------------------------" +ARCH=$(uname -m) +memTotal=$(LC_ALL=C free -m | grep Mem | awk '{print $2}') +OS=$(source /etc/os-release && { [[ "$ID" == "debian" ]] && echo "debian"; } || { [[ "$ID" == "centos" ]] || [[ "$ID" == "rhel" ]] || [[ "$ID" == "rocky" ]] || [[ "$ID" == "almalinux" ]] && echo "centos"; } || echo "unknown") +downloadUrl="https://dl.cdn.haozi.net/panel/postgresql" +setupPath="/www" +postgresqlPath="${setupPath}/server/postgresql" +postgresqlVersion="" +cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l) + +if [[ "${1}" == "15" ]]; then + postgresqlVersion="15.4" +elif [[ "${1}" == "16" ]]; then + postgresqlVersion="16.0" +else + echo -e $HR + echo "错误:不支持的 PostgreSQL 版本!" + exit 1 +fi + +# 安装依赖 +if [ "${OS}" == "centos" ]; then + dnf makecache -y + dnf groupinstall "Development Tools" -y + dnf install make gettext zlib-devel readline-devel libicu-devel libxml2-devel libxslt-devel openssl-devel systemd-devel -y +elif [ "${OS}" == "debian" ]; then + apt-get update + apt-get install build-essential make gettext zlib1g-dev libreadline-dev libicu-dev libxml2-dev libxslt-dev libssl-dev libsystemd-dev -y +else + echo -e $HR + echo "错误:耗子Linux面板不支持该系统" + exit 1 +fi + +# 停止已有服务 +systemctl stop postgresql + +# 准备目录 +rm -rf ${postgresqlPath}/src +cd ${postgresqlPath} + +# 下载源码 +wget -T 120 -O ${postgresqlPath}/postgresql-${postgresqlVersion}.tar.gz ${downloadUrl}/postgresql-${postgresqlVersion}.tar.gz +tar -zxvf postgresql-${postgresqlVersion}.tar.gz +rm -f postgresql-${postgresqlVersion}.tar.gz +mv postgresql-${postgresqlVersion} src + +# 编译 +cd src +./configure --prefix=${postgresqlPath} --enable-nls='zh_CN en' --with-icu --with-ssl=openssl --with-systemd --with-libxml --with-libxslt +if [ "$?" != "0" ]; then + echo -e $HR + echo "错误:PostgreSQL 编译初始化失败,请截图错误信息寻求帮助。" + exit 1 +fi +make -j${cpuCore} +if [ "$?" != "0" ]; then + echo -e $HR + echo "错误:PostgreSQL 编译失败,请截图错误信息寻求帮助。" + exit 1 +fi +make install +if [ "$?" != "0" ]; then + echo -e $HR + echo "错误:PostgreSQL 安装失败,请截图错误信息寻求帮助。" + exit 1 +fi + +cd ${postgresqlPath} +rm -rf ${postgresqlPath}/src + +# 配置 +chown -R postgres:postgres ${postgresqlPath} +chmod -R 700 ${postgresqlPath} + +panel writePlugin postgresql${1} ${postgresqlVersion} + +systemctl daemon-reload +systemctl restart postgresql + +echo -e "${HR}\nPostgreSQL-${1} 升级完成\n${HR}"