安装依赖
```shell
yum install gcc rpm-build rpm-devel rpmlint make python bash coreutils diffutils
yum install rpmdev-newspec
```
准备build文件
- 生成目录
```
rpmdev-setuptree
```
2.准备源文件
```
echo "ccc" > /root/test.txt
```
3.编写SPEC文件
```
cd rpmbuild/SPECS
rpmdev-newspec provisioner.
vi provisioner.spec
```
```spec
Name: provisioner
Version: 1.0
Release: 1%{?dist}
Summary: provisioner post script install
License: cccc
BuildArch: noarch
%description
%install
rm -fr /tmp/provisioner
install -m 755 -d %{buildroot}/tmp/provisioner
cp -a /root/test.txt %{buildroot}/tmp/provisioner
%files
/tmp/provisioner
%post
mkdir -p /root/provisioner
cp -a /tmp/provisioner/. /root/provisioner/
%doc
%changelog
```
- 打包
```
rpmbuild -ba provisioner.spec
```
```
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.giWZzf
+ umask 022
+ cd /root/rpmbuild/BUILD
+ '[' /root/rpmbuild/BUILDROOT/provisioner-1.0-1.el7.x86_64 '!=' / ']'
+ rm -rf /root/rpmbuild/BUILDROOT/provisioner-1.0-1.el7.x86_64
++ dirname /root/rpmbuild/BUILDROOT/provisioner-1.0-1.el7.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT
+ mkdir /root/rpmbuild/BUILDROOT/provisioner-1.0-1.el7.x86_64
+ rm -fr /tmp/provisioner
+ install -m 755 -d /root/rpmbuild/BUILDROOT/provisioner-1.0-1.el7.x86_64/tmp/provisioner
+ cp -a /root/test.txt /root/rpmbuild/BUILDROOT/provisioner-1.0-1.el7.x86_64/tmp/provisioner
+ '[' noarch = noarch ']'
+ case "${QA_CHECK_RPATHS:-}" in
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars
Processing files: provisioner-1.0-1.el7.noarch
Provides: provisioner = 1.0-1.el7
Requires(interp): /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(post): /bin/sh
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/provisioner-1.0-1.el7.x86_64
Wrote: /root/rpmbuild/SRPMS/provisioner-1.0-1.el7.src.rpm
Wrote: /root/rpmbuild/RPMS/noarch/provisioner-1.0-1.el7.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.ku3Neo
+ umask 022
+ cd /root/rpmbuild/BUILD
+ /usr/bin/rm -rf /root/rpmbuild/BUILDROOT/provisioner-1.0-1.el7.x86_64
+ exit 0
```
本地安装测试
```
yum install /root/rpmbuild/RPMS/noarch/provisioner-1.0-1.el7.noarch.rpm
```
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。