Linux - openssh透過原始碼build rpm包

HOUHUILIN發表於2024-03-13

# 安裝依賴包
yum install --downloadonly --downloaddir=/home/rpm-install rpm-build gcc gcc-c++ glibc glibc-devel openssl-devel openssl pcre-devel zlib zlib-devel make wget krb5-devel pam-devel libX11-devel xmkmf libXt-devel initscripts libXt-devel imake gtk2-devel lrzsz


yum install -y rpm-build gcc gcc-c++ glibc glibc-devel openssl-devel openssl pcre-devel zlib zlib-devel make wget krb5-devel pam-devel libX11-devel xmkmf libXt-devel initscripts libXt-devel imake gtk2-devel lrzsz

# 建立RPM包的相關目錄
mkdir -pv /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}

[root@node home]# mkdir -pv /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
mkdir: 已建立目錄 "/root/rpmbuild"
mkdir: 已建立目錄 "/root/rpmbuild/BUILD"
mkdir: 已建立目錄 "/root/rpmbuild/BUILDROOT"
mkdir: 已建立目錄 "/root/rpmbuild/RPMS"
mkdir: 已建立目錄 "/root/rpmbuild/SOURCES"
mkdir: 已建立目錄 "/root/rpmbuild/SPECS"
mkdir: 已建立目錄 "/root/rpmbuild/SRPMS"


# 開啟OpenSSH官網下載最新版本的Openssh 9.3p2和相關依賴包
cd /root/rpmbuild/SOURCES/
wget  https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p2.tar.gz
tar -xf openssh-9.3p2.tar.gz
wget https://src.fedoraproject.org/repo/pkgs/openssh/x11-ssh-askpass-1.2.4.1.tar.gz

# 配置相關編譯檔案
cp openssh-9.3p2/contrib/redhat/openssh.spec /root/rpmbuild/SPECS/
cd /root/rpmbuild/SPECS/
#不生產ask包
sed -i -e "s/%global no_gnome_askpass 0/%global no_gnome_askpass 1/g" openssh.spec
sed -i -e "s/%global no_x11_askpass 0/%global no_x11_askpass 1/g" openssh.spec
#修改openssl-devel的報錯
sed -i '/openssl-devel < 1.1/s/^/#/' openssh.spec
#修改PreReq的報錯
sed -i '/PreReq:/s/^/#/' openssh.spec

# 編譯檔案
rpmbuild -ba openssh.spec

# 
cd /root/rpmbuild/RPMS/x86_64
ll
total 9780
-rw-r--r-- 1 root root  648612 Aug  4 11:06 openssh-9.3p2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root  641296 Aug  4 11:06 openssh-clients-9.3p2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 3273756 Aug  4 11:06 openssh-debuginfo-9.3p2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root  472476 Aug  4 11:06 openssh-server-9.3p2-1.el7.x86_64.rpm

# 打包所有rpm包
tar -zcvf openssh9.3p2_el7_rpms.tar.gz *.rpm

相關文章