把腳本製作成RPM包

redhat系列的linux使用RPM來管理安裝軟件很方便,把自己常用的腳本變成RPM包之後,用起來就方便了。

  1. 要製作RPM包,首先要看一下RPM包的內容(可以忽略)
    把腳本製作成RPM包
    把腳本製作成RPM包

....還是不看了把,看不懂....

2.環境準備:

軟件包依賴:rpm-build rpmdevtools
把腳本製作成RPM包

3.設置 製作RPM包 的環境

直接執行命令:rpmdev-setuptree 即可在當前用戶的家目錄生成如下目錄結構
把腳本製作成RPM包

4.拷貝自己的腳本到相應目錄

(簡單介紹一下我的那三個腳本的功能:
customOS.sh:設置歷史命令格式,終端(PS1)顯示之類的
scanport.sh :掃描目標主機的可用TCP端口
setRM.sh :當rm -rf 刪除的目標 大小小於10M,就把目標放入到/tmp目錄下

把腳本製作成RPM包

5.配置SPCE文件(重點)

在SPEC目錄下,編譯ddcw.spec
把腳本製作成RPM包

ddcw.spec內容參考如下:

Name: ddcw #名字
Version: 2019 #版本
Release: 1125
Summary: this is test RPM

Group: Applications/System
License: ddcw
URL: https://blog.51cto.com/10888845

#Requires:
Requires:grep #依賴,即安裝這個軟件所需的其它RPM包

%description #描述
this is set ddcw some habit

%prep #安裝前所需要做的事情
echo -e "\033[1;41;33m pre install NOTHING\033[0mprep"

%build #這個我也不知道
echo -e "\033[1;41;33m build NOTHING\033[0mprep"

%install #安裝,即把自己的腳本放到那個位置
#echo -e "\033[1;41;33m install NOTHING\033[0mprep"
mkdir -p %{buildroot}/tmp/ddcw
install -m 744 scanport.sh %{buildroot}/tmp/ddcw/scanport.sh
install -m 744 setRM.sh %{buildroot}/tmp/ddcw/setRM.sh
install -m 744 customOS.sh %{buildroot}/tmp/ddcw/customOS.sh

%post #安裝之後的工作,(因爲我的腳本自帶安裝功能,即執行腳本他會自動安裝)
sh /tmp/ddcw/scanport.sh
sh /tmp/ddcw/setRM.sh
sh /tmp/ddcw/customOS.sh

%files #文件
/tmp/ddcw/scanport.sh
/tmp/ddcw/setRM.sh
/tmp/ddcw/customOS.sh

%postun #卸載操作,即運行 rpm -e 軟件包 的時候執行的命令
mv /usr/bin/scanportDDCW /tmp
sed -i "/alias rm='\/bin\/rms'/d" /etc/profile >/dev/null
sed -i "/export HISTTIMEFORMAT=/d" /etc/profile >/dev/null
sed -i "/export DISPLAY=/d" /etc/profile >/dev/null
sed -i "/export PS1=/d" /etc/profile >/dev/null

%changelog #對於我來說,沒啥用

把腳本製作成RPM包

6.執行打包命令

rpmbuild -bb SPECS/ddcw.spec
把腳本製作成RPM包

7.檢查測試

打包成功後,會在 RPMS/x86_64/ 目錄下生成改RPM包
把腳本製作成RPM包

我換一臺機器測試這個RPM包:
把腳本製作成RPM包

再驗證一下功能(根據自己腳本測試,我的測試出來是OK的):
把腳本製作成RPM包

卸載試一下(也是木的問題的)
把腳本製作成RPM包

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章