在Ubuntu下如何创建远程".deb"包仓库

简介:

在Ubuntu下如何创建远程".deb"包仓库

Reprepro是一款小巧的命令行工具来方便地创建并管理.deb仓库。今天我们会展示给你如何使用reprepro简单地创建一个Debian包仓库,并使用rsync上传到Sourceforge.net。

步骤 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) 2013 Free Software Foundation, Inc.
  2. This is free software: you are free to change and redistribute it.
  3. There is NO WARRANTY, to the extent permitted by law.
  4.  
  5. Please select what kind of key you want:
  6. (1) RSA and RSA (default)
  7. (2) DSA and Elgamal
  8. (3) DSA (sign only)
  9. (4) RSA (sign only)
  10. Your selection?
  11. RSA keys may be between 1024 and 4096 bits long.
  12. What keysize do you want? (2048)
  13. Requested keysize is 2048 bits
  14. Please specify how long the key should be valid.
  15. 0 = key does not expire
  16. = key expires in n days
  17. w = key expires in n weeks
  18. m = key expires in n months
  19. y = key expires in n years
  20. Key is valid for? (0)
  21. Key does not expire at all
  22. Is this correct? (y/N) Y
  23.  
  24. You need a user ID to identify your key; the software constructs the user ID
  25. from the Real Name, Comment and Email Address in this form:
  26. "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
  27.  
  28. Real name: ravisaive
  29. Email address: tecmint.com@gmail.com
  30. Comment: tecmint
  31. You selected this USER-ID:
  32. "Ravi Saive (tecmint) <tecmint.com@gmail.com>"
  33.  
  34. Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
  35. You need a Passphrase to protect your secret key.
  36.  
  37. We need to generate a lot of random bytes. It is a good idea to perform
  38. some other action (type on the keyboard, move the mouse, utilize the
  39. disks) during the prime generation; this gives the random number
  40. generator a better chance to gain enough entropy.
  41.  
  42. +++++
  43. gpg: key 2EB446DD marked as ultimately trusted
  44. public and secret key created and signed.
  45.  
  46. gpg: checking the trustdb
  47. gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
  48. gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
  49. pub 2048R/2EB446DD 2014-06-24
  50. Key fingerprint = D222 B1C9 342E 5911 02B1 9147 3BD6 7918 2EB4 46DD
  51. uid Ravi Saive (tecmint) <tecmint.com@gmail.com>
  52. sub 2048R/7EF2F750 2014-06-24

现在你的key已经生成了,要检查一下,用root权限运行这条命令。

 
 
  1. $ sudo gpg --list-keys

示例输出

 
 
  1. /home/ravisaive/.gnupg/pubring.gpg
  2. ----------------------------------
  3. pub 2048R/2EB446DD 2014-06-24
  4. uid ravisaive (tecmint) <tecmint.com@gmail.com>
  5. sub 2048R/7EF2F750 2014-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 yourmail@mail.com >> /var/www/apt/key/deb.gpg.key

注意:用你之前步骤中输入的用户名代替username,用你的email代替上面的yourmail@mail.com

我们需要在/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. Exporting Trusty...
  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) <tecmint.com@gmail.com> needs a passphrase
  8. Please enter passphrase:
  9. Successfully created '/var/www/apt/dists/Trusty/Release.gpg.new'
  10. FF5097B479C8220C ravisaive (tecmint) <tecmint.com@gmail.com> 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) <tecmint.com@gmail.com> needs a passphrase
  8. Please enter passphrase:
  9. Successfully created './dists/Trusty/Release.gpg.new'
  10. FF5097B479C8220C ravisaive (tecmint) <tecmint.com@gmail.com> 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/ username@frs.sourceforge.net:/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

祝贺你! 你的软件仓库已经激活了!你现在可以非常简单地在你需要的时候安装包了。

原文发布时间:2014-07-14

本文来自云栖合作伙伴“linux中国”

目录
相关文章
|
3月前
|
Ubuntu Linux 时序数据库
|
Oracle Ubuntu 关系型数据库
Ubuntu安装MySQL(RPM包安装)
Ubuntu安装MySQL(RPM包安装)
617 0
|
5月前
|
Ubuntu Linux
仓库 “https://mirrors.aliyun.com/docker-ce/linux/ubuntu una Release” 没有 Release 文件
仓库 “https://mirrors.aliyun.com/docker-ce/linux/ubuntu una Release” 没有 Release 文件
169 0
|
8月前
|
Ubuntu Perl
Ubuntu已删除包的残余文件删除命令
Ubuntu已删除包的残余文件删除命令
90 0
|
Ubuntu 关系型数据库 MySQL
远程在线给Ubuntu安装MySQL,Navicat远程连接数据库(详细过程和避坑事项)
这里使用XShell连接服务器,设置主机ip,ssh远程连接即可。如此可用命令去操纵服务器。
542 0
远程在线给Ubuntu安装MySQL,Navicat远程连接数据库(详细过程和避坑事项)
|
Ubuntu 安全 网络协议
Ubuntu SSH连接、远程上传下载文件
Ubuntu SSH连接、远程上传下载文件
793 0
|
Ubuntu Linux 网络安全
linux实用技巧:ubuntu从零开始拉取远程git空仓库并提交代码及git相关其他问题
linux实用技巧:ubuntu从零开始拉取远程git空仓库并提交代码及git相关其他问题
linux实用技巧:ubuntu从零开始拉取远程git空仓库并提交代码及git相关其他问题
|
Ubuntu Unix Linux
xming + putty 搭建远程图形化ssh访问ubuntu 14.04
xming + putty 搭建远程图形化ssh访问ubuntu 14.04
261 0
xming + putty 搭建远程图形化ssh访问ubuntu 14.04
|
Ubuntu 关系型数据库 MySQL
Ubuntu 通过 Deb 安装 MySQL| 学习笔记
快速学习 Ubuntu 通过 Deb 安装 MySQL
224 0