网站搜索

在 Ubuntu 中使用“Reprepro”工具在 Sourceforge.net 创建“.deb 包存储库”


Reprepro 是一个小型命令行工具,可以轻松创建和管理 .deb 存储库,今天我们将展示如何使用 reprepro 轻松创建 Debian 软件包存储库以及如何使用rsync命令将其上传到Sourceforge.net。

第 1 步:安装 Reprepro 并生成密钥

首先,使用以下 apt-get 命令安装所有必需的软件包。

sudo apt-get install reprepro gnupg

现在您需要使用 gnupg 生成 gpg 密钥,为此,请应用此命令。

gpg --gen-key

它会问你一些问题,比如你想要的密钥类型,密钥的有效期限,如果你不知道回答什么,只需点击Enter默认选项(推荐)。

当然,它会要求您输入用户名和密码,请记住这些,因为我们稍后会需要它们。

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) <[email >"

Real name: ravisaive
Email address: [email 
Comment: tecmint
You selected this USER-ID:
    "Ravi Saive (tecmint) <[email >"

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) <[email >
sub   2048R/7EF2F750 2014-06-24

现在您的密钥将被生成,要检查是否是这样,请以 root 权限运行此命令。

sudo gpg --list-keys
样本输出
/home/ravisaive/.gnupg/pubring.gpg
----------------------------------
pub   2048R/2EB446DD 2014-06-24
uid                  ravisaive (tecmint) <[email >
sub   2048R/7EF2F750 2014-06-24

第 2 步:创建包存储库和导出密钥

我们现在开始创建存储库,首先你必须创建一些文件夹,我们的存储库将位于 /var/www/apt 目录中,所以让我们创建一些文件夹。

sudo su
cd /var/www
mkdir apt
mkdir -p ./apt/incoming 
mkdir -p ./apt/conf
mkdir -p ./apt/key

您现在必须将创建的密钥导出到存储库文件夹,然后运行。

gpg --armor --export username [email  >> /var/www/apt/key/deb.gpg.key

注意:将用户名替换为您在上述步骤中输入的用户名,将 [email 替换为您的电子邮件地址。

我们需要在 /var/www/apt/conf 中创建一个名为“distributions”的文件。

touch /var/www/apt/conf/distributions

将以下行添加到发行版文件中并保存文件。

Origin: (yourname)
Label: (name of repository)
Suite: (stable or unstable)
Codename: (the codename for the distribution you are using, like trusty)
Version: (the version for the distribution you are using, like 14.04)
Architectures: (the repository packages  architecture, like i386 or amd64)
Components: (main restricted universe multiverse)
Description: (Some information about the repository)
SignWith: yes

接下来,我们必须创建存储库树,为此,请运行这些命令。

reprepro --ask-passphrase -Vb /var/www/apt export
样本输出
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) <[email > needs a passphrase
Please enter passphrase:
Successfully created '/var/www/apt/dists/Trusty/Release.gpg.new'
FF5097B479C8220C ravisaive (tecmint) <[email > needs a passphrase
Please enter passphrase:
Successfully created '/var/www/apt/dists/Trusty/InRelease.new'

第 3 步:将包添加到新创建的存储库中

现在准备要添加到存储库的 .deb 包。转到 /var/www/apt 目录,每次要添加包时都必须执行此操作。

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

注意:将 trusty 替换为您在发行版文件中为存储库输入的代号,并替换 /home/username/package .deb 和包的路径,系统将要求您输入密码。

样本输出
/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) <[email > needs a passphrase
Please enter passphrase:
Successfully created './dists/Trusty/Release.gpg.new'
FF5097B479C8220C ravisaive (tecmint) <[email > needs a passphrase
Please enter passphrase:
Successfully created './dists/Trusty/InRelease.new'

您的包已添加到存储库中,然后将其删除。

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 来执行此操作命令。

rsync -avP -e ssh /var/www/apt/ [email :/home/frs/project/myfoo/testrepository/

注意:将 username 替换为您在 sourceforge.net 上的用户名,将 myfoo 替换为您的项目 UNIX 名称,将 testrepository 替换为您要存储文件的文件夹。

现在您的存储库已上传到http://sourceforge.net/projects/myfoo/testrepository,要将其添加到您已安装的系统中,首先您必须导入存储库密钥,它将位于< b>/var/www/apt/key/deb.gpg.key,但这是本地路径,您的存储库的用户将无法将其添加到他们的系统中,这就是为什么我们会从 sourceforge.net 导入密钥。

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

您现在可以轻松地将存储库添加到您的系统中,打开 /etc/apt/sources.list 并添加此行。

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

注意:将 myfoo 替换为您的项目 UNIX-Name,trusty 替换为您的存储库代号,testrepository 替换为您将文件上传到的文件夹,main 替换为您添加到的存储库组件分发文件。

接下来,运行以下命令来更新存储库列表。

sudo apt-get update

恭喜!您的存储库已激活!如果需要,您现在可以轻松地从中安装软件包。