3

I have created a bash script which will store some data into a mysql database. Then I have created deb file with that script and made it available for installation by creating local apt repository.

Now, I can install that package in any system(apt-get install packgename), but the problem is, I have to manually create the mysql database for that script after each installation on each system.

Is there any way so that I can run a script for creating mysql database(as it is a one time requirement for a system) during the installation itself. I have heard something like post and pre scripts but not getting any idea on googling. Could you guys give some good tutorials for that ?

2

1 Answer 1

4

Lets assume you have your .deb-file local (If not you can download it via apt-get download package).

Unpack your deb file:

ar x package.deb

Inside the current folder there are now a few files. data.tar.gz is the file with the package content. But we're interessted in the file control.tar.gz, where the post- and pre-scripts are. So, unpack the control file in another folder:

tar xfs control.tar.gz

Now, what you search is the script called postinst, that is executed after the installation of the package. If that script don't exist, just create it, with rwxr-xr-x permissions (755). Inside that script place your db create command, and let the script end with a exit 0 for a successful installation or exit 1 for a failure.

When you did all your belongings, tar the files back to the control file. Use that command in the folder to create the control.tar.gz file.

tar -czf control.tar.gz *

Now, recreate the deb-package with those new files, with this command:

ar r package.deb debian-binary control.tar.gz data.tar.gz

That's it!

3
  • This worked perfect. Oct 27, 2014 at 3:22
  • So, could you tell whether we have an option for making this possible before making deb file ? Since, as per your answer, we have already have a deb file. What I am asking is, whether is there a way we can implement this before making this deb file. Oct 27, 2014 at 3:39
  • @UvaisIbrahim, it should be placed in the debian/ folder.
    – user.dz
    Mar 29, 2015 at 22:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .