0

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
LPs
  • 16,045
  • 8
  • 30
  • 61
  • Do the rules in `debian/rules` actually pick up your `postinst` script? It could also be a problem with how you install it. Depending on how exactly you run `dpkg`, it might not expose the standard output of the script to you. – tripleee May 15 '23 at 07:20
  • @tripleee what I need to check in the rules file? I guessed all is ready in the hello-traditional package to process postinst script. I just use 'sudo dpkg -i ../hello-traditional_2.10-5_amd64.deb' to test my package – LPs May 15 '23 at 07:25
  • As a quick first check, does the generated `.deb` file contain your script? – tripleee May 15 '23 at 07:27
  • @tripleee actually not..... it is in the tar.xz but not in the .deb file.. – LPs May 15 '23 at 07:34
  • Do you know where to look? There is a `control` member inside the top-level archive. Unfortunately, these comment boxes are too small to describe in detail how to learn to read `debian/rules` – tripleee May 15 '23 at 07:42
  • @tripleee I checked the DEBIAN folder where I can find `control` file. Have you any link to understand how rules works? I can find a package online to check how it works however. I post my rules file here – LPs May 15 '23 at 07:50
  • Not `DEBIAN/control`; the actual `.deb` file is an `ar` archive with two members, one of which is called `control.tar.gz` – tripleee May 15 '23 at 07:52
  • So if you add `cp postinst debian/tmp/DEBIAN/` to the `binary-indep` target, does it work? – tripleee May 15 '23 at 07:56
  • @tripleee already tried coping postinst in the tmp/DEBIAN folder without success... – LPs May 15 '23 at 08:09
  • @tripleee manually solved ;) as you can see in my answer. Thx – LPs May 15 '23 at 10:17
  • 1
    Uh, that seems to be exactly what I suggested two comments back, which you were apparently saying wasn't working. – tripleee May 15 '23 at 10:19
  • @tripleee maybe :) btw I checked the `devian/tmp/DEBIAN` dir but it was cancel each time I recompile. – LPs May 15 '23 at 11:38

1 Answers1

0

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 ..
[...]
LPs
  • 16,045
  • 8
  • 30
  • 61