2014-07-14 21:18:00 +08:00
|
|
|
|
在Ubuntu下如何创建远程".deb"包仓库
|
2014-06-25 13:34:10 +08:00
|
|
|
|
================================================================================
|
2014-07-14 21:18:00 +08:00
|
|
|
|
**Reprepro**是一款小巧的命令行工具来方便地创建并管理**.deb**仓库。今天我们会展示给你如何使用reprepro简单地创建一个Debian包仓库,并使用**rsync**上传到Sourceforge.net。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
![Create Deb Package Repository](http://www.tecmint.com/wp-content/uploads/2014/06/Create-Debian-Package-Repository1.png)
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
### 步骤 1: 安装Reprepro并生成key ###
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
首先,安装所有需要的包,使用下面的apt-get命令。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
$ sudo apt-get install reprepro gnupg
|
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
现在你需要使用gnupg生成一个gpg key,这里使用下面的命令。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
$ gpg --gen-key
|
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
它会询问你一些问题,比如你想要哪种key、key的有效期、如果你不知道如何回答,只需点击**回车** 来选择默认选项(建议)
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
当然,它会询问你用户名和密码,在脑海中记住这些,因为我们会在之后需要它。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
gpg (GnuPG) 1.4.14; Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
|
|
This is free software: you are free to change and redistribute it.
|
|
|
|
|
There is NO WARRANTY, to the extent permitted by law.
|
|
|
|
|
|
|
|
|
|
Please select what kind of key you want:
|
|
|
|
|
(1) RSA and RSA (default)
|
|
|
|
|
(2) DSA and Elgamal
|
|
|
|
|
(3) DSA (sign only)
|
|
|
|
|
(4) RSA (sign only)
|
|
|
|
|
Your selection?
|
|
|
|
|
RSA keys may be between 1024 and 4096 bits long.
|
|
|
|
|
What keysize do you want? (2048)
|
|
|
|
|
Requested keysize is 2048 bits
|
|
|
|
|
Please specify how long the key should be valid.
|
|
|
|
|
0 = key does not expire
|
|
|
|
|
= key expires in n days
|
|
|
|
|
w = key expires in n weeks
|
|
|
|
|
m = key expires in n months
|
|
|
|
|
y = key expires in n years
|
|
|
|
|
Key is valid for? (0)
|
|
|
|
|
Key does not expire at all
|
|
|
|
|
Is this correct? (y/N) Y
|
|
|
|
|
|
|
|
|
|
You need a user ID to identify your key; the software constructs the user ID
|
|
|
|
|
from the Real Name, Comment and Email Address in this form:
|
|
|
|
|
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
|
|
|
|
|
|
|
|
|
|
Real name: ravisaive
|
|
|
|
|
Email address: tecmint.com@gmail.com
|
|
|
|
|
Comment: tecmint
|
|
|
|
|
You selected this USER-ID:
|
|
|
|
|
"Ravi Saive (tecmint) <tecmint.com@gmail.com>"
|
|
|
|
|
|
|
|
|
|
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
|
|
|
|
|
You need a Passphrase to protect your secret key.
|
|
|
|
|
|
|
|
|
|
We need to generate a lot of random bytes. It is a good idea to perform
|
|
|
|
|
some other action (type on the keyboard, move the mouse, utilize the
|
|
|
|
|
disks) during the prime generation; this gives the random number
|
|
|
|
|
generator a better chance to gain enough entropy.
|
|
|
|
|
|
|
|
|
|
+++++
|
|
|
|
|
gpg: key 2EB446DD marked as ultimately trusted
|
|
|
|
|
public and secret key created and signed.
|
|
|
|
|
|
|
|
|
|
gpg: checking the trustdb
|
|
|
|
|
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
|
|
|
|
|
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
|
|
|
|
|
pub 2048R/2EB446DD 2014-06-24
|
|
|
|
|
Key fingerprint = D222 B1C9 342E 5911 02B1 9147 3BD6 7918 2EB4 46DD
|
|
|
|
|
uid Ravi Saive (tecmint) <tecmint.com@gmail.com>
|
|
|
|
|
sub 2048R/7EF2F750 2014-06-24
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
现在你的key已经生成了,要检查一下,用root权限运行这条命令。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
$ sudo gpg --list-keys
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
#### 示例输出 ####
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
/home/ravisaive/.gnupg/pubring.gpg
|
|
|
|
|
----------------------------------
|
|
|
|
|
pub 2048R/2EB446DD 2014-06-24
|
|
|
|
|
uid ravisaive (tecmint) <tecmint.com@gmail.com>
|
|
|
|
|
sub 2048R/7EF2F750 2014-06-24
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
### 步骤 2: 创建一个包仓库并导出key ###
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
我们现在要开始创建仓库,首先你需要创建一些文件夹,我们的仓库会放在**/var/www/apt**目录,让我们先创建这些目录。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
$ sudo su
|
|
|
|
|
# cd /var/www
|
|
|
|
|
# mkdir apt
|
|
|
|
|
# mkdir -p ./apt/incoming
|
|
|
|
|
# mkdir -p ./apt/conf
|
|
|
|
|
# mkdir -p ./apt/key
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
你现在需要将key导出到仓库文件夹,运行:
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
# gpg --armor --export username yourmail@mail.com >> /var/www/apt/key/deb.gpg.key
|
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
注意:用你之前步骤中输入的用户名代替username,用你的email代替上面的yourmail@mail.com。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
我们需要在**/var/www/apt/conf**创建一个文件“**distributions**”。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
# touch /var/www/apt/conf/distributions
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
加入下面这几行到distributions这个文件中并保存。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
Origin: (你的名字)
|
|
|
|
|
Label: (库的名字)
|
|
|
|
|
Suite: (stable 或 unstable)
|
|
|
|
|
Codename: (发布的代码名,比如 trusty)
|
|
|
|
|
Version: (发布的版本,比如 14.04)
|
|
|
|
|
Architectures: (软件包所支持的架构, 比如 i386 或 amd64)
|
|
|
|
|
Components: (包含的部件,比如 main restricted universe multiverse)
|
|
|
|
|
Description: (描述)
|
2014-06-25 13:34:10 +08:00
|
|
|
|
SignWith: yes
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
接下来我们会创建仓库树,运行这些命令:
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
# reprepro --ask-passphrase -Vb /var/www/apt export
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
#### 示例输出 ####
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
Created directory "/var/www/apt/db"
|
|
|
|
|
Exporting Trusty...
|
|
|
|
|
Created directory "/var/www/apt/dists"
|
|
|
|
|
Created directory "/var/www/apt/dists/Trusty"
|
|
|
|
|
Created directory "/var/www/apt/dists/Trusty/universe"
|
|
|
|
|
Created directory "/var/www/apt/dists/Trusty/universe/binary-i386"
|
|
|
|
|
FF5097B479C8220C ravisaive (tecmint) <tecmint.com@gmail.com> needs a passphrase
|
|
|
|
|
Please enter passphrase:
|
|
|
|
|
Successfully created '/var/www/apt/dists/Trusty/Release.gpg.new'
|
|
|
|
|
FF5097B479C8220C ravisaive (tecmint) <tecmint.com@gmail.com> needs a passphrase
|
|
|
|
|
Please enter passphrase:
|
|
|
|
|
Successfully created '/var/www/apt/dists/Trusty/InRelease.new'
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
### 步骤 3: 在新创建的仓库中加入包 ###
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
现在准备你的**.deb**包来加入到仓库中。进入 **/var/www/apt**目录,你每次要加包的时候都必须这么做。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
# cd /var/www/apt
|
|
|
|
|
# reprepro --ask-passphrase -Vb . includedeb Trusty /home/ravisaive/packages.deb
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
**注意**:用你在distributions文件中输入的仓库代号来代替**trusty** ,并且用包的路径替换**/home/username/package.deb**,你会被要求输入密码。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
#### 示例输出####
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
/home/ravisaive/packages.deb : component guessed as 'universe'
|
|
|
|
|
Created directory "./pool"
|
|
|
|
|
Created directory "./pool/universe"
|
|
|
|
|
Created directory "./pool/universe/o"
|
|
|
|
|
Created directory "./pool/universe/o/ojuba-personal-lock"
|
|
|
|
|
Exporting indices...
|
|
|
|
|
FF5097B479C8220C ravisaive (tecmint) <tecmint.com@gmail.com> needs a passphrase
|
|
|
|
|
Please enter passphrase:
|
|
|
|
|
Successfully created './dists/Trusty/Release.gpg.new'
|
|
|
|
|
FF5097B479C8220C ravisaive (tecmint) <tecmint.com@gmail.com> needs a passphrase
|
|
|
|
|
Please enter passphrase:
|
|
|
|
|
Successfully created './dists/Trusty/InRelease.new'
|
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
你的包已经加入了仓库,如果要移除它的话采用如下命令:
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
# reprepro --ask-passphrase -Vb /var/www/apt remove trusty package.deb
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
当然你需要用你的包名与仓库代号来修改命令。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
### 步骤 4: 上传仓库到Sourceforge.net ###
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
要上传仓库到**Sourceforge.net**,你当然需要一个可用的账号与一个可用的项目,让我假设你想要上传仓库到**http://sourceforge.net/projects/myfoo/testrepository**,这里的myfoo是项目名(UNIX上的名称,不是URL,不是标题),testrepository是你想要上传文件到这上面的目录,这里我们会使用[rsync 命令][1]。(LCTT译注:当然你也可以上传到其它的支持Http/Rsync的服务器上,以提供远程软件库的服务。)
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
# rsync -avP -e ssh /var/www/apt/ username@frs.sourceforge.net:/home/frs/project/myfoo/testrepository/
|
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
**注意**:用你在sourceforge.net上的用户名代替username,用你的项目的UNIX名称代替myfoo,用你想要存储的文件夹代替testrepository。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
现在你的仓库(包括设置和key等等)上传到了**http://sourceforge.net/projects/myfoo/testrepository**。
|
|
|
|
|
|
|
|
|
|
要把它加入到一个已装好的系统,首先你需要导入仓库key,它实际上就是**/var/www/apt/key/deb.gpg.key**,但是这是一个本地路径,使用你的仓库的其它用户不能添加到他们的系统中,这就是为什么我们要导入来自sourceforge.net的key的原因。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
$ sudo su
|
|
|
|
|
# wget -O - http://sourceforge.net/projects/myfoo/testrepository/apt/key/deb.gpg.key | apt-key add -
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
你现在可以非常轻松地把仓库加入到系统中了,打开**/etc/apt/sources.list**,并加入下面这行:
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
deb http://sourceforge.net/projects/myfoo/testrepository/apt/key/deb.gpg.key trusty main
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
**Note**:用你的项目的UNIX类型名称代替myfoo,用你的仓库代码代替trusty,用你上传存储的文件夹代替testrepository,用你在distributionsj加入的仓库组件代替main。
|
|
|
|
|
|
|
|
|
|
接下来,运行下面的命令来更新仓库列表。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
$ sudo apt-get update
|
|
|
|
|
|
2014-06-26 10:42:20 +08:00
|
|
|
|
**祝贺你**! 你的软件仓库已经激活了!你现在可以非常简单地在你需要的时候安装包了。
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
via: http://www.tecmint.com/create-deb-pacakge-repository-in-ubuntu/
|
|
|
|
|
|
2014-07-14 21:18:00 +08:00
|
|
|
|
译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
|
2014-06-25 13:34:10 +08:00
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
|
|
|
|
|
2014-06-26 10:01:59 +08:00
|
|
|
|
[1]:http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/
|