Friday, 17 June 2011

Ubuntu packages and repositories

Creating Ubuntu (debian) packages always seems a bit fiddly....At the moment I can do it, so thought I'd better write down quickly how I did it.

Packages

  • Create a directory and put the files you want to install into a directory tree under it (e.g. if you create a directory called [pkgname], files that you want in /usr/local/bin go in [pkgname]/usr/local/bin.
  • Create a directory called [pkgname]/DEBIAN and put a file in it called 'control'.  This can be as simple as:
Package: grahamstestdeb
Version: 001
Architecture: i386
Depends:
Maintainer: Graham Jones (grahamjones139@gmail.com)
Description: Test Debian Package

  • Create a file called 'postinst' in DEBIAN.  This will be executed when the package is installed. This can be
  • #!/bin/sh
  • echo "postinst works!!!!"
  • Create the .deb package by doing
dpkg-deb --build [pkgname]
  •  Copy your new [pkgname].deb file into a new folder called repository.
  • Run 'sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz' in the repostitory directory.
  • Upload the repository directory to your web server:
ncftpput -v -R -u maps3.org.uk -p ftp.maps3.org.uk public_html/apt/ *

  • Add the following to /etc/apt/sources.lst 
deb http://apt.maps3.org.uk / 

  • Run sudo apt-get update
  • Run sudo apt-cache search [pkgname] - should find your package.
  • Run sudo apt-get install [pkgname] - should run your postinst script.
For better instructions see: http://odzangba.wordpress.com/2006/10/13/how-to-build-local-apt-repositories/#comment-7304.