I am creating a .deb package that needs a MySQL database. I am building the package using dpkg-deb --build. While installing I want my post install script to execute an SQL script to set up the database like so:

cat setup.sql | mysql -u root -p

I am currently putting setup.sql into the "DEBIAN" folder of my package. What path do I need to specify in my post install script to find this SQL script?

I know I could embed the SQL contents into my post-install script but I want to keep them separate for code maintenance reasons.


You can’t easily (if at all) access files you add to DEBIAN in a package built with dpkg-deb -b — those files end up in the control information area of the binary package, they aren’t installed as such (in fact, I’m not sure non-standard files are even included in the package; standard files end up in /var/lib/dpkg/info).

You should instead install your script in /usr/share/yourpackage (replacing yourpackage with the name of your package). Then your postinst can access it there.

Ideally, you’d use dbconfig-common instead; that supports a wide variety of use-cases and database configurations. It would involve more work up-front but would result in a much more versatile package.

  • I ended up with something similar, creating a folder <install root>/install with the bits and pieces I needed and then deleting them in the postinst script. Is /usr/share/<name/ a more standard location? Should I be tidying up after installation or leaving them there? – AlastairG Nov 17 '17 at 15:22
  • /usr/share/package is yours to do what you want in, and yes, that’s the standard location for such files. You should leave them alone, postinst shouldn’t delete files which are shipped in a package. – Stephen Kitt Nov 17 '17 at 15:27
  • If the "setup.sql" really is not properly part of the installed package, maybe instead of a separate file, you should include the text in postinst. pass it to mysql with echo instead of cat – Joshua Clayton Nov 29 '17 at 16:13

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.