download/panel/php_exts/sqlsrv.sh
耗子 972ec603a0
Some checks failed
Generate Checksums / checksums (push) Has been cancelled
feat: 更新一堆php拓展
2025-04-12 02:13:38 +08:00

116 lines
3.7 KiB (Stored with Git LFS)
Bash

#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
: '
Copyright (C) 2022 - now HaoZi Technology Co., Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'
source <(curl -f -s --connect-timeout 10 --retry 3 https://dl.cdn.haozi.net/panel/public.sh)
if [ $? -ne 0 ]; then
echo "下载 public.sh 失败,请检查网络或稍后重试。"
echo "Download public.sh failed, please check the network or try again later."
exit 1
fi
action=${1}
version=${2}
php_path="${setup_path}/server/php/${version}"
sqlsrv_version="5.12.0"
if [ ${version} -le "80" ]; then
sqlsrv_version="5.11.1"
fi
if [ ${version} -le "74" ]; then
sqlsrv_version="5.10.1"
fi
Install() {
# 检查是否已经安装
is_install=$(cat ${php_path}/etc/php.ini | grep '^extension=sqlsrv')
if [ "${is_install}" != "" ]; then
error "PHP-${version} 已安装 sqlsrv"
fi
# 安装依赖
if [ ${OS} == "rhel" ]; then
dnf install unixODBC-devel -y
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install unixodbc-dev -y
else
error "不支持的操作系统"
fi
cd ${php_path}/src/ext
rm -rf sqlsrv
rm -rf sqlsrv-${sqlsrv_version}.tgz
wget --retry-connrefused --retry-on-host-error --retry-on-http-error=429,500,502,503,504 -t 10 -T 120 -O sqlsrv-${sqlsrv_version}.tgz ${download_url}/php_exts/sqlsrv-${sqlsrv_version}.tgz
wget --retry-connrefused --retry-on-host-error --retry-on-http-error=429,500,502,503,504 -t 10 -T 120 -O sqlsrv-${sqlsrv_version}.tgz.sha256 ${download_url}/php_exts/sqlsrv-${sqlsrv_version}.tgz.sha256
if ! sha256sum --status -c sqlsrv-${sqlsrv_version}.tgz.sha256; then
rm -f sqlsrv-${sqlsrv_version}.tgz
rm -f sqlsrv-${sqlsrv_version}.tgz.sha256
error "PHP-${version} sqlsrv 校验失败"
fi
tar -xzf sqlsrv-${sqlsrv_version}.tgz
mv sqlsrv-${sqlsrv_version} sqlsrv
rm -f package.xml
rm -f sqlsrv-${sqlsrv_version}.tgz
rm -f sqlsrv-${sqlsrv_version}.tgz.sha256
cd sqlsrv
${php_path}/bin/phpize
./configure --with-php-config=${php_path}/bin/php-config
make
if [ "$?" != "0" ]; then
rm -rf ${php_path}/src/ext/sqlsrv
error "PHP-${version} sqlsrv 编译失败"
fi
make install
if [ "$?" != "0" ]; then
rm -rf ${php_path}/src/ext/sqlsrv
error "PHP-${version} sqlsrv 安装失败"
fi
sed -i '/;panel/a\extension=sqlsrv' ${php_path}/etc/php.ini
# 重载PHP
systemctl reload php-fpm-${version}.service
echo -e $HR
echo "PHP-${version} sqlsrv 安装成功"
}
Uninstall() {
# 检查是否已经安装
is_install=$(cat ${php_path}/etc/php.ini | grep '^extension=sqlsrv$')
if [ "${is_install}" == "" ]; then
error "PHP-${version} 未安装 sqlsrv"
fi
sed -i '/extension=sqlsrv/d' ${php_path}/etc/php.ini
# 重载PHP
systemctl reload php-fpm-${version}.service
echo -e $HR
echo "PHP-${version} sqlsrv 卸载成功"
}
if [ "$action" == 'install' ]; then
Install
fi
if [ "$action" == 'uninstall' ]; then
Uninstall
fi