Difference between revisions of "Create or Update a Debian package"

From Organic Design wiki
(Change source-code blocks to standard format)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{procedure
 
{{procedure
 
|description = This procedure defines the steps required to package up a collection of official packages and other installation scripts into a [[w:Debian package|Debian package]] which can then be installed as part of the [[Debian Post Install]] using ''apt-get''. See [[Packages]] for more information on our overall package repository plans.
 
|description = This procedure defines the steps required to package up a collection of official packages and other installation scripts into a [[w:Debian package|Debian package]] which can then be installed as part of the [[Debian Post Install]] using ''apt-get''. See [[Packages]] for more information on our overall package repository plans.
|role = dev
+
|role = sysop
 
|status = in use
 
|status = in use
 
}}__NOTOC__
 
}}__NOTOC__
Line 8: Line 8:
 
=== Working directory structure ===
 
=== Working directory structure ===
 
Here's an example directory structure for a package which replaces the apache default config file and sets up default php and html files in ''/var/www''.
 
Here's an example directory structure for a package which replaces the apache default config file and sets up default php and html files in ''/var/www''.
{{#tree:root=example-package|
+
{{code|{{#tree:root=example-package|
 
*DEBIAN
 
*DEBIAN
 
**control
 
**control
Line 23: Line 23:
 
***index.html
 
***index.html
 
***index.php5
 
***index.php5
}}
+
}}}}
 
The ''control'' file in the DEBIAN sub-directory is where all the main configuration is done. The other three files in that sub-directory are scripts which execute on installation and removal of the package.
 
The ''control'' file in the DEBIAN sub-directory is where all the main configuration is done. The other three files in that sub-directory are scripts which execute on installation and removal of the package.
  
Line 30: Line 30:
 
Our packages at Organic Design are in ''/var/www/domains/packages'' and the source directory structures for them are in the ''sources'' subdirectory.
 
Our packages at Organic Design are in ''/var/www/domains/packages'' and the source directory structures for them are in the ''sources'' subdirectory.
  
=== Building into a package ===
+
=== Building or updating a package ===
 +
Next the source needs to be built into a .deb file, if this is being done for an existing package which is being updated, then don't forget to ensure that the version number in the control file is larger.
 +
 
 
To turn the directory structure into a proper ''.deb'' package file, use:
 
To turn the directory structure into a proper ''.deb'' package file, use:
dpkg -b /var/www/domains/packages/source/<package-name>
+
<source>
The package will be created with the same name but with the ''.deb'' extension in the same directory as the package directory. It should be moved into the correct subdirectory of such as ''/var/www/domains/packages/main''.
+
cd /var/www/domains/packages
 
+
dpkg -b source/<package-name> main/<package-name>.deb
e.g.
+
</source>
dpkg -b /var/www/domains/packages/source/organicdesign-workstation
 
mv /var/www/domains/packages/source/organicdesign-workstation.deb /var/www/domains/packages/main/organicdesign-workstation.deb
 
  
 
=== Adding to a package repository ===
 
=== Adding to a package repository ===
 
All the ''.deb'' package files must be added to the ''main'' repository on the server which is in ''/var/www/packages/main''. Ensure that this repository is included in your ''/etc/apt/sources.list'':
 
All the ''.deb'' package files must be added to the ''main'' repository on the server which is in ''/var/www/packages/main''. Ensure that this repository is included in your ''/etc/apt/sources.list'':
deb http://packages.organicdesign.co.nz main/
+
<source>
 +
echo "deb http://packages.organicdesign.co.nz main/" >> /etc/apt/sources.list
 +
</source>
 +
 
  
 
Whenever any of the packages in the repository change, the ''Packages.gz'' index file must be updated which can be done as follows.
 
Whenever any of the packages in the repository change, the ''Packages.gz'' index file must be updated which can be done as follows.
cd /var/www/domains/packages
+
<source>
dpkg-scanpackages main /dev/null | gzip > main/Packages.gz
+
cd /var/www/domains/packages
 +
dpkg-scanpackages main /dev/null | gzip > main/Packages.gz
 +
</source>
 +
 
 +
== Creating a GPG Key ==
 +
<source>
 +
gpg --gen-key
 +
</source>
 +
*Don't choose a password for signing, or automated package processing will not work.
 +
 
 +
Export the public key for import into apt:
 +
<source>
 +
gpg --list-public-keys
 +
</source>
 +
 
 +
 
 +
Using the line that states "pub" look for the hex numbers after the / (eg. pub 1024D/5F6DEDCD 2008-07-10)
 +
 
 +
We'll use my temporary key hex for this example, be sure to change it.
 +
<source>
 +
gpg --export 0x5F6DEDCD >repo.key
 +
</source>
 +
 
 +
 
 +
Whenever you connect a new system to this apt repository you will need to place a copy of the key into your working directory and issue the following command:
 +
<source>
 +
apt-key add repo.key
 +
</source>
 +
 
 +
== Modifying dependencies in a .deb file ==
 +
# dpkg-deb -x foo.deb tmpdir
 +
# dpkg-deb --control foo.deb tmpdir/DEBIAN
 +
# nano tmpdir/DEBIAN/control
 +
# dpkg -b tmpdir hacked.deb
  
 
== See also ==
 
== See also ==
 
*[[Packages]] ''- we plan to manage our IT infrastructure using APT''
 
*[[Packages]] ''- we plan to manage our IT infrastructure using APT''
 +
*[[organicdesign-server]]
 +
*[[organicdesign-workstation]]
 
*[http://www.linuxdevices.com/articles/AT8047723203.html LinuxDevices instructions]
 
*[http://www.linuxdevices.com/articles/AT8047723203.html LinuxDevices instructions]
 
*[http://tldp.org/HOWTO/html_single/Debian-Binary-Package-Building-HOWTO TLDP HOWTO]
 
*[http://tldp.org/HOWTO/html_single/Debian-Binary-Package-Building-HOWTO TLDP HOWTO]
 
*[[Google:creating Debian packages]]
 
*[[Google:creating Debian packages]]
 
*[http://mirror.atrpms.net/ccrma/man/man5/sources.list.5.html Format of sources.list file]
 
*[http://mirror.atrpms.net/ccrma/man/man5/sources.list.5.html Format of sources.list file]

Latest revision as of 18:11, 22 May 2015

Procedure.svg Create or Update a Debian package
Organic Design procedure

General procedure

Working directory structure

Here's an example directory structure for a package which replaces the apache default config file and sets up default php and html files in /var/www.

The control file in the DEBIAN sub-directory is where all the main configuration is done. The other three files in that sub-directory are scripts which execute on installation and removal of the package.

The rest of the directory structure outside the DEBIAN sub-directory define the directory structure which will be merged with the root of the filesystem when the package is installed.

Our packages at Organic Design are in /var/www/domains/packages and the source directory structures for them are in the sources subdirectory.

Building or updating a package

Next the source needs to be built into a .deb file, if this is being done for an existing package which is being updated, then don't forget to ensure that the version number in the control file is larger.

To turn the directory structure into a proper .deb package file, use:

cd /var/www/domains/packages
dpkg -b source/<package-name> main/<package-name>.deb

Adding to a package repository

All the .deb package files must be added to the main repository on the server which is in /var/www/packages/main. Ensure that this repository is included in your /etc/apt/sources.list:

echo "deb http://packages.organicdesign.co.nz main/" >> /etc/apt/sources.list


Whenever any of the packages in the repository change, the Packages.gz index file must be updated which can be done as follows.

cd /var/www/domains/packages
dpkg-scanpackages main /dev/null | gzip > main/Packages.gz

Creating a GPG Key

gpg --gen-key
  • Don't choose a password for signing, or automated package processing will not work.

Export the public key for import into apt:

gpg --list-public-keys


Using the line that states "pub" look for the hex numbers after the / (eg. pub 1024D/5F6DEDCD 2008-07-10)

We'll use my temporary key hex for this example, be sure to change it.

gpg --export 0x5F6DEDCD >repo.key


Whenever you connect a new system to this apt repository you will need to place a copy of the key into your working directory and issue the following command:

apt-key add repo.key

Modifying dependencies in a .deb file

  1. dpkg-deb -x foo.deb tmpdir
  2. dpkg-deb --control foo.deb tmpdir/DEBIAN
  3. nano tmpdir/DEBIAN/control
  4. dpkg -b tmpdir hacked.deb

See also