定义SPEC文件
首先从nmap的github上下载SPEC定义文件,然后进行修改,如下:
# To build a static RPM, add
# --define "static 1"
# to the rpmbuild command line. To build without Ncat, add
# --define "buildncat 0"
# To build without Nping, add
# --define "buildnping 0"
#
# To specify openssl dir, add something like:
# --define "openssl /usr/local/ssl"
%define name nmap
%define version 7.95
%define release 2
%define _prefix /usr
%define makeargs OPENSSL_LIBS="%{openssl}/lib64/libssl.a %{openssl}/lib64/libcrypto.a" LIBSSL="%{openssl}/lib64/libssl.a %{openssl}/lib64/libcrypto.a" ZLIB_LIBS="$(pwd)/libz/libz.a" LIBZ="$(pwd)/lib64/libz.a"
Summary: Network exploration tool and security scanner
Name: %{name}
Version: %{version}
Release: %{release}%{?dist}
Epoch: 2
License: https://nmap.org/man/man-legal.html
Group: Applications/System
Source0: %{name}-%{version}.tar.bz2
URL: https://nmap.org
# Disable automatic dependency calculation because we want to provide
# packages for more than one version of Python. Without this, RPM will
# grep through the installed files and automatically add things like
# Requires: python(abi) = 2.4
# setup.py takes care of adjusting sys.path to point to wherever the
# modules were installed so it's not dependent on any particular ABI.
AutoReqProv: no
# For Ndiff.
BuildRequires: python3-devel
Requires: python3 >= 3.0
%global debug_package %{nil}
# RPM can't be relocatable until I stop storing path info in the binary.
Prefix: %{_prefix}
BuildRoot: %{_tmppath}/%{name}-root
%description
Nmap ("Network Mapper") is a free and open source utility
for network exploration or security auditing. Many systems and network
administrators also find it useful for tasks such as network
inventory, managing service upgrade schedules, and monitoring host or
service uptime. Nmap uses raw IP packets in novel ways to determine
what hosts are available on the network, what services (application
name and version) those hosts are offering, what operating systems
(and OS versions) they are running, what type of packet
filters/firewalls are in use, and dozens of other characteristics. It
was designed to rapidly scan large networks, but works fine against
single hosts. Nmap runs on all major computer operating systems, and
both console and graphical versions are available.
%prep
%setup -q
%build
./configure --prefix=%{_prefix} -without-zenmap --without-ncat --without-nping --without-ndiff
make
%install
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT
# Don't package the Ndiff uninstaller with the RPM.
rm -f $RPM_BUILD_ROOT%{_bindir}/uninstall_ndiff
strip $RPM_BUILD_ROOT%{_bindir}/* || :
gzip $RPM_BUILD_ROOT%{_mandir}/man1/* || :
%clean
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%doc LICENSE
%doc docs/README
%doc docs/nmap.usage.txt
%doc %{_prefix}/share/man/man1/nmap.1*
%doc %{_prefix}/share/man/*/man1/nmap.1*
%{_bindir}/nmap
%{_datadir}/nmap
%changelog
* Sat Jun 06 2009 Fyodor (fyodor(a)insecure.org)
- Removed changelog entries as SVN is a more authoritative source. Execute:
- svn log --username guest --password "" https://svn.nmap.org/nmap/nmap.spec.in
安装编译环境
分别在CentOS7.9、AnolisOS8.9上搭建编译环境。
yum -y groupinstall Development Tools
yum -y install openssl-devel python3-devel libssh2-devel flex bison byacc libpcap epel-rpm-macros libtool
yum -y install rpmdevtools rpm-build rpmrebuild
准备构建环境
su - user1
rpmdev-setuptree
~]$ ll ~/
总用量 0
drwxrwxr-x 7 user1 user1 72 8月 6 15:15 rpmbuild
cp /opt/nmap-7.95.tar.bz2 ~/rpmbuild/SOURCES/
构建RPM包
rpmbuild -ba SPECS/nmap-7.95-2.spec
构建完验证
适配CentOS7、AnolisOS8.*、BCLinux8.*、openEuler。
rpm -ivh nmap-7.95-2.x86_64.el7.rpm
Preparing... ################################# [100%]
Updating / installing...
1:nmap-2:7.95-2 ################################# [100%]
[root@ultraamr-node02 /]# nmap -V
Nmap version 7.95 ( https://nmap.org )
Platform: x86_64-unknown-linux-gnu
Compiled with: nmap-liblua-5.4.6 openssl-1.0.2k-fips nmap-libssh2-1.11.0 libz-1.2.7 nmap-libpcre2-10.43 nmap-libpcap-1.10.4 nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: epoll poll select