Score:0

What is the official way to extend postinst scripts a la debconf?

ph flag

I have a project name snaplogger that I use to send logs to files, syslog, the console, or a remote computer (what syslogd does but with many more features).

Whenever another project wants to use the snaplogger, it's expected to create a log sub-directory. For example, my communicatord project does that:

PACKAGENAME=communicatord
USERNAME=communicatord
GROUPNAME=communicatord

[...snip...]

LOGDIR=/var/log/${PACKAGENAME}
LOGFILE=${LOGDIR}/${PACKAGENAME}.log
mkdir -p ${LOGDIR}
touch ${LOGFILE}
chown ${USERNAME}:${GROUPNAME} ${LOGFILE}
chmod 640 ${LOGFILE}

What I would like to do is move the last 6 lines to a script that the snaplogger project provides. Then the communicatord would just use a function that the script defined. Maybe something like this:

prepare-snaplogger ${PACKAGENAME} ${USERNAME} ${GROUPNAME} true

The true at the end means we also want a secure log sub-folder.

Since the postinst script is run with root, it can create all of that whereas the service will run as itself (i.e. I have a communicatord user) so it would not be able to create those folders.

My question here is: is there a documented way of providing such extension scripts in Debian and/or Ubuntu?

My idea is that each project should provide such under /usr/share/<project-name>/[debconf/?]. But maybe we can use the /var/share/debconf/... folder?


As a result, I would have one additional line to source that file like the following which would appear near the start of the communicatord.postinst script:

. /usr/share/snaplogger/debconf
muru avatar
us flag
Private scripts for a package's internal usage typically go in some `libexec` folder, which on Debian (and hence Ubuntu) is `/usr/lib/<package>` (e.g., see the tons of binaries in `/usr/lib/git-core/`). Put your private scripts from `snaplogger ` in `/usr/lib/snaplogger`, have the `communicatord` package depend on `snaplogger` and you should be able to use `/usr/lib/snaplogger/<whatever>` in the `communicatord`'s postinst script.
Marco avatar
br flag
Addtionally, use `install` instead of `mkdir`,`chown`,`chmod`.
ph flag
@Marco Note that the `chown`/`chmod` are for the file I `touch`, not the `mkdir`. So `install` is not that useful in this case.
Marco avatar
br flag
Shouldn't syslog be the only one writing files in `/var/log` ? But this is off-topic.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.