36

I have a large project where we have the following files:

  • A few 3rd party pre-compiled binaries
  • Our own in-house binaries
  • collection of Ruby scripts
  • A sizable Ruby on Rails project

This product will be installed on appliance hardware that my employer has already selected, using Ubuntu Linux (Lucid) as the target OS, with our goal of distributing the archive as a Debian package to ease installation and upgrades. Additionally, we have a number of ERB templates that we need to "fill-in" with appropriate values on a per-customer basis, so the use of the postinst script will be particularly handy for our purposes.

As a side note, the Debian packages will be stored on a server repository that we manage in-house.

At this stage, I have used dh_make to create the Debian directory and related files (e.g., rules, control, etc.), but the rules file that is generated seems like overkill for my purposes.

Based on this description, all I really need the "rules" file to do is simply copy files from a source directory (or within an archive) to the target directories shown below:

/opt/company_product/3rd_party_binaries/bin
/opt/company_product/3rd_party_binaries/etc
/opt/company_product/in_hourse_binaries/bin
/opt/company_product/in_hourse_binaries/etc
/opt/company_product/ruby
/opt/company_product/rails_project
/opt/company_product/etc
/opt/company_product/shared/logs
/opt/company_product/shared/tmp
/opt/company_product/shared/license

...and so on.

I've read the Debian Policy Manual and several How-To's which indicate that you should not alter the rules file to use mkdir to create directories and there is generally a dh_ app (e.g., dh_installdirs, et al) that can suit your needs for nearly any installation purposes. The man pages for these dh_ related apps are cursory at best, and I am an "example" kind of guy.

That said, I'm a little lost on what the best approach is to getting my rules file to install my various pre-compiled binaries and Ruby/Rails text files to the desired locations.

Here's my initial rules file. It's pretty much a standard boilerplate rules file that dh_make creates. My thinking is that I should comment out all sections except for the install and then find the appropriate command(s) to make directories, copy files, etc. within that section.

Any advice or suggestions are greatly appreciated.

#!/usr/bin/make -f

package = testapp

CC = gcc
CFLAGS = -g -Wall

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2
endif

#export DH_VERBOSE=1

clean:
        dh_testdir
        dh_clean
        rm -f build

install: build
        dh_clean
        dh_installdirs
        echo "Place the Install Script here"
        cp $(CURDIR)/testapp-2.0.tar.gz $(CURDIR)/debian/$(package)/opt/testapp-2.0
        echo "Finished copying folders"


build:
        touch build

binary-indep: install
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch: install
        dh_testdir -a
        dh_testroot -a
        dh_installdocs -a 
        dh_installchangelogs -a 
        dh_strip -a
        dh_compress -a
        dh_fixperms -a
        dh_installdeb -a
        dh_shlibdeps -a
        dh_gencontrol -a
        dh_md5sums -a
        dh_builddeb -a

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean checkroot
Matze
  • 5,100
  • 6
  • 46
  • 69
Chip Castle
  • 2,132
  • 3
  • 20
  • 34

2 Answers2

61

Although you've already got your own answer, I'll point out a couple of things.

You seem to be doing this in a very complicated manner. If you simply need to copy files into certain directories, write a debian/mypackagename.install with the following format:

path/to/file/relative/to/source/root path/to/install/relative/to/system/root

(do not prepend / before /usr, or /opt, or whatever your target directory is. Read man dh_install for more information)

Then your debian/rules can be:

#!/usr/bin/make -f

%:
    dh $@

If you have some sort of makefile, etc in your source root, then append this to the above rules file:

override_dh_auto_build:

override_dh_auto_install:

Don't forget put 7 in debian/compat.

Also, you shouldn't install files into /opt/ or /usr/local/, etc. Those are meant for files not installed by Debian packages. Debian recommends installing in /usr/share/yourcompany/. As juzzlin points out below, the Ubuntu Software Center may have different requirements.

More specifically, your mypackage.install file should look like this:

src/bin/* usr/bin
src/etc/* etc/
Community
  • 1
  • 1
Umang
  • 5,196
  • 2
  • 25
  • 24
  • Excellent suggestions. Once I do this, which command should I use to build the deb package? – Chip Castle Jul 12 '10 at 19:09
  • ok, I ran dpkg-buildpackage and got a .deb file, but when I install it on the target server it doesn't run my debian/mypackagename.install file. Also, if I have scripts that go under init.d, where do I put them? – Chip Castle Jul 12 '10 at 20:25
  • Here's my directory structure: build_deploy.rb build_package.rb debian docs extras Rakefile src test.txt. Under src is the following: bin console created_vipre.sql etc filter install.rb opt spf transport. All I want is to have a .deb file that contains everything under src. I then want that exact structure to be copied to /opt/vipre on the target system. I then want everything under src/etc/init.d to be copied to /etc/init.d. I'm not sure why I can't get this. It seems simple, but the docs are confusing me. Please help. Thanks so much. – Chip Castle Jul 12 '10 at 20:45
  • 1
    Essentially what debhelper does is that if it doesn't know how to install (we don't have a buildsystem like a makefile or python's distutils, if we do, we override it as mentioned above) is it reads `debian/mypackage.install` and dh_install then puts the source files into the target temporary directory (with which the .deb is created). So your `debian/mypackage.install` should like the one I'm going to put into the edited answer. You can run `debbuild` to generate the package. It's generally easier to do that. – Umang Jul 13 '10 at 03:21
  • Look at the example I've put in the answer and let me know whether you have any problems with it. If you want to check whether everything look like you want it, you can open your .deb with `gdebi` and then check section on the files that the package will install. Verify that it is like you want. If it isn't, either you or I have got something wrong. If it doesn't like `foobar.install` is being parsed, then you should try adding the override_dh_auto* targets to your rules file that I've put above. – Umang Jul 13 '10 at 03:32
  • I've made your requested changes and I get a deb package. I used dupload to send it to my server on ec2, which worked fine on the first attempt. Subsequent uploads reported this error: "Nothing to upload". I'm using reprepro to manage the debian repo. Any suggestions? – Chip Castle Jul 13 '10 at 18:59
  • For now I'm manually removing the db directory that reprepro creates on the ec2 server, just so I can test the package installation. On the target machine "sudo apt-get install vipre" reported this (I'm only showing the first few lines of output): The following packages have unmet dependencies: vipre: Depends: libmilter1.0.1 but it is not going to be installed Depends: libruby1.8 (>= 1.8.7.174) but it is not going to be installed Depends: libstdc++5 (>= 1:3.3.4-1) but it is not installable.****libstdc++5 error is a surprise because I removed it from debian/control Dependencies. – Chip Castle Jul 13 '10 at 19:09
  • I don't think I can help here. A similar problem I remember having was a `.upload` file in the directory of the `.deb` file. (e.g. `mypackage_1.2.3-1_source.myserver.upload`). `dput` would not upload any version less than or equal to the last upload to that server. See if something similar is happening. – Umang Jul 14 '10 at 05:09
  • About your second problem, this could be because you've got an old .deb in your server that hasn't been overridden by a new one. Check the output of commands like `apt-cache depends vipre` and `apt-cache show vipre` clues on this. – Umang Jul 14 '10 at 05:11
  • 2
    Just a side note about /opt: Ubuntu Software Center, for example, requires/required, the applications install to /opt. – juzzlin Dec 29 '13 at 14:05
  • I keep coming back to this answer because it feels like it must be great. But without a concrete example, I can't put it into practice. As I continue to learn more about deb packaging I come back here and try to re-understand it. But, I have yet to do so. I'd love to see an example project on github. These things are very difficult to understand in paragraph form. – Bruno Bronosky Oct 26 '17 at 15:22
-2

You can install cdbs and change the rules file like this

#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk

binary-install/package_name::
                   mkdir debian/$(cdbs_curpkg)/destination_path 
                   cp path_of_your_files  debian/$(cdbs_curpkg)/destination_path