Search code examples
packagedebianpost-install

Add postinst script to hello-traditional Debian package


I'm trying to add to the standard: hello-traditional Debian package

I downloaded it and unpacked it and I added the postinst script into the debian folder. It is a very basic script which just echo a string.

#!/bin/sh
# This `DEBIAN/postinst` script is run post-installation

set -e
echo "Prova..............."

exit 0

I rebuild the package locally using:

dpkg-buildpackage -uc -us

or

debuild -us -uc

but when I test it the postinst script is not called: I don't see the echo string.

Any clue?

EDIT

rules file below (which is the orginal one in the package actually)

#!/usr/bin/make -f
# Sample debian/rules file - for GNU Hello.
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified

package = hello-traditional
docdir = debian/tmp/usr/share/doc/$(package)

BUILD_DATE := $(shell dpkg-parsechangelog -S Date)

CFLAGS := `dpkg-buildflags --get CFLAGS` -Wall
LDFLAGS := `dpkg-buildflags --get LDFLAGS`
CPPFLAGS := `dpkg-buildflags --get CPPFLAGS`

STRIP = true

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

export AM_UPDATE_INFO_DIR = no

# Recommended snippet for Autoconf 2.52 or later
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
  stripcmd = strip
else
  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
  stripcmd = $(DEB_HOST_GNU_TYPE)-strip
endif

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  STRIP = $(stripcmd) --remove-section=.comment --remove-section=.note
endif

build:
    ./configure CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
        LDFLAGS="$(LDFLAGS)" $(confflags) --prefix=/usr
    $(MAKE)
    touch build

clean:
    rm -f build
    [ ! -f Makefile ] || $(MAKE) distclean
    rm -rf *~ debian/tmp debian/*~ debian/files* debian/substvars

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

binary-arch: build
    rm -rf debian/tmp
    install -d debian/tmp/DEBIAN $(docdir)
    $(MAKE) prefix="$$(pwd)/debian/tmp/usr" install
    $(STRIP) debian/tmp/usr/bin/hello
    cp -a NEWS debian/copyright $(docdir)
    cp -a debian/changelog $(docdir)/changelog.Debian
    cp -a ChangeLog $(docdir)/changelog
    cd $(docdir) && gzip -9n changelog changelog.Debian
    gzip -r9n debian/tmp/usr/share/man
    gzip -9n debian/tmp/usr/share/info/*
    dpkg-shlibdeps debian/tmp/usr/bin/hello
    dpkg-gencontrol
    cd debian/tmp && \
        find * -type f ! -regex "DEBIAN/.*" -print0 |\
        LC_ALL=C sort -z | xargs -0r md5sum > DEBIAN/md5sums
    chown -R 0:0 debian/tmp
    chmod -R u+w,go=rX debian/tmp
    find debian/tmp -newermt '$(BUILD_DATE)' -print0 |\
         xargs -0r touch -h --date='$(BUILD_DATE)'
    dpkg --build debian/tmp ..

binary: binary-indep binary-arch

build-arch: build

build-indep: build

.PHONY: binary binary-arch binary-indep build-arch build-indep clean

Solution

  • I finally found out the problem: the postinst wasn't copied to debian/tmp/DEBIAN folder so it was not exported to the package.

    The solution, at the moment, is to modify the rules file adding the copy command

    [...]
    binary-arch: build
        rm -rf debian/tmp
        install -d debian/tmp/DEBIAN $(docdir)
        $(MAKE) prefix="$$(pwd)/debian/tmp/usr" install
        $(STRIP) debian/tmp/usr/bin/hello
        cp -a NEWS debian/copyright $(docdir)
        cp -a debian/changelog $(docdir)/changelog.Debian
        cp -a ChangeLog $(docdir)/changelog
        cd $(docdir) && gzip -9n changelog changelog.Debian
        gzip -r9n debian/tmp/usr/share/man
        gzip -9n debian/tmp/usr/share/info/*
        dpkg-shlibdeps debian/tmp/usr/bin/hello
        dpkg-gencontrol
        cd debian/tmp && \
            find * -type f ! -regex "DEBIAN/.*" -print0 |\
            LC_ALL=C sort -z | xargs -0r md5sum > DEBIAN/md5sums
        cp -a debian/postinst debian/tmp/DEBIAN/               # <---- COPY ADDED
        chown -R 0:0 debian/tmp
        chmod -R u+w,go=rX debian/tmp
        find debian/tmp -newermt '$(BUILD_DATE)' -print0 |\
             xargs -0r touch -h --date='$(BUILD_DATE)'
        dpkg --build debian/tmp ..
    [...]