Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing environment variable inside the postinst script of the debian package

I have made a debian package for automating the oozie installation. The postinst script, which is basically a shell script, runs after the package is installed. I want to access the environment variable inside this script. Where should I set the environment variables?

like image 572
Narayan Periwal Avatar asked Dec 16 '15 00:12

Narayan Periwal


1 Answers

Depending on what you are actually trying to accomplish, the proper way to pass in information to the package script is with a Debconf variable.

Briefly, you add a debian/templates file something like this:

Template: oozie/secret
Type: string
Default: xyzzy
Description: Secret word for teleportation?
 Configure the secret word which allows the player to teleport.

and change your postinst script to something like

#!/bin/sh -e

# Source debconf library.
. /usr/share/debconf/confmodule

db_input medium oozie/secret || true
db_go

# Check their answer.
db_get oozie/secret
instead_of_env=$RET
: do something with the variable

You can preseed the Debconf database with a value for oozie/secret before running the packaging script; then it will not prompt for the value. Simply do something like

debconf-set-selections <<<'oozie oozie/secret string plugh'

to preconfigure it with the value plugh.

See also http://www.fifi.org/doc/debconf-doc/tutorial.html

There is no way to guarantee that the installer runs in a particular environment or that dpkg is invoked by a particular user, or from an environment which can be at all manipulatel by the user. Correct packaging requires robustness and predictability in these scenarios; also think about usability.

like image 183
tripleee Avatar answered Sep 23 '22 13:09

tripleee