db_input in postinst doesn't work

2019-07-30 01:00发布

问题:

I have a problem with postinst script, I have to ask root password for MySQL to create some user for my application. I know, it's bad practice to use db_input in postinst however I really need it. Why this postinst doesn't work when I install my app form repository but works properly when I install it as .deb package?

postinst:

#!/bin/bash -e

. /usr/share/debconf/confmodule

db_input high my_app/mysql_root_password || true
db_go

error:

dpkg: error processing my-app (--configure):
 subprocess installed post-installation script returned error exit status 30
configured to not write apport reports
                                      Errors were encountered while processing:
 my-app
E: Sub-process /usr/bin/dpkg returned an error code (1)

回答1:

The difference probably has something to do with how the terminal is set up when your postinst is run; probably apt does something differently from what happens when you run dpkg on its own. Maybe apt-wrapped postinst invocations don't even have a TTY allocated; I'm not sure, offhand.

But I don't think that putting db_input in a postinst is even supported, so it may be difficult for you to fix it as is. If you really, really need to ask questions from the postinst script itself, you may be able to debug by setting $DEBCONF_DEBUG to "developer" in the environment where the debhelper commands run.

However, I think a more useful solution will be this: you really should use a debian/config script for db_input, as is recommended. What is stopping you?



回答2:

May be the problem in your postinst will be resolved if you change it to

#!/bin/sh -e
. /usr/share/debconf/confmodule
db_version 2.0
db_beginblock
db_input high my_app/mysql_root_password || true
db_endblock
db_go

Take a look on my old debian/postinst file contains has db_input. It works fine, but I changed it because lintian did not like db_input in postinst and told me to move it to debian/config.