Once the recipe defines an installation script, the class for the specific package type will install it while following the packaging rules of the specific format.
For post-installation scripts, when running on the host, D is set to the destination directory, so the comparison test will fail. But D will be empty when running on the target.
Another common way to test whether a script is running on the device is:
if test -n "$D"; then # Running on host else # Running on target fi
It is recommended to perform post-installation scripts on the host if possible, as we need to take into account that some root filesystems will be read-only and hence it would not be possible to perform some operations on the target.