Debian Packaging === ###### tags: `debian` `SZ Lin` `Linux` package: [--.SZ reference: 從頭打包Debian套件流程](https://hackmd.io/zjBAekZBTkS6_4gh0uvtQA) [--.Debian 新維護人員手冊](https://www.debian.org/doc/manuals/maint-guide/index.zh-tw.html) [--.Debian 维护者指南](https://www.debian.org/doc/manuals/debmake-doc/index.zh-cn.html) [--.SZ reference: googler](https://salsa.debian.org/debian/googler) [--.reference](https://www.howtoing.com/install-local-deb-packages-in-debian-ubuntu-linux-mint) [--.reference](https://wiki.debian.org/BuildingTutorial#Get_the_build_dependencies) [--.reference](https://hosiet.me/blog/2016/09/15/make-debian-package-with-git-the-canonical-way/) autotools: http://www.gnu.org/software/automake/manual/automake.html#Hello-World http://www.gnu.org/software/automake/manual/automake.html http://markuskimius.wikidot.com/programming:tut:autotools/ https://geesun.github.io/posts/2015/02/autotool.html http://bluelove1968.pixnet.net/blog/post/222286486-unix%E4%B8%8A%E8%87%AA%E5%8B%95%E7%94%A2%E7%94%9F%E7%9A%84makefile-----automake http://welong-pad.blogspot.com/2011/07/easy-lab-for-autotools.html http://bluelove1968.pixnet.net/blog/post/222286522-gcc-gdb-make-autotool-%E6%96%87%E4%BB%B6-%E6%95%99%E5%AD%B8 https://elinux.org/images/4/43/Petazzoni.pdf others: https://www.theo-andreou.org/?p=1145 http://wen00072.github.io/blog/2014/11/20/package-debian-packages-using-local-debian-pbuilder-package/ https://pbuilder-docs.readthedocs.io/en/latest/usage.html https://superuser.com/questions/250437/how-to-pass-custom-options-to-configure-when-building-a-package-with-debuild https://www.debian.org/doc/manuals/maint-guide/start.zh-tw.html git: https://zlargon.gitbooks.io/git-tutorial/content/startup/commit_a_patch.html next challenge https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=942091 https://szlin.me/2017/01/07/%E5%88%9D%E6%8E%A2-tpm-2-0/ ## 從頭打包Debian套件流程(SZ Lin's hackmd Reference) ### A. 安裝打包的必要套件 ``` $ sudo apt-get install build-essential fakeroot devscripts git git-buildpackage debmake lintian ``` 因為是要打包到SID版本(unstable Debian),可能結果會有些版本上的問題,所以建議安裝SID版本的套件。 ```shell $ vim /etc/apt/sources.list ``` ```shell $ deb http://ftp.de.debian.org/debian sid main ``` ```shell $ sudo apt-get update # 確認可用版本 $ sudo apt-cache policy debhelper $ sudo apt-cache policy debmake $ sudo apt-cache policy lintian # 更新版本 $ sudo apt-get -t sid install debhelper debmake lintian ``` 安裝gnome3和cinnamon這兩個desktop environment的debian,在做完此步驟後會crach,後來改使用xfce的版本 ### B. 範例實做 - gnujump #### 創造package repository 在[Salsa](https://salsa.debian.org/)上創建名為"gnujump"的project #### 產生package repository 1. 先clone剛剛在Salsa創立的repo ```shell $ git clone https://salsa.debian.org/kainonex-guest/gnujump.git ``` 2. 產生debian/master的branch ``` $ cd gnujump $ git checkout -b debian/master ``` 3. 先在上層目錄(與套件目錄平行)抓下upstream的tar檔 * 通常我們選擇upstream最新的release版本,名稱應該會是[檔名+版本].tar.gz (gnujump-1.0.8.tar.gz) ``` $ cd .. $ wget https://ftp.gnu.org/gnu/gnujump/gnujump-1.0.8.tar.gz ``` 4. 利用tar檔產生初始branch,然後gbp會問你package的名稱 ``` $ cd gnujump $ gbp import-orig --pristine-tar ../gnujump-1.0.8.tar.gz --debian-branch=debian/master -u 1.0.8 ``` ![](https://i.imgur.com/EzbdaHr.png) 5. 完成後就是初步的套件了 * repo裡面會有三個branch(debian/master, pristine-tar, upstream) ![](https://i.imgur.com/HPB5q7L.png) * 這三個branch分別代表的意義如下 1. upstream: 原作者的source 2. pristine-tar: 利用原作者的source產生出來的tar檔 3. debian/master: 除了upstream的source外,還包括debian的資料夾,這也是我們主要修改上傳資訊的地方 * 外層資料夾會有[package_name]_[version].orig.tar.gz的檔案 ![](https://i.imgur.com/ibaiUgp.png) #### 產生Debian套件所需內容 ``` # 把剛剛創的資料夾加上版號 $ cd .. $ mv gnujump gnujump-1.0.8 $ cd gnujump-1.0.8 $ debmake ``` - [debmake or dh-make, what should I use?](https://lists.debian.org/debian-mentors/2004/10/msg00174.html) #### 修改debian相關檔案 ##### debian/control ``` Source: gnujump Section: misc Priority: optional Maintainer: KaidenYu (余泊鎧) <kainonex@gmail.com> Build-Depends: debhelper (>=11~), libsdl1.2-dev, libsdl-image1.2-dev, libsdl-mixer1.2-dev Standards-Version: 4.1.4 Homepage: https://jump.gnu.sinusoid.es Vcs-Browser: https://salsa.debian.org/debian/gnujump Vcs-Git: https://salsa.debian.org/debian/gnujump.git Package: gnujump Architecture: any Multi-Arch: foreign Depends: ${misc:Depends}, ${shlibs:Depends} Description: Interesting game where you need to keep jumping The goal in this game is to jump to the next floor so you don't fall down. As you go higher in the falling tower the floors will fall faster. Try to survive longer than anyone, or, in single player mode, try to get as high as you can. At the moment, the game is called sdljump (and it will appear as such in the menu), but the package name has changed following an upstream rename. The new version of the game will be called gnujump as well. The game is a clone of xjump, and provides all its features, plus some more: * Multiplayer mode (up to four players, not networked) * Smooth graphics possible (but xjump style as well) * Different themes are available * Can use OpenGL for rendering * Music and sound effects * Recording (and replaying) of games This package provides the data files for the game. ``` - section: misc - 須再研究各種section - 若section填入"games",但安裝不在/usr/games會有lintian warning - Maintainer: KaidenYu (余泊鎧) <<kainonex@gmail.com>> - Build-Depends: 按照"套件打包教學指南試做"加入 - Homepage: https://jump.gnu.sinusoid.es - Vcs-Browser: https://salsa.debian.org/debian/gnujump - debmake沒產生此項,自己加 - Vcs-> version control system - Vcs-Git: https://salsa.debian.org/debian/gnujump.git - debmake沒產生此項,自己加 ``` W: gnujump source: useless-autoreconf-build-depends dh-autoreconf ``` - Build-Depends: dh-autoreconf拿掉 ``` I: gnujump: description-synopsis-might-not-be-phrased-properly ``` - Description: 不能用"."結尾 ``` W: gnujump: description-synopsis-starts-with-article ``` - Description: 不能用"A"、"An"、"The"開頭 ``` I: gnujump: extended-description-is-probably-too-short ``` - Description: 後面要加上extended decription,每一段開頭要有空格 ##### debian/patches - 若有更動原始碼的需求,使用gbp打patch,記得加上no-patch-num,來去除patch number - https://honk.sigxcpu.org/projects/git-buildpackage/manual-html/gbp.patches.html - https://manpages.debian.org/testing/git-buildpackage/gbp-clone.1.en.html - https://honk.sigxcpu.org/projects/git-buildpackage/manual-html/gbp.patches.firstpatch.html - https://linux.debian.maint.python.narkive.com/9wqYGHHd/git-dpm-vs-gbp-pq-new-upstream-and-patch-refresh-long - [git branch與checkout](https://backlog.com/git-tutorial/tw/stepup/stepup2_3.html) ``` $ gbp clone --pristine-tar [Salsa的git位置] delay_package_gbm $ gbp pq import --no-patch-num # 此時會切換到patch branch,開始做必要的更動並commit $ gbp pq export --no-patch-num ``` - 第一步驟(gbp clone --pristine-tar...)有問題 ![](https://i.imgur.com/oHRewag.png) - 第二步驟會產生一個branch並切換到該branch ![](https://i.imgur.com/5ouJhKo.png) - 第三步驟,修改src/Makefile.am,並git add src/Makefile.am,然後git commit -m - 編輯src/Makefile.am並替換 ``` gnujump_LDFLAGS = $(all_libraries) ``` - 成下列 ``` gnujump_LDFLAGS = -Wl,--as-needed gnujump_LDADD = $(all_libraries) -lm ``` - git add並commit ``` git add src/Makefile.am git commit -m "fix Makefile.am" ``` - 第四步驟,會產生debian/patches/Makefile.am-under-src-directory-modification.patch,並跳回debian/master branch ![](https://i.imgur.com/gf8kCoa.png) ![](https://i.imgur.com/7Fqmzrb.png) ![](https://i.imgur.com/PqRfj0G.png) 使用quilt的作法 ``` export QUILT_PATCHES=debian/patches mkdir debian/patches quilt new linker-fixes.patch quilt add src/Makefile.am ``` - 編輯src/Makefile.am並替換 ``` gnujump_LDFLAGS = $(all_libraries) ``` - 成下列 ``` gnujump_LDFLAGS = -Wl,--as-needed gnujump_LDADD = $(all_libraries) -lm ``` ``` I: gnujump source: quilt-patch-missing-description linker-fixes.patch ``` - 使用quilt header -e加入description - "You can edit the description with quilt header -e when the patch is at the top of the stack." ##### debian/copyright - 自動產生,有出現多個lintian warning,參考下方解Lintian warning的部份 ##### debian/changelog 使用`dch -i`來修改changelog檔案,基本上一次上傳只進一版(第一次的上傳所有修改都只會是x.x.x-1) 有幾個地方要修改一下 * unknown(UNRELEASED?)要改成unstable * bug number要改為自己的ITP number * 修改自己的名字、email ``` gnujump (1.0.8-1) unstable; urgency=low * Initial release. Closes: #123456 -- KaidenYu (余泊鎧) <kainonex@gmail.com> Mon, 24 Jun 2019 18:43:38 +0800 ``` ##### debian/rules 如果原始程式碼的Makefile並不是我們要的,例如說會install檔案到`/usr/local/bin`(我們沒有權限可以做這件事),那應該就必須要修改這個檔案。 ``` #!/usr/bin/make -f %: dh $@ --with autoreconf ``` 記住要把debmake產生的註解拿掉,如上。 ``` P: gnujump source: file-contains-trailing-whitespace debian/rules (line 4) ``` - 不要留空白的行 ##### debian/[pkg_name].manpages - 若無manpage,請在github上開issue請原作者加入,或參考別人的package加入後回饋給上游 - `[pkg_name].manpages`內新增manpage的位置,例如`[package].1 ``` doc/gnujump.6 ``` - 如果想要看manpage長什麼樣子,可用`nroff -man [package].1` - 位置在gnujump-1.0.8/doc/gnujump.6 ``` #在gnujump-1.0.8/ $ nroff -man doc/gnujump.6 ``` ##### debian/watch 1. 修改watch的檔案,可參考[官網介紹](https://wiki.debian.org/debian/watch)或[這邊的範例](https://salsa.debian.org/debian/buku/blob/debian/master/debian/watch) ``` version=4 ftp://ftp.gnu.org/gnu/gnujump gnujump-(.+)\.(?:zip|tgz|tbz|txz|(?:tar\.(?:gz|bz2|xz))) ``` - ftp官網上沒有範例(後續解lintian warning時改為https) - version=4: 此處version應該是表示這個watch檔的version - 參考[uscan的manpage](https://manpages.debian.org/buster/devscripts/uscan.1.en.html) ![](https://i.imgur.com/7RLt15Q.png) 用uscan測試 ``` # 測試方式 uscan --no-download --verbose # 如果要debug uscan --no-download --verbose --debug ``` ![](https://i.imgur.com/IQbxpDN.png) ##### debian/upstream 1. 在debian資料夾下新增upstream資料夾 ``` mkdir upstream ``` 2. 在upstream資料夾中新增metadata ``` cd upstream vi metadata ``` ![](https://i.imgur.com/KS0gK9P.png) - 有savannah及github mirror的source ``` Bug-Database: https://github.com/arximboldi/gnujump/issues Bug-Submit: https://github.com/arximboldi/gnujump/issues/new Name: gnujump Repository: https://github.com/arximboldi/gnujump.git Repository-Browse: https://github.com/arximboldi/gnujump ``` ##### debian/install ``` src/gnujump usr/bin/ ``` - 增加要搬移的位置,通常為usr/bin - gnujump會產生在gnujump-1.0.8/src/gnujump ##### debian/[package_name].docs 要記得創立debian/[package_name].docs,主要是要把README.md包入binary package內 最後修改完相關debian檔案後,git log要整理,第一次上套件的log只留一筆,內容可以寫"Initialize packaging"。 ##### debian/tests 實際上怎麼修改可以參考[4. autopkgtest: Automatic testing for packages](http://packaging.ubuntu.com/html/auto-pkg-test.html)和[Tutorial: Functional Testing of Debian Packages](https://annex.debconf.org/debconf-share/debconf15/slides/173-tutorial-functional-testing-of-debian-packages.pdf) 1. 首先先在debian底下新增tests資料夾 ``` mkdir tests ``` 2. tests底下增加control這個檔案,內容如下 - Tests右邊的build代表我們要測試的script file - Depends右邊的@代表相依檔案只有自己,如果有其他就加在這行 - 可參考[別人的範例](https://github.com/HypoPG/hypopg/blob/master/debian/tests/control) ``` Tests: build Depends: @ ``` 3. 接著新增build這個檔案 ```sh #!/bin/sh set -e echo "run start" # 要做的測試 echo "run: OK" ``` - gnujump的版本 ```sh #!/bin/sh set -e echo "test start" if [ -e "/usr/bin/gnujump" ]; then echo "test OK" else echo "test fail" fi ``` ##### 執行debuild 改完後就可以開始用debuild了,不過我們不是DD,所以可以跳過sign key的動作。 修改`~/.devscripts`或`/etc/devscripts.conf`為如下 ``` DEBUILD_LINTIAN=yes # -E include experimental tags DEBUILD_LINTIAN_OPTS="-i -EvIL +pedantic --show-overrides" #-uc -us代表不要sign key DEBUILD_DPKG_BUILDPACKAGE_OPTS="-uc -us --changes-option=-sa" # DEBSIGN_KEYID可填可不填 DEBSIGN_KEYID="FIXME - YOUR KEYID" DEB_BUILD_OPTIONS="parallel=10" ``` 執行完成後會在自己資料夾的上一層產生許多檔案,包括[套件名稱].dsc,這就是所謂的Debian source control files,之後如果要跑pubuilder也會需要用到。 ```sh $ debuild ``` &nbsp; - 若是有upstream source有改,會出錯 ![](https://i.imgur.com/e5NAIiU.png) - 在上層資料夾會產生一個.build,紀錄debuild執行的訊息 ![](https://i.imgur.com/hvavSpe.png) ##### 清除debuild產生的檔案 因為debuild會產生許多檔案,這些都是不用上git的。如果想要清除的話,可以用如下指令 ``` debuild -- clean ``` ##### 解決Lintian的問題 跑完後可能會出現Lintian相關的錯誤,相關錯誤的解法可參考[Solutions to some lintian warnings](https://hackmd.io/tsRaPMWTQACNbFZ5v05O-w) 1. I: gnujump source: out-of-date-standards-version 4.1.4 (released 2018-04-05) (current is 4.3.0) - debian/control中的Standards-Version改為4.3.0 &nbsp; 2. W: gnujump source: syntax-error-in-dep5-copyright line 511: Continuation line outside a paragraph (maybe line 510 should be " .") - debian/copyright 510行附近有幾行用井字號開頭的部份,中間有空白行,刪掉 ![](https://i.imgur.com/qihWlXN.png) &nbsp; 3. W: gnujump source: dep5-copyright-license-name-not-unique gpl-3.0+ (paragraph at line 370) - 此問題要解掉問題2才會出現 - 請參考[packaging-manuals/copyright-format/1.0](https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/) ![](https://i.imgur.com/GBcK3H4.png) - copyright檔案裡一般包含一個header paragraph和多個file paragraph - header paragraph如下所示 - ![](https://i.imgur.com/3j2IC0L.png) - file paragraph如下所示 - ![](https://i.imgur.com/pHLbSJq.png) - 在gnujump的這個例子裡 ![](https://i.imgur.com/rFGvTMk.png) - 可以看見License: GPL-3.0+下面有Lincense text,而且重複兩次,所以出現這個warning,可以使用Stand-alone License Paragraph來解決(可以參考SZ的[googler](https://salsa.debian.org/debian/googler/blob/debian/master/debian/copyright)) - ![](https://i.imgur.com/wNQI1jo.png) - 解完GPL-3.0+又會出現其他兩個License有同樣的錯誤,解法相同 - _SAME_ - GPL-2.0+ 4. W: gnujump source: file-without-copyright-information ChangeLog - ![](https://i.imgur.com/j3Dt01g.png) - ChangeLog、m4/ChangeLog、po/ChangeLog以及debian/*都沒有列在debian/copyright裡面,加入以下這個file paragraph ``` Files: debian/* ChangeLog m4/ChangeLog po/ChangeLog Copyright: 2019 KaidenYu (余泊鎧) <kainonex@gmail.com> License: GPL-3.0+ ``` 5. W: gnujump source: missing-license-paragraph-in-dep5-copyright __no_copyright_nor_license__ (paragraph at line 7) - 加入licnese text,如下所示 ![](https://i.imgur.com/oXEXzkY.png) 6. W: gnujump: old-fsf-address-in-copyright-file - ![](https://i.imgur.com/Y5uU9Ex.png) - debian/copyright用到舊的地址:Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - 改成新的地址:Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 7. E: gnujump: copyright-file-contains-full-gpl-license - ![](https://i.imgur.com/6UEsYUq.png) - debian/copyright裡面有GPL的全文,導致這個warning - ![](https://i.imgur.com/8nFUDL7.png) - lintian上有說在/usr/share/common-licenses/有GPL-1,GPL-2和GPL-3等等,可以使用cat看看 - ![](https://i.imgur.com/ufqyGKl.png) - ![](https://i.imgur.com/RGyZg5W.png) - 上圖cat的結果(GPL-3)可以發現真的跟copyright裡面的內容一樣,所以那些都刪掉並修改如下圖 - ![](https://i.imgur.com/6evIiCx.png) 8. W: gnujump: copyright-has-url-from-dh_make-boilerplate - ![](https://i.imgur.com/gzUkNAP.png) - ![](https://i.imgur.com/YCVAuq7.png) - debian/copyright中,將上圖中紅框的部份,修改如下 ``` Source: <https://github.com/arximboldi/gnujump> ``` 9. W: gnujump: readme-debian-contains-debmake-template - 修改debian/README.debian ``` gnujump for Debian This is a practice -- KaidenYu (余泊鎧) <kainonex@gmail.com> Tue, 15 Oct 2019 22:26:37 +0800 ``` - 此部份內容應該寫什麼需要在查資料,可先參考SZ的[範例](https://salsa.debian.org/debian/buku/blob/debian/master/debian/README.Debian) 10. I: gnujump: hardening-no-bindnow usr/bin/gnujump - [參考](https://hackmd.io/tsRaPMWTQACNbFZ5v05O-w) - 安裝blhc ``` sudo apt-get install blhc ``` - 執行blhc,但出錯 ![](https://i.imgur.com/VnKuC81.png) - 後來發現版本太舊,因為先前已經把/etc/apt/sources.list中 sid的部份註解掉了,取消註解然後update後再重新install,就可以用了 ![](https://i.imgur.com/W5u97UY.png) - [參考](https://eriberto.pro.br/blog/2015/09/07/debian-how-to-use-blhc-to-solve-hardening-issues-when-packaging/) - 直接把下面這行加到debina/rules就可以解,但這個解法不確定是否正確 ``` export DEB_BUILD_MAINT_OPTIONS = hardening=+all ``` ![](https://i.imgur.com/BwhqlnX.png) - 改完debian/rules後debuild,再用blhc指令就看不到東西了 ![](https://i.imgur.com/3lPKjgP.png) 11. I: gnujump source: debian-watch-uses-insecure-uri ftp://ftp.gnu.org/gnu/gnujump - debian/watch使用"ftp://"導致的 ![](https://i.imgur.com/uslcues.png) - 將ftp改成https即可 ![](https://i.imgur.com/efPuUz7.png) - 再使用uscan確認結果無誤 ![](https://i.imgur.com/FlEJqTC.png) 12. I: gnujump: spelling-error-in-binary usr/bin/gnujump Availible Available ![](https://i.imgur.com/HtS2KjA.png) - 先以"Availible"這個typo來說,使用grep找出錯字出現的地方(注意:lintian列出Availible但其實也有小寫的availible typo,把Availible解掉後才在lintian warning出現) ``` $ grep -wr Availible ``` ![](https://i.imgur.com/at4v73x.png) - 上圖中有很多Binary file開頭的訊息,基本上可以不用看(改source file就好),所以再使用grep把Binary file開頭的部份擋掉 ``` $ grep -wr 'Availible' | grep -v 'Binary file' ``` ![](https://i.imgur.com/Jxfz7bh.png) - 先切到patch branch(記得先debuild -- clean 不然好像會有問題) ``` $ git checkout patch-queue/debian/master ``` - 修改檔案:Availible和availible typo修掉 - git add 修改的檔案 - 用以下指令只加入modified的部份,不加入delete的,順便看git status ``` git status | grep modified | awk '{print $2}' | xargs git add && git status ``` - git commit - gbp pq export產生patch並回到debian/master branch ``` $ gbp pq export --no-patch-num ``` - debuild後lintian warning就部會出現Availible和availible的typo - 這時候debuild -- clean後再重新debuild卻發現出錯 ![](https://i.imgur.com/YzWoeFG.png) ![](https://i.imgur.com/AzICgH0.png) - 發現只要有去改動po/it.po或是po/tr.po就會導致po/it.gmo和po/tr.gmo這兩個binary file在debuild之後產生變化 - 照說明建立debian/source/include-binaries然後將這兩個binary file列進去 - [參考1](https://stackoverflow.com/questions/21057015/debian-include-binaries-format) - [參考2](https://manpages.debian.org/jessie/dpkg-dev/dpkg-source.1.en.html) ![](https://i.imgur.com/edMqIBm.png) - 依序把所有的typo修掉,步驟同上,要注意,若用下述指令把modified都加入,會連po/it.gmo和po/tr.gmo都加進去,可以用git reset HEAD拿掉 ``` $ git status | grep modified | awk '{print $2}' | xargs git add && git status $ git reset HEAD po/it.gmo $ git reset HEAD po/tr.gmo ``` 13. (未解)X: gnujump source: deprecated-configure-filename ![](https://i.imgur.com/XXYR0sT.png) 14. (未解)X: gnujump source: debian-watch-does-not-check-gpg-signature ![](https://i.imgur.com/iR1kTeR.png) #### 驗證修改 為了確認打包結果是否可以在一個乾淨的環境上執行,以及是否能通用在32, 64bit的系統上,所以要經過下面的測試。 ##### 使用pbuilder建立sid環境 使用pubuilder最主要的原因是debuild是在我們當前環境,可能不夠乾淨,pbuilder可以模擬一個乾淨的環境供我們測試是否有相依性或其他問題。 - [reference](http://wen00072.github.io/blog/2014/07/31/package-debian-packages-discussion-on-pbuilder/) 1. 安裝pbuilder後,首先設定`/etc/pbuilderrc` ```sh # this is your configuration file for pbuilder. # the file in /usr/share/pbuilder/pbuilderrc is the default template. # /etc/pbuilderrc is the one meant for overwriting defaults in # the default template # # read pbuilderrc.5 document for notes on specific options. MIRRORSITE=http://deb.debian.org/debian # the hook dir may already be set/populated! HOOKDIR="/var/cache/pbuilder/hooks/" if [ -n "$DEPS" ] ; then export DEPSBASE=/var/cache/pbuilder/deps BINDMOUNTS=$DEPSBASE fi ``` 2. pbuilder執行時會執行hook資料夾下設定的hook,通常我們會加入一個Lintian hook來做檢查。在`/var/cache/pbuilder/hooks/B90lintian`中輸入下面內容,相關example可在`/usr/share/doc/pbuilder/examples`找到。 - hooks和B90lintian都要自己建,owner改成kaiden - P.S. 每個不同功能的hook都有制式的名字,不能隨意輸入 ```dash #!/bin/dash set -e install_packages() { apt-get -y --allow-downgrades install "$@" } install_packages lintian echo "+++ lintian output +++" su -c "lintian -i -EvIL +pedantic --show-overrides /tmp/buildd/*.changes" - pbuilder # use this version if you don't want lintian to fail the build #su -c "lintian -i -I --show-overrides /tmp/buildd/*.changes; :" - pbuilder echo "+++ end of lintian output +++" ``` 3. 記得把`/var/cache/pbuilder/hooks/B90lintian`執行權限打開 ```shell chmod a+x /var/cache/pbuilder/hooks/B90lintian ``` 4. 由於我們要在SID的環境執行(也就是不穩定的Debian版本),可參考[這裡的設定](https://wiki.debian.org/PbuilderTricks),先創立`~/.pbuilderrc`(通常應該是`/root/.pbuilderrc`),然後貼上如下內容 - 請注意.pbuilderrc是要在root/不是home/[USER]/,可以在.pbuilderrc內容加上一些echo以確定有執行到 ```dash # Codenames for Debian suites according to their alias. Update these when # needed. echo "#######################################################" echo "Kaiden:This is root's .pbuilderrc modified by Kaiden:D" echo "#######################################################" UNSTABLE_CODENAME="sid" TESTING_CODENAME="buster" STABLE_CODENAME="stretch" STABLE_BACKPORTS_SUITE="$STABLE_CODENAME-backports" # List of Debian suites. DEBIAN_SUITES=($UNSTABLE_CODENAME $TESTING_CODENAME $STABLE_CODENAME $STABLE_BACKPORTS_SUITE "experimental" "unstable" "testing" "stable") # List of Ubuntu suites. Update these when needed. UBUNTU_SUITES=("xenial" "wily" "vivid" "utopic" "trusty") # Mirrors to use. Update these to your preferred mirror. DEBIAN_MIRROR="deb.debian.org" UBUNTU_MIRROR="mirrors.kernel.org" # Optionally use the changelog of a package to determine the suite to use if # none set. if [ -z "${DIST}" ] && [ -r "debian/changelog" ]; then DIST=$(dpkg-parsechangelog --show-field=Distribution) fi # Optionally set a default distribution if none is used. Note that you can set # your own default (i.e. ${DIST:="unstable"}). : ${DIST:="$(lsb_release --short --codename)"} # Optionally change Debian codenames in $DIST to their aliases. case "$DIST" in $UNSTABLE_CODENAME) DIST="unstable" ;; $TESTING_CODENAME) DIST="testing" ;; $STABLE_CODENAME) DIST="stable" ;; esac # Optionally set the architecture to the host architecture if none set. Note # that you can set your own default (i.e. ${ARCH:="i386"}). : ${ARCH:="$(dpkg --print-architecture)"} NAME="$DIST" if [ -n "${ARCH}" ]; then NAME="$NAME-$ARCH" DEBOOTSTRAPOPTS=("--arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}") fi BASETGZ="/var/cache/pbuilder/$NAME-base.tgz" DISTRIBUTION="$DIST" BUILDRESULT="/var/cache/pbuilder/$NAME/result/" APTCACHE="/var/cache/pbuilder/$NAME/aptcache/" BUILDPLACE="/var/cache/pbuilder/build/" HOOKDIR="/var/cache/pbuilder/hooks/" if $(echo ${DEBIAN_SUITES[@]} | grep -q $DIST); then # Debian configuration MIRRORSITE="http://$DEBIAN_MIRROR/debian/" COMPONENTS="main contrib non-free" if $(echo "$STABLE_CODENAME stable" | grep -q $DIST); then OTHERMIRROR="$OTHERMIRROR | deb $MIRRORSITE $STABLE_BACKPORTS_SUITE $COMPONENTS" fi elif $(echo ${UBUNTU_SUITES[@]} | grep -q $DIST); then # Ubuntu configuration MIRRORSITE="http://$UBUNTU_MIRROR/ubuntu/" COMPONENTS="main restricted universe multiverse" else echo "Unknown distribution: $DIST" exit 1 fi ``` 5. 建立pbuilder環境 ``` $ sudo OS=debian DIST=sid ARCH=i386 pbuilder create $ sudo OS=debian DIST=sid ARCH=amd64 pbuilder create ``` - 上述兩步驟做完,在`/var/cache/pbuilder`會看到 - unstable-amd64-base.tgz - unstable-i386-base.tgz - unstable-amd64 - unstable-i386 - ![](https://i.imgur.com/kyqHl6T.png) - 可以用以下指令登入到做好的.tgz ``` sudo OS=debian DIST=sid ARCH=i386 pbuilder --login sudo OS=debian DIST=sid ARCH=amd64 pbuilder --login ``` 6. 執行pbuilder ``` # 注意若changelog版本號有變,xxx.dsc的檔案名也要更動 $ sudo OS=debian DIST=sid ARCH=i386 pbuilder build [剛剛產生的的dsc檔].dsc $ sudo OS=debian DIST=sid ARCH=amd64 pbuilder build [剛剛產生的的dsc檔].dsc # 若有錯誤,修正後先跑debuild然後再重複上面pbuilder build的步驟 $ debuild ``` ``` $ sudo OS=debian DIST=sid ARCH=amd64 pbuilder build ../gnujump_1.0.8-1.dsc ``` ![](https://i.imgur.com/WJ9VlOJ.png) - 會花一點時間,最後也是做完lintian就結束 7. 若有更動/root/.pbuilderrc,記得更新pbuilder環境 ```sh $ sudo OS=debian DIST=sid ARCH=i386 pbuilder update --override-config --configfile ~/.pbuilderrc $ sudo OS=debian DIST=sid ARCH=amd64 pbuilder update --override-config --configfile ~/.pbuilderrc ``` #### 上傳salsa ##### 上傳debian/master ```shell $ git add . $ git commit -m "Initial packaging" $ git push --set-upstream origin debian/master ``` - username是"kainonex-guest",不是"KaidenYu" ##### 上傳pristine-tar ```shell $ git checkout pristine-tar $ git push --set-upstream origin pristine-tar ``` ##### 上傳upsream ```shell $ git checkout upstream $ git push --set-upstream origin upstream ``` ### C. Import and export gitlab project - 目的:想把先前gitlab的gnujump project備份到gnujump_backup project,然後重新做 - https://stackoverflow.com/questions/53155915/gitlab-copy-project-to-other-git-lab-repository 1. export ![](https://i.imgur.com/7t1tiMi.png) 2. import ![](https://i.imgur.com/QbdhQiz.png) ## Debian 套件打包教學指南試做 ### A. 環境與工具建製 #### pbuilder - [reference: PbuilderHowto](https://wiki.ubuntu.com/PbuilderHowto) 1.安裝需要的packages ```shell $ sudo apt-get install pbuilder debootstrap devscripts ``` 2.產生base tarball ```shell $ sudo pbuilder create --debootstrapopts --variant=buildd ``` --- ### B. 範例實做 #### gnujump 1. 下載source壓縮檔 ```shell $ wget http://ftp.gnu.org/gnu/gnujump/gnujump-1.0.8.tar.gz ``` 2. 將下載的source壓縮檔重新命名 ```shell $ mv gnujump-1.0.8.tar.gz gnujump_1.0.8.orig.tar.gz ``` 3. 解開source壓縮檔 ```shell $ tar xf gnujump_1.0.8.orig.tar.gz ``` 4. 進入解開後的資料夾 ```shell cd gnujump-1.0.8/ ``` 5. 使用dh7指令產生debian資料夾 ```shell $ dh_make -f ../gnujump-1.0.8.tar.gz ``` > 此步驟會出錯 > ![](https://i.imgur.com/tABP1io.png) > 因為第二步驟是用mv,所以gnujump-1.0.8.tar.gz這個檔案已經不存在,試了兩種做法 > A作法:第二步驟用cp取代mv,第五步驟不變 > B作法:第二步驟不變,第五步驟只下**dh_make**,後面-f ../gnujump-1.0.8.tar.gz捨去 > 6. 修改debian/control,加入缺少的Build-Depends: libsdl1.2-dev, libsdl-image1.2-dev, libsdl-mixer1.2-dev - ![](https://i.imgur.com/mgLv5Tr.png) 7. 透過quilt來準備補丁 ```shell $ export QUILT_PATCHES=debian/patches $ mkdir debian/patches $ quilt new linker-fixes.patch $ quilt add src/Makefile.am ``` 8. 修改src/Makefile.am - ![](https://i.imgur.com/rdTBc58.png) 9. 執行quilt refresh ```shell $ quilt refresh ``` 10. 修改debian/rules - ![](https://i.imgur.com/mxdVWe3.png) 11. 使用pbuilder版本的debuild,完成後會在/var/cache/pbuilder/result內產生package ```shell $ pdebuild ``` 12. 進入/var/cache/pbuilder/result內,並安裝package ``` $ cd /var/cache/pbuilder/result $ sudo dpkg -i gnujump_1.0.8-1_amd64.deb ``` - ![](https://i.imgur.com/ep1buPL.png) ## 未整理 - wnpp-check使用問題 ``` $ wnpp-check [套件名] ``` ![](https://i.imgur.com/nniHsRf.png) > 看起來是只會show出 1.being packaged (ITPed) 2.being requested (RFPed) >> WNPP(Work-Needing and Prospective Packages) >> ITP(intent to package) [reference](https://wiki.debian.org/ITP) >> RFP(request for package) [reference](https://wiki.debian.org/RFP) &nbsp; ![](https://i.imgur.com/ezvuQSM.png) > 有些package什麼都不會show,期待的輸出是什麼?