Is it possible to force some preinst script to run before another?

What I would like to do, is create a package in my private repository, which when installed would FIRST ask some questions, and only then other packages (on which it depends) would be unpacked.

For example, let's say I want to create my-mysql package, which would depend on mysql-server-5.5 from standard repository. I would like when user types apt-get install my-mysql for my-mysql.preinst to run before mysql-server-5.5.preinst (so it can do debconf-set-selections to autogenerate root password and to stop mysql-server package from asking for it interactively).

I could do it without putting any depends in my-mysql package, and manually running two commands:

apt-get install my-mysql
apt-get install mysql-server-5.5

but I need it to work with only one command (apt-get install my-mysql). I've tried playing with Pre-depends on third package which would do config, and Depends on mysql-server-5.5, but it seems mysql-server-5.5.preinst always run first. Is there a way to change that and force my package preinst to run before it?

As alternative way, I also cannot run apt-get install mysql-server-5.5 from postinst because of dpkg locking issues, and would like to do it in much cleaner way than locking kludges like this one.

UPDATE: as mentioned in the comments, it seems that mysql-server package also has .config scripts (with associated .templates) which execute even before .preinst scripts, so I need to order them too.

  • I checked mysql-server-5.5, and it asks for the password in postinst, not preinst. I'd suggest you check whether your preinst is correctly setting the password debconf selection. – muru Feb 17 '16 at 1:35
  • @muru I'm pretty sure. I've set DEBIAN_SCRIPT_DEBUG and apt-get install my-mysql says as a first thing Preconfiguring packages ... + DEBIAN_SCRIPT_TRACE=1 ${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 } + echo '#42#DEBUG# RUNNING /tmp/mysql-server-5.5.config.WdEe3A configure ' '1>&2'. Only later does my-mysql.preinst does its output. – Matija Nalis Feb 17 '16 at 3:35
  • Pretty sure of what? That your preinst is setting the password correctly? The output you show doesn't indicate anything to that effect. – muru Feb 17 '16 at 3:45
  • @muru shortened Output shows that the first thing apt-get runs is mysql-server-5.5.config. Only after that is completed, does it run my-mysql.preinst script (first line of which outputs some text, so I know exactly when it is run). Since my-mysql.preinst is run only AFTER mysql-server already asked the password question, it does not matter what my-mysql.preinst does or does not do correctly, as it is already too late. – Matija Nalis Feb 17 '16 at 3:59
  • That's because that prompt is from a config script, not a preinst script. You might try running your own config script, but the timing of config isn't guaranteed, so there's no telling if it will work. – muru Feb 17 '16 at 4:34

I've found a way to do it.

So, in order for single apt-get install my-mysql to work as described in question, I had to do several things:

  • make my-mysql package so it pre-depends on my-mysql-config and depends on mysql-server
  • create additional package my-mysql-config, which pre-depends on debconf and contains my-mysql-config.templates and my-mysql-config.config script (which among other things sets password so mysql-server-5.5 won't ask for it) containing code like:

    . /usr/share/debconf/confmodule
    db_set  mysql-server/root_password "$PW"
    db_fset mysql-server/root_password seen true
    db_set  mysql-server/root_password_again "$PW"
    db_fset mysql-server/root_password_again seen true
  • also my-mysql-config.preinst contains code that does db_get and creates config files before mysql-server gets started

  • you can use my-mysql package .postinst script to run stuff you want after mysql-server is installed and running.

The Debconf Programmer's Tutorial was great help there, as was using export DEBCONF_DEBUG=developer and set -x in scripts for debugging.

Another two time-consuming issues for debug was making sure that config/preinst/postinst scripts do not output ANYTHING to STDOUT (as it breaks debconf in strange and interesting ways) and that you need db_stop if you do stuff like invoke-rc.d mysql restart or similar (or your apt-get will hang hard, without even responding to Ctrl + C)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.