Create A “.deb Pacakge Repository” at Sourceforge.net Using “Reprepro” Tool in Ubuntu
================================================================================
**Reprepro** is a small command-line tool to create and manage **.deb** repositories easily, Today we’ll be showing how to create a Debian package repositories easily using reprepro and how to upload it to Sourceforge.net using **rsync** command.

![Create Deb Package Repository](http://www.tecmint.com/wp-content/uploads/2014/06/Create-Debian-Package-Repository1.png)

### Step 1: Install Reprepro and Generate Key ###

First, install all the necessary packages, using the following apt-get command.

    $ sudo apt-get install reprepro gnupg

Now you need to generate a gpg key using gnupg, to do this, apply this command.

    $ gpg --gen-key

It will ask you some questions, like the kind of the key you want, how long the key should be valid, if you don’t know what to answer, just click **Enter** for the default options (recommended).

Of course, it will ask you for a username and a password, keep those in mind, because we will need them later.

    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

Now your key will be generated, to Check if so, run this command as a root privileges.

    $ sudo gpg --list-keys

#### Sample Output ####

    /home/ravisaive/.gnupg/pubring.gpg
    ----------------------------------
    pub   2048R/2EB446DD 2014-06-24
    uid                  ravisaive (tecmint) <tecmint.com@gmail.com>
    sub   2048R/7EF2F750 2014-06-24

### Step 2: Create a Package Repository and Export Key ###

We’ll start the work now to create the repository, first you have to create some folders, our repository will be in **/var/www/apt** directory, so let’s create some folders.

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

You have now to export the key you created to the repository folder, run.

    # gpg --armor --export username yourmail@mail.com >> /var/www/apt/key/deb.gpg.key

Note: Replace username with the username you entered in above step, and yourmail@mail.com with your email.

We need to create a file called “**distributions**” inside **/var/www/apt/conf**.

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

Add these following lines to the distributions file and save the file.

    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

Next, We’ll have to create the repository tree, to do this, run those commands.

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

#### Sample Output ####

    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'

### Step 3: Add Packages to Newly Created Repository ###

Now prepare your **.deb** packages to be added to the repository. Go to the **/var/www/apt** directory, you have to do this each time you want to add packages.

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

**Note**: Replace **trusty** with the codename you entered for the repository in the distributions file, and replace **/home/username/package.deb** with the path to the package, you will be asked for the passphrase to enter.

#### Sample Output ####

    /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'

Your package is added to the repository, to remove it.

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

And of course, you need to modify the command with your package name and the repository codename.

### Step 4: Upload Repository to Sourceforge.net ###

To upload the repository to **Sourceforge.net**, you need to have a running account there of course, and a running project, let’s assume that you want to upload the repository to **http://sourceforge.net/projects/myfoo/testrepository** where myfoo is your project name (UNIX name, not URL, not the Title), and testrepository is the folder where you want to upload the files into, We will do this using [rsync command][1].

    # rsync -avP -e ssh /var/www/apt/ username@frs.sourceforge.net:/home/frs/project/myfoo/testrepository/

**Note**: Replace username with your username on sourceforge.net and myfoo with your project UNIX-name and testrepository with the folder you want to store the files in.

Now thats your repository is uploaded to **http://sourceforge.net/projects/myfoo/testrepository**, to add it to your installed system, first you have to import the repository key, it will be in **/var/www/apt/key/deb.gpg.key**, but that’s a local path and the users for your repository won’t be able to add it to their systems, thats why we’ll be importing the key from sourceforge.net.

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

You can add the repository easily now to your system, open **/etc/apt/sources.list** and add this line.

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

**Note**: Replace myfoo with your project UNIX-Name, trusty with your repository codename, testrepository with the folder you uploaded the files into, and main with repository components you added to the distributions file.
Next, run following to update the repositories list.

    $ sudo apt-get update

**Congratulations**! Your repository is active! You can now install packages easily from it if you want.

--------------------------------------------------------------------------------

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

译者：[译者ID](https://github.com/译者ID) 校对：[校对者ID](https://github.com/校对者ID)

本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译，[Linux中国](http://linux.cn/) 荣誉推出

[1]:http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/