Skip to contentSkip to conversation

clarify use of "$D" in pkg_postinst routines?

DISCUSSION Robert P. J. Day 2 participants 5 messages Apr 7, 2020

lore
Share & tools
lore
#0 lore raw

first time looking closely at pkg_postinst_* routines, so can
someone clarify the use of "$D" in those routines? at the moment, i'm *guessing* that those routines need to be able to run in two different contexts (but i could be wrong):

1) at image creation time
2) at later package installation time on a running system

i'm aware that bitbake requires the use of curly braces, so always must use "${D}", so in something like this from xorg-font-common.inc, how does OE process this shell function? as in, what context do those routines run in?

  pkg_postinst_${PN} () {
        for fontdir in `find $D/usr/lib/X11/fonts -type d`; do
                mkfontdir $fontdir
                mkfontscale $fontdir
        done
        for fontdir in `find $D/usr/share/fonts/X11 -type d`; do
                mkfontdir $fontdir
                mkfontscale $fontdir
        done
  }

it seems(?) clear that testing $D is the way to tell which of the two contexts one is running in, as in:

  pkg_postinst_${PN}_class-target () {
        if [ "x$D" != "x" ]; then
          rootarg="--root $D"
        else
          rootarg=""
        fi
        ... snip ...

such that if $D is the empty string, then you're in the context of a running system. am i close?

rday

p.s. i notice there are two ways that $D is used to define the context. in some cases, just using it (as in the first example above) is sufficient, while in other cases (as in the second case), the routine needs to actually test the value.

#1 lore raw

These run
- at image creation time in the context of package manager (dnf/apt/opkg) installing packages into the image rootfs directory. The code that executes the package manager specifically exports $D into the environment before launching it.
- at runtime when packages are installed or updated through the same package manager. Then, $D is absent.

The scripts are written into the package files when the packages gets created; they become 'post-install scriptlets' that every package manager supports and executes if they are present.

Alex

Quoted 47 lines · Robert P. J. Day

first time looking closely at pkg_postinst_* routines, so can
someone clarify the use of "$D" in those routines? at the moment, i'm *guessing* that those routines need to be able to run in two different contexts (but i could be wrong):

1) at image creation time
2) at later package installation time on a running system

i'm aware that bitbake requires the use of curly braces, so always must use "${D}", so in something like this from xorg-font-common.inc, how does OE process this shell function? as in, what context do those routines run in?

  pkg_postinst_${PN} () {
        for fontdir in `find $D/usr/lib/X11/fonts -type d`; do
                mkfontdir $fontdir
                mkfontscale $fontdir
        done
        for fontdir in `find $D/usr/share/fonts/X11 -type d`; do
                mkfontdir $fontdir
                mkfontscale $fontdir
        done
  }

it seems(?) clear that testing $D is the way to tell which of the two contexts one is running in, as in:

  pkg_postinst_${PN}_class-target () {
        if [ "x$D" != "x" ]; then
          rootarg="--root $D"
        else
          rootarg=""
        fi
        ... snip ...

such that if $D is the empty string, then you're in the context of a running system. am i close?

rday

p.s. i notice there are two ways that $D is used to define the context. in some cases, just using it (as in the first example above) is sufficient, while in other cases (as in the second case), the routine needs to actually test the value.

#2 lore raw
Quoted 9 lines · Alexander Kanavin

These run

- at image creation time in the context of package manager (dnf/apt/opkg) installing packages into the image rootfs directory. The code that executes the package manager specifically exports $D into the environment before launching it.

- at runtime when packages are installed or updated through the same package manager. Then, $D is absent.

ah, that's very much what i'd guessed. i also just noted sec 4.7.7
in ref manual, one of the QA checks:

"An additional QA check has been added to detect usage of ${D} in FILES values where D values should not be used at all. The same check ensures that $D is used in pkg_preinst/pkg_postinst/pkg_prerm/pkg_postrm functions instead of ${D}."

Quoted 3 lines

The scripts are written into the package files when the packages gets created; they become 'post-install scriptlets' that every package manager supports and executes if they are present.

so far, so good, i'm still going to expand on that section since
it definitely could use some fleshing out.

rday

#3 lore raw
In reply to Alexander Kanavin
Quoted 7 lines · Alexander Kanavin

These run

- at image creation time in the context of package manager (dnf/apt/opkg) installing packages into the image rootfs directory. The code that executes the package manager specifically exports $D into the environment before launching it.

Quoted 6 lines

- at runtime when packages are installed or updated through the same package manager. Then, $D is absent.

The scripts are written into the package files when the packages gets created; they become 'post-install scriptlets' that every package manager supports and executes if they are present.

i assume the same holds for pre-install scriptlets, even though the
docs claim otherwise.

rday

#4 lore raw
In reply to Alexander Kanavin
Quoted 9 lines · Alexander Kanavin

These run

- at image creation time in the context of package manager (dnf/apt/opkg) installing packages into the image rootfs directory. The code that executes the package manager specifically exports $D into the environment before launching it.

- at runtime when packages are installed or updated through the same package manager. Then, $D is absent.

i think i'm going to use
meta-selftest/recipes-test/postinst/postinst_1.0.bb as the basis for writing a more extensive section on this topic, 'cuz writing this up is the only way i'm going to understand this. there are definitely subtleties here that are not documented in the manuals.

rday