Difference between revisions of "DEB package notes - dpkg, apt, aptitude, and friends"

From Noah.org
Jump to navigationJump to search
m
Line 33: Line 33:
 
== download a specific DEB file from a repository ==
 
== download a specific DEB file from a repository ==
  
This will force a download of the given PACKAGE_NAME. The file will be stored in '''/var/cache/apt/archives''' and the exact name might be different than the package name. It will at least have a version number appended to it.
+
This will download the given PACKAGE_NAME. The file will be stored in '''/var/cache/apt/archives'''. Note that the exact name will be different than the package name. It will at least have a version number appended to it. This action may also download dependency DEB packages.
 
<pre>
 
<pre>
 
apt-get --download-only --force-yes -yy install --reinstall [PACKAGE_NAME]
 
apt-get --download-only --force-yes -yy install --reinstall [PACKAGE_NAME]

Revision as of 23:16, 20 April 2014


Notes on APT, apt-get, aptittude, dpkg, and friends

open and extract files from a DEB package

This will create the destination directory that you give as the last argument. The filesystem contents of the deb package will be created. Note that this does not extract the control scripts and all the logic actually responsible for setting up the package. See the next example for that.

dpkg-deb --extract example-package-name.deb /tmp/example-package-name

Extract only the control files.

dpkg-deb --control example-package-name.deb /tmp/example-package-name

Extract both the filesystem tree and the control files.

dpkg-deb --raw-extract example-package-name.deb /tmp/example-package-name

download source package and extract the package source directory tree

This will download a source package and unpack its source tree.

apt-get source python-pexpect

This will download a source package but leave it unpacked.

apt-get --download-only source python-pexpect

download a specific DEB file from a repository

This will download the given PACKAGE_NAME. The file will be stored in /var/cache/apt/archives. Note that the exact name will be different than the package name. It will at least have a version number appended to it. This action may also download dependency DEB packages.

apt-get --download-only --force-yes -yy install --reinstall [PACKAGE_NAME]

This script will download into the current directory:

#!/bin/sh
# deb-download

PACKAGE_NAME=$1
DESTINATION_DIR=$(readlink -f .)
PARTIAL_DIR=${DESTINATION_DIR}/partial
[ -d ./partial/ ] && PARTIAL_EXISTS=1

if [ -z "${PARTIAL_EXISTS}" ]; then
    mkdir ${DESTINATION_DIR}/partial
fi

apt-get -d --force-yes -y install --reinstall -o Dir::Cache::archives=${DESTINATION_DIR} ${PACKAGE_NAME}

if [ -z "${PARTIAL_EXISTS}" ]; then
    rmdir ${DESTINATION_DIR}/partial
fi

You can also see the URL of where the package would be downloaded from:

--print-uris

Caching apt requests vs. maintaining a local mirror

Maintaining a local mirror takes more effort, storage, bandwidth, and maintenance. The main advantage of running a local mirror is that it isolates you from upstream updates to a repository. This is particularly important when working with Debian Sid. You can update the mirror on a staging server, point some test hosts at the stage repository, do a full update and upgrade on the test hosts, test and confirm that the hosts work as required; finally, push stage repository to the primary local mirror. A secondary advantage of a local mirror is much faster upgrade and updates of hosts.

Setting up a proxy cache is easy and quick. Hosts do need to be reconfigured to use the proxy, but this a one time setup. The main advantage of running a proxy cache is that subsequent upgrades and updates by other hosts using the cache will be much faster. The downside is that a proxy cache does not provide isolation from upstream changes.

This script will install the apt-cacher-ng package and then configure each host in the HOSTS list to use the MIRROR_HOST as a proxy.

#!/bin/sh
export MIRROR_HOST=10.188.121.121
export HOSTS="solute-1 solute-2 solute-3 solute-4 solute-5"
apt-get install -y apt-cacher-ng
# lynx http://localhost:3142/
for HOST in ${HOSTS}; do 
        ssh root@${HOST} 'echo "Acquire::http{Proxy \"http://'${MIRROR_HOST}':3142\";};" > /etc/apt/apt.conf.d/01proxy'
done

Creating DEB packages

debian control directory

debian/
root name of a package control directory.
dh-make
Convert an existing source package to your own package for modification.
aptitude -q -y install dh-make fakeroot pbuilder cdebootstrap

How To

  1. Put all source into a directory named package-version.
  2. Modify source directory as specified in http://www.debian.org/doc/maint-guide/ch-modify.en.html
  3. When you are done cd above this directory: cd ..
  4. create package-version.tar.gz source tarball: `tar czf package-version.tar.gz package-version`.
  5. Create initial debian package environment: `cd package-version/;dh_make -e user@example.com -f ../package-version.tar.gz`. This will create a new "debian" directory.
  6. Edit these files ./debian/control ./debian/copyright ./debian/license
  7. Run `dpkg-buildpackage -rfakeroot`

clean environment and workspace

This depends on `cdebootstrap`. This will take a while as it create an entire Debian chroot directory that looks like a fresh install.

sudo pbuilder create

Errors

Package is in a very bad inconsistent state - you should reinstall it before attempting a removal.

If an install or remove gets interrupted the package database might get left in an inconsistent state. This can cause errors like the one below:

dpkg: error processing xserver-xorg-video-s3virge (--remove):
Package is in a very bad inconsistent state - you should
reinstall it before attempting a removal.


The following may resolve the issue. This forces dpkg to remove the package despite the errors. This may break stuff!

dpkg --force-remove-reinstreq --remove xserver-xorg-video-s3virge