9

As part of my custom (in-house) .deb file that will be deployed to Ubuntu 12.04 devices, I need to add several PPA repositories, run apt-get update, and then install packages from those PPAs.

Can this be done within the .preinst or .postinst scripts in my .deb file?

I assume that when my .deb file is installed (sudo dpkg -i testing.deb) that some locks or mechanisms likely exist which would prevent me from calling certain commands such as add-apt-repository, apt-get update, and apt-get install.

Is this a correct assumption?

7

You are correct. Maintainer scripts are not supposed to make any changes to the apt or dpkg states, other than the changes that will be made when installing the package anyway.

Installing a file into /etc/apt/sources.list.d, though, is fine. Most packages that fill a role like "install this package to add the APT repository X to your system" simply do that (as opposed to calling add-apt-repository). It's also common to drop the GPG public key used to sign the repo into /etc/apt/trusted.gpg.d.

If you want to make it simple for the user to perform the additional installation steps for your software, you might just want to ship a script which does the job, and tell the user to run the script manually.

But if you really, really want to call apt-get update or apt-get install, etc automatically, and you don't mind that your package will be wholly unacceptable in Debian or Ubuntu proper, and your users are ok with the package acting that way, then you could perhaps put something in /etc/cron.d which checks for any existing apt or dpkg locks, and if none are held, performs your additional installation steps and arranges for those steps not to be performed again. I don't recommend that approach.

| improve this answer | |

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.