#!/bin/bash
set -e
set -v
#wget https://www.openssl.org/source/openssl-3.1.2.tar.gz --no-check-certificate
mkdir ~/openssl && cd ~/openssl
yum -y install \
curl \
which \
make \
gcc \
perl \
perl-WWW-Curl \
rpm-build \
perl-IPC-Cmd
# Get openssl tarball
#cp /root/openssl-3.1.2.tar.gz ./
# SPEC file
cat << 'EOF' > ~/openssl/openssl.spec
Summary: OpenSSL 3.1.2 for CentOS
Name: openssl
Version: %{?version}%{!?version:3.1.2}
Release: 1%{?dist}
Obsoletes: %{name} <= %{version}
Provides: %{name} = %{version}
URL: https://www.openssl.org/
License: GPLv2+
Vendor: YanShunwen
Source: https://www.openssl.org/source/%{name}-%{version}.tar.gz
BuildRequires: make gcc perl perl-WWW-Curl perl-IPC-Cmd
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%global openssldir /usr/openssl
%description
OpenSSL RPM for version 3.1.2 on CentOS
%package devel
Summary: Development files for programs which will use the openssl library
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
%description devel
OpenSSL RPM for version 3.1.2 on CentOS (development package)
%prep
%setup -q
%build
./config --prefix=%{openssldir} --openssldir=%{openssldir}
make
%install
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%make_install
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_libdir}
ln -sf %{openssldir}/lib/libssl.so.3 %{buildroot}%{_libdir}
ln -sf %{openssldir}/lib/libcrypto.so.3 %{buildroot}%{_libdir}
ln -sf %{openssldir}/bin/openssl %{buildroot}%{_bindir}
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%files
%{openssldir}
%defattr(-,root,root)
/usr/bin/openssl
/usr/lib64/libcrypto.so.3
/usr/lib64/libssl.so.3
%files devel
%{openssldir}/include/*
%defattr(-,root,root)
%post
/usr/bin/cat /etc/ld.so.conf | grep -wq '/lib' >/dev/null 2>&1 || echo "/lib" >> /etc/ld.so.conf
/usr/bin/cat /etc/ld.so.conf | grep -wq '/lib64' >/dev/null 2>&1 || echo "/lib64" >> /etc/ld.so.conf
/usr/bin/cat /etc/ld.so.conf | grep -wq '/usr/lib' >/dev/null 2>&1 || echo "/usr/lib" >> /etc/ld.so.conf
/usr/bin/cat /etc/ld.so.conf | grep -wq '/usr/lib64' >/dev/null 2>&1 || echo "/usr/lib64" >> /etc/ld.so.conf
/usr/bin/cat /etc/ld.so.conf | grep -wq '/usr/openssl/lib' >/dev/null 2>&1 || echo "/usr/openssl/lib" >> /etc/ld.so.conf
/usr/bin/cat /etc/ld.so.conf | grep -wq '/usr/openssl/lib64' >/dev/null 2>&1 || echo "/usr/openssl/lib64" >> /etc/ld.so.conf
/usr/bin/cat /etc/ld.so.conf | grep -wq '/usr/local/lib' >/dev/null 2>&1 || echo "/usr/local/lib" >> /etc/ld.so.conf
/usr/bin/cat /etc/ld.so.conf | grep -wq '/usr/local/lib64' >/dev/null 2>&1 || echo "/usr/local/lib64" >> /etc/ld.so.conf
/usr/bin/cat /etc/ld.so.conf | grep -wq '/var/lib' >/dev/null 2>&1 || echo "/var/lib" >> /etc/ld.so.conf
/sbin/ldconfig
%postun -p /sbin/ldconfig
EOF
mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
cp ~/openssl/openssl.spec /root/rpmbuild/SPECS/openssl.spec
mv openssl-3.1.2.tar.gz /root/rpmbuild/SOURCES
cd /root/rpmbuild/SPECS && \
rpmbuild \
-D "version 3.1.2" \
-ba openssl.spec
网友评论