Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

如何製作「Debian Package」/ 基本

操作步驟

建立專案資料夾

執行下面指令,建立專案資料夾

mkdir -p demo/DEBIAN
mkdir -p demo/usr/bin

產生「control」檔案

執行下面指令,產生「demo/DEBIAN/control」

cat > demo/DEBIAN/control << EOF
Package: demo
Version: 0.1
Architecture: all
Description: This is a test package.
Maintainer: developer <developer@home.heaven>

EOF

可以執行「$ man deb-control」來閱讀「欄位說明」。

產生「demo script」

執行下面指令,產生「demo/usr/bin/demo」

cat > demo/usr/bin/demo << EOF
#!/usr/bin/env bash

echo 'Hi!'

EOF

執行下面指令,設定執行權限

$ chmod +x demo/usr/bin/demo

執行

$ demo/usr/bin/demo

顯示

Hi!

觀看專案資料夾結構

執行下面指令,觀看專案資料夾結構

$ tree demo

顯示

demo
├── DEBIAN
│   └── control
└── usr
    └── bin
        └── demo

3 directories, 2 files

打包成「Debian Package」

執行下面指令,將「demo」打包成「deb檔」。

$ dpkg -b demo

顯示

dpkg-deb: building package 'demo' in 'demo.deb'.

會產生一個檔案「demo.deb」。

觀看deb檔案資訊

執行下面指令,觀看「demo.deb」的檔案資訊

$ dpkg -I demo.deb

顯示

new debian package, version 2.0.
size 668 bytes: control archive=240 bytes.
	129 bytes,     6 lines      control              
Package: demo
Version: 0.1
Architecture: all
Description: This is a test package.
Maintainer: developer <developer@home.heaven>

執行

$ dpkg -f demo.deb

顯示

Package: demo
Version: 0.1
Architecture: all
Description: This is a test package.
Maintainer: developer <developer@home.heaven>

執行

$ dpkg -c demo.deb

顯示

drwxrwxr-x user/user           0 2017-05-26 13:56 ./
drwxrwxr-x user/user           0 2017-05-26 13:56 ./usr/
drwxrwxr-x user/user           0 2017-05-26 13:56 ./usr/bin/
-rwxrwxr-x user/user          33 2017-05-26 13:56 ./usr/bin/demo

安裝

執行下面指令,安裝「demo.deb」

$ sudo dpkg -i demo.deb

確認是否安裝

執行

$ dpkg -l demo

顯示

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                          Version             Architecture        Description
+++-=============================-===================-===================-================================================================
ii  demo                          0.1                 all                 This is a test package.

執行

$ dpkg -s demo

顯示

Package: demo
Status: install ok installed
Maintainer: developer <developer@home.heaven>
Architecture: all
Version: 0.1
Description: This is a test package.

執行

$ grep '^Package: demo$' /var/lib/dpkg/status -A 5

顯示

Package: demo
Status: install ok installed
Maintainer: developer <developer@home.heaven>
Architecture: all
Version: 0.1
Description: This is a test package.

執行

$ apt-cache show demo

顯示

Package: demo
Status: install ok installed
Maintainer: developer <developer@home.heaven>
Architecture: all
Version: 0.1
Description: This is a test package.
Description-md5: 9aba808511e384454d68cb7face0f2da

執行

$ ls /var/lib/dpkg/info/demo* -1

顯示

/var/lib/dpkg/info/demo.list
/var/lib/dpkg/info/demo.md5sums

觀看那些檔案安裝在系統上

執行

$ dpkg -L demo

顯示

/.
/usr
/usr/bin
/usr/bin/demo

執行

$ cat /var/lib/dpkg/info/demo.list

顯示

/.
/usr
/usr/bin
/usr/bin/demo

執行

$ cat /var/lib/dpkg/info/demo.md5sums

顯示

1b55790573c853326dcf2107cfdfb682  usr/bin/demo

移除

執行下面指令,透過「dpkg」,移除「demo」這個「Package」

$ sudo dpkg -r demo

或是執行下面指令,透過「apt-get」,移除「demo」這個「Package」

$ sudo apt-get remove demo

強制移除

執行下面指令,觀看「force」選項說明

$ dpkg --force-help

顯示

dpkg forcing options - control behaviour when problems found:
  warn but continue:  --force-<thing>,<thing>,...
  stop with error:    --refuse-<thing>,<thing>,... | --no-force-<thing>,...
 Forcing things:
  [!] all                Set all force options
  [*] downgrade          Replace a package with a lower version
      configure-any      Configure any package which may help this one
      hold               Process incidental packages even when on hold
      not-root           Try to (de)install things even when not root
      bad-path           PATH is missing important programs, problems likely
      bad-verify         Install a package even if it fails authenticity check
      bad-version        Process even packages with wrong versions
      overwrite          Overwrite a file from one package with another
      overwrite-diverted Overwrite a diverted file with an undiverted version
  [!] overwrite-dir      Overwrite one package's directory with another's file
  [!] unsafe-io          Do not perform safe I/O operations when unpacking
  [!] confnew            Always use the new config files, don't prompt
  [!] confold            Always use the old config files, don't prompt
  [!] confdef            Use the default option for new config files if one
                         is available, don't prompt. If no default can be found,
                         you will be prompted unless one of the confold or
                         confnew options is also given
  [!] confmiss           Always install missing config files
  [!] confask            Offer to replace config files with no new versions
  [!] architecture       Process even packages with wrong or no architecture
  [!] breaks             Install even if it would break another package
  [!] conflicts          Allow installation of conflicting packages
  [!] depends            Turn all dependency problems into warnings
  [!] depends-version    Turn dependency version problems into warnings
  [!] remove-reinstreq   Remove packages which require installation
  [!] remove-essential   Remove an essential package

WARNING - use of options marked [!] can seriously damage your installation.
Forcing options marked [*] are enabled by default.

執行下面指令,強制移除

$ sudo dpkg -r --force-all demo

或是執行下面指令,強制移除,忽略相依性的問題

$ sudo dpkg -r --force-depends demo

強制移除相關討論:「#23 回覆: 套件系統損壞 (懷疑是 LiberOffice 與 OpenOffice 衝突)

相關討論

Manpage