天天看點

deb打包

一、deb包結構

deb包本身有三部分組成

deb打包

 deb 軟體包裡面的結構:它具有DEBIAN和軟體具體安裝目錄(如etc, usr, opt, tmp等):

soft-name
    |--DEBIAN
    |       |--control
    |       |--postinst
    |       |--postrm
    |       |--preinst
    |       |--prerm
    |       |--copyright
    |
    |--opt
    |   |--files
    |--etc
    |   |--files
    ...          

二、control檔案

  control:這個檔案主要描述軟體包的名稱(Package),版本(Version),Installed-Size(大小),Maintainer(打包人和聯系方式)以及描述(Description)等,是deb包必須具備的描述性檔案,以便于軟體的安裝管理和索引。

deb打包

 三、腳本檔案

preinst 檔案于軟體包安裝之前會被調用

postinst 檔案于軟體包安裝之後被調用

prerm 檔案于軟體包解除安裝之前調用

postrm 檔案于軟體包解除安裝之後調用

四、編寫測試用例

1,編寫control檔案

mkdir -p ~/test/DEBIAN

cd ~/test/DEBIAN

vim control

Package: test
Version: 1
Architecture: amd64
Maintainer: guanghe
Description: test      
deb打包

2,放置需要安裝到系統的檔案

mkdir -p ~/test/opt/test

cd ~/test/opt/test

touch test.sh

echo 'echo `date`"光何" > /tmp/test.log' > ./test.sh

deb打包

3,設定安裝完成後執行腳本

vim ~/test/DEBIAN/postinst

#!/bin/bash
cd /opt/test
chmod +x /opt/test/test.sh/opt/test/test.sh      

修改postinst權限

chmod 755  ~/test/DEBIAN/postinst

五、打包、安裝、解除安裝

1,打包

cd ~

dpkg -b ./test test.deb

第一個參數為将要打包的目錄名(./表示目前目錄),第二個參數為生成包的名稱<.deb file name>,預設則使用檔案夾名稱

deb打包

2,安裝

dpkg -i test.deb

deb打包

3,解除安裝

dpkg --purge test

-r:删除包,--purge:删除包并删除配置檔案

deb打包