歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 在Ubuntu下如何創建遠程“.deb”包倉庫

在Ubuntu下如何創建遠程“.deb”包倉庫

日期:2017/2/28 14:30:06   编辑:Linux教程

Reprepro是一款小巧的命令行工具來方便地創建並管理.deb倉庫。今天我們會展示給你如何使用reprepro簡單地創建一個Debian包倉庫,並使用rsync上傳到Sourceforge.net。

Ubuntu下deb包的安裝方法 http://www.linuxidc.com/Linux/2014-03/99037.htm

步驟 1: 安裝Reprepro並生成key

首先,安裝所有需要的包,使用下面的apt-get命令。

  1. $ sudo apt-get install reprepro gnupg

現在你需要使用gnupg生成一個gpg key,這裡使用下面的命令。

  1. $ gpg --gen-key

它會詢問你一些問題,比如你想要哪種key、key的有效期、如果你不知道如何回答,只需點擊回車 來選擇默認選項(建議)

當然,它會詢問你用戶名和密碼,在腦海中記住這些,因為我們會在之後需要它。

  1. gpg (GnuPG)1.4.14;Copyright(C)2013FreeSoftwareFoundation,Inc.
  2. Thisis free software: you are free to change and redistribute it.
  3. Thereis NO WARRANTY, to the extent permitted by law.
  4. Pleaseselect what kind of key you want:
  5. (1) RSA and RSA (default)
  6. (2) DSA andElgamal
  7. (3) DSA (sign only)
  8. (4) RSA (sign only)
  9. Your selection?
  10. RSA keys may be between 1024and4096 bits long.
  11. What keysize do you want?(2048)
  12. Requested keysize is2048 bits
  13. Please specify how long the key should be valid.
  14. 0= key does not expire
  15. = key expires in n days
  16. w = key expires in n weeks
  17. m = key expires in n months
  18. y = key expires in n years
  19. Keyis valid for?(0)
  20. Key does not expire at all
  21. Isthis correct?(y/N) Y
  22. You need a user ID to identify your key; the software constructs the user ID
  23. from the RealName,CommentandEmailAddressinthis form:
  24. "Heinrich Heine (Der Dichter) <[email protected]>"
  25. Real name: ravisaive
  26. Email address: [email protected]
  27. Comment: tecmint
  28. You selected this USER-ID:
  29. "Ravi Saive (tecmint) <[email protected]>"
  30. Change(N)ame,(C)omment,(E)mail or(O)kay/(Q)uit? O
  31. You need a Passphrase to protect your secret key.
  32. We need to generate a lot of random bytes.Itis a good idea to perform
  33. some other action (type on the keyboard, move the mouse, utilize the
  34. disks) during the prime generation;this gives the random number
  35. generator a better chance to gain enough entropy.
  36. +++++
  37. gpg: key 2EB446DD marked as ultimately trusted
  38. publicand secret key created andsigned.
  39. gpg: checking the trustdb
  40. gpg:3 marginal(s) needed,1 complete(s) needed, PGP trust model
  41. gpg: depth:0 valid:1signed:0 trust:0-,0q,0n,0m,0f,1u
  42. pub 2048R/2EB446DD2014-06-24
  43. Key fingerprint = D222 B1C9 342E591102B191473BD679182EB446DD
  44. uid RaviSaive(tecmint)<[email protected]>
  45. sub2048R/7EF2F7502014-06-24

現在你的key已經生成了,要檢查一下,用root權限運行這條命令。

  1. $ sudo gpg --list-keys

示例輸出

  1. /home/ravisaive/.gnupg/pubring.gpg
  2. ----------------------------------
  3. pub 2048R/2EB446DD2014-06-24
  4. uid ravisaive (tecmint)<[email protected]>
  5. sub2048R/7EF2F7502014-06-24

步驟 2: 創建一個包倉庫並導出key

我們現在要開始創建倉庫,首先你需要創建一些文件夾,我們的倉庫會放在/var/www/apt目錄,讓我們先創建這些目錄。

  1. $ sudo su
  2. # cd /var/www
  3. # mkdir apt
  4. # mkdir -p ./apt/incoming
  5. # mkdir -p ./apt/conf
  6. # mkdir -p ./apt/key

你現在需要將key導出到倉庫文件夾,運行:

  1. # gpg --armor --export username [email protected] >> /var/www/apt/key/deb.gpg.key

注意:用你之前步驟中輸入的用戶名代替username,用你的email代替上面的[email protected]

我們需要在/var/www/apt/conf創建一個文件“distributions”。

  1. # touch /var/www/apt/conf/distributions

加入下面這幾行到distributions這個文件中並保存。

  1. Origin:(你的名字)
  2. Label:(庫的名字)
  3. Suite:(stable 或 unstable)
  4. Codename:(發布的代碼名,比如 trusty)
  5. Version:(發布的版本,比如14.04)
  6. Architectures:(軟件包所支持的架構,比如 i386 或 amd64)
  7. Components:(包含的部件,比如 main restricted universe multiverse)
  8. Description:(描述)
  9. SignWith: yes

接下來我們會創建倉庫樹,運行這些命令:

  1. # reprepro --ask-passphrase -Vb /var/www/apt export

示例輸出

  1. Created directory "/var/www/apt/db"
  2. ExportingTrusty...
  3. Created directory "/var/www/apt/dists"
  4. Created directory "/var/www/apt/dists/Trusty"
  5. Created directory "/var/www/apt/dists/Trusty/universe"
  6. Created directory "/var/www/apt/dists/Trusty/universe/binary-i386"
  7. FF5097B479C8220C ravisaive (tecmint)<[email protected]> needs a passphrase
  8. Please enter passphrase:
  9. Successfully created '/var/www/apt/dists/Trusty/Release.gpg.new'
  10. FF5097B479C8220C ravisaive (tecmint)<[email protected]> needs a passphrase
  11. Please enter passphrase:
  12. Successfully created '/var/www/apt/dists/Trusty/InRelease.new'

步驟 3: 在新創建的倉庫中加入包

現在准備你的.deb包來加入到倉庫中。進入 /var/www/apt目錄,你每次要加包的時候都必須這麼做。

  1. # cd /var/www/apt
  2. # reprepro --ask-passphrase -Vb . includedeb Trusty /home/ravisaive/packages.deb

注意:用你在distributions文件中輸入的倉庫代號來代替trusty ,並且用包的路徑替換/home/username/package.deb,你會被要求輸入密碼。

示例輸出

  1. /home/ravisaive/packages.deb : component guessed as'universe'
  2. Created directory "./pool"
  3. Created directory "./pool/universe"
  4. Created directory "./pool/universe/o"
  5. Created directory "./pool/universe/o/ojuba-personal-lock"
  6. Exporting indices...
  7. FF5097B479C8220C ravisaive (tecmint)<[email protected]> needs a passphrase
  8. Please enter passphrase:
  9. Successfully created './dists/Trusty/Release.gpg.new'
  10. FF5097B479C8220C ravisaive (tecmint)<[email protected]> needs a passphrase
  11. Please enter passphrase:
  12. Successfully created './dists/Trusty/InRelease.new'

你的包已經加入了倉庫,如果要移除它的話采用如下命令:

  1. # reprepro --ask-passphrase -Vb /var/www/apt remove trusty package.deb

當然你需要用你的包名與倉庫代號來修改命令。

步驟 4: 上傳倉庫到Sourceforge.net

要上傳倉庫到Sourceforge.net,你當然需要一個可用的賬號與一個可用的項目,讓我假設你想要上傳倉庫到http://sourceforge.net/projects/myfoo/testrepository,這裡的myfoo是項目名(UNIX上的名稱,不是URL,不是標題),testrepository是你想要上傳文件到這上面的目錄,這裡我們會使用rsync 命令。(LCTT譯注:當然你也可以上傳到其它的支持Http/Rsync的服務器上,以提供遠程軟件庫的服務。)

  1. # rsync -avP -e ssh /var/www/apt/ [email protected]:/home/frs/project/myfoo/testrepository/

注意:用你在sourceforge.net上的用戶名代替username,用你的項目的UNIX名稱代替myfoo,用你想要存儲的文件夾代替testrepository。

現在你的倉庫(包括設置和key等等)上傳到了http://sourceforge.net/projects/myfoo/testrepository

要把它加入到一個已裝好的系統,首先你需要導入倉庫key,它實際上就是/var/www/apt/key/deb.gpg.key,但是這是一個本地路徑,使用你的倉庫的其它用戶不能添加到他們的系統中,這就是為什麼我們要導入來自sourceforge.net的key的原因。

  1. $ sudo su
  2. # wget -O - http://sourceforge.net/projects/myfoo/testrepository/apt/key/deb.gpg.key | apt-key add -

你現在可以非常輕松地把倉庫加入到系統中了,打開/etc/apt/sources.list,並加入下面這行:

  1. deb http://sourceforge.net/projects/myfoo/testrepository/apt/key/deb.gpg.key trusty main

Note:用你的項目的UNIX類型名稱代替myfoo,用你的倉庫代碼代替trusty,用你上傳存儲的文件夾代替testrepository,用你在distributionsj加入的倉庫組件代替main。

接下來,運行下面的命令來更新倉庫列表。

  1. $ sudo apt-get update

祝賀你! 你的軟件倉庫已經激活了!你現在可以非常簡單地在你需要的時候安裝包了。


via: http://www.tecmint.com/create-deb-pacakge-repository-in-ubuntu/

譯者:geekpi 校對:wxy

本文由 LCTT 原創翻譯,Linux中國 榮譽推出

更多Ubuntu相關信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2

Copyright © Linux教程網 All Rights Reserved