75

I searched for a simple way to create .deb Packages for things which have no source code to compile (configs, shellscripts, proprietary software). This was quite a problem because most of the package tutorials are assuming you have a source tarball you want to compile. Then I've found this short tutorial (german).

Afterwards, I created a small script to create a simple repository. Like this:

rm /export/my-repository/repository/*
cd /home/tdeutsch/deb-pkg
for i in $(ls | grep my); do dpkg -b ./$i /export/my-repository/repository/$i.deb; done
cd /export/avanon-repository/repository
gpg --armor --export "My Package Signing Key" > PublicKey
apt-ftparchive packages ./ | gzip > Packages.gz
apt-ftparchive packages ./ > Packages
apt-ftparchive release ./ > /tmp/Release.tmp; mv /tmp/Release.tmp Release
gpg --output Release.gpg -ba Release

I added the key to the apt keyring and included the source like this:

deb http://my.default.com/my-repository/ ./

It looks like the repo itself is working well (I ran into some problems, to fix them I needed to add the Packages twice and make the temp-file workaround for the Release file). I also put some downloaded .deb into the repo, it looks like they are also working without problems. But my self created packages didn't... Wenn i do sudo apt-get update, they are causing errors like this:

E: Problem parsing dependency Depends
E: Error occurred while processing my-printerconf (NewVersion2)
E: Problem with MergeList /var/lib/apt/lists/my.default.com_my-repository_._Packages
E: The package lists or status file could not be parsed or opened.

Has anyone an idea what I did wrong?

UPDATE 2012-03-06: Just a a hint for another person who is searching for a easy way to create DEBs: Take a look at FPM.

  • Did you add a DEBIAN/control file to the package, which contains the field Depends: ? – Bilal Akhtar Feb 23 '11 at 12:30
  • 5
    Btw. Now I'm using FPM for my packaging needs: https://github.com/jordansissel/fpm – Thomas Deutsch Oct 27 '11 at 13:10
  • FWIW, I got the same error message on a package that I built because I had specified one of the dependencies incorrectly. I had written "foo >= 2.1" when it should be "foo (>= 2.1)". I spent over an hour looking at the last half of the error before I realized the first half of the error was telling me exactly what was wrong... (PS: FPM rocks. You look at Aptly, too.) – Mark E. Haase Aug 01 '14 at 03:42
  • 2
    I would strongly agree that there are no tutorials or guides for packaging something which does not come from a tar ball with make files etc. It is very difficult to work out how to do this. We need such a guide for people like java developers who want to distribute a war with a few scripts and perhaps liquibase, but are not debian sys admins or debian maintainers. FPM does not help in this case, as it too requires that you already know how create something it can package. – John Little Jan 15 '16 at 09:42
  • 1
    Thanks so much for sharing the information about fpm. It works like charm! – Damian Nadales May 08 '18 at 09:14

1 Answers1

76

The tutorial you have linked uses a low level approach for building a package. Such an approach is not usually recommended and may lead to all sorts of issues when not done carefully.

Creating a .deb for a script is very simple once you understand packaging basics. In a nutshell:

# Configure your paths and filenames
SOURCEBINPATH=~
SOURCEBIN=myscript.sh
DEBFOLDER=~/somescripts
DEBVERSION=0.1

DEBFOLDERNAME=$DEBFOLDER-$DEBVERSION

# Create your scripts source dir
mkdir $DEBFOLDERNAME

# Copy your script to the source dir
cp $SOURCEBINPATH/$SOURCEBIN $DEBFOLDERNAME 
cd $DEBFOLDERNAME

# Create the packaging skeleton (debian/*)
dh_make -s --indep --createorig 

# Remove make calls
grep -v makefile debian/rules > debian/rules.new 
mv debian/rules.new debian/rules 

# debian/install must contain the list of scripts to install 
# as well as the target directory
echo $SOURCEBIN usr/bin > debian/install 

# Remove the example files
rm debian/*.ex

# Build the package.
# You  will get a lot of warnings and ../somescripts_0.1-1_i386.deb
debuild

Adding more scripts requires them to be copied to the directory and added to the debian/install file -- then just re-run debuild. You should also check and update the debian/* files as required .

You should read the man pages for: dh_make, dh_install, and debuild

João Pinto
  • 17,159
  • Looks good. I got an _amd64 deb. Since those scripts are not arch specific, what can i do to get an deb for all architectures? – Thomas Deutsch Feb 23 '11 at 14:24
  • 4
    Edit debian/control, "Architecture: any" must be changed to "Architecture: all". Don't forget to set the question as answered ;) – João Pinto Feb 23 '11 at 14:30
  • thanks :)yes, since the question is answered now, I do mark the answer ;) I just wanted to try it first – Thomas Deutsch Feb 24 '11 at 07:50
  • when I do update my script, do I have to do more than rename the directory to the new versionnumber and update debian/changelog? – Thomas Deutsch Feb 24 '11 at 08:41
  • 3
    Apart renaming the directory and updating debian/changelog you must create the .orig archive corresponding to the new version, this is an archive form the source directory contents (without including debian/) . – João Pinto Feb 24 '11 at 09:51
  • Thanks... with or without the source directory in the path? (I mean: cd source directory before taring?) – Thomas Deutsch Feb 24 '11 at 10:02
  • 1
    With the directory include, what I usually do is something like: cp sourcedir sourcedir.orig && rm -rf sourcedir.orig/debian && tar czvf filename.orig.tar.gz sourcedir.orig – João Pinto Feb 24 '11 at 10:07
  • 1
    Adding the --indep flag to dh_make will make the package "Architecture: all" Also the -b flag doesn't exist in 11.04 and above. – andrewsomething Aug 26 '11 at 12:33
  • 1
    After building the .deb package, you should check for errors and enhancements with lintian somescripts_0.1-1_i386.deb or lintian package-source.changes - see: http://packaging.ubuntu.com/html/packaging-new-software.html#next-steps – rubo77 Jul 14 '14 at 23:50
  • If you want to create a Ubuntu PPA on launchpad for it later, you should use debuild -us -uc -k'YOUR GPG KEY' to sign it for uploading it to Launchpad – rubo77 Jul 14 '14 at 23:55
  • And there is not space in -k'YOUR GPG KEY' – Anwar Oct 14 '15 at 07:20
  • you saved my day – iWizard Nov 13 '15 at 16:10
  • 1
    On Ubuntu 14.04 debuild fails with this message: dpkg-buildpackage: error: fakeroot debian/rules binary gave error exit status 2 – Luís de Sousa Jan 13 '16 at 15:18
  • If the install should also create a user (like tomcat7 for the tomcat package), does this have to be manually done with hand written scripts which are part of the package? How and when would the user creation scripts be run, and how does the installation process switch to this user? – John Little Jan 15 '16 at 09:39
  • 4
    dh_make: error: argument -i/--indep: not allowed with argument -s/--single – Jeff Puckett May 29 '17 at 19:32