What does installation script do in apt-get install?

14

8

It seems apt-get install will download a Debian package and try to run installation script for:

  • Create proper directory
  • Create proper account
  • Copy Binary files
  • Copy Data files
  • Copy Conf files
  • Copy init.d script
  • Start service
  • etc.

I’m really interested in it and want to figure out what’s going on step-by-step. Is there any way to it see? Like print shell commands in a “dry run” mode?

ShenLei

Posted 2015-02-11T09:14:13.130

Reputation: 333

Answers

25

In short: apt-get install does everything that is needed that your system can successfully execute the new installed software application.

Longer version:

Preliminaries:

From the manpage:

All packages required by the package(s) specified for installation will also be retrieved and installed.

Those packages are stored on a repository in the network (internet). So, apt-get downloads all the needed packages into a temporary directory (/var/cache/apt/archives/). They will be downloaded from a web- or an ftp-server. They are specified in the so called sources.list; a list of repositories for the package manager apt. From then on, they get installed one by one procedurally.

The first ones to be installed are the ones that have no further dependencies; so no other package has to be installed for them to work properly. Through that, other packages (that had dependencies previously) haven't now dependencies anymore. The system keeps doing that process over and over until the specified packages are installed.

Each package undergoes an installation procedure.

Package installation procedure:

In Debian-based Linux distributions, such as Ubuntu or Mint, those packages are in a specified standardized format called: deb --> The Debian binary package format.

Such a package contains the files to be installed on the system. Also they contain a control file. That file contains scripts that the packaging system should execute in a specific situation; the so-called maintainer scripts. Those scripts are split in:

  • preinst: before the installation of the files into the systems file hierarchy
  • postinst: after the installation
  • prerm: before the uninstallation
  • postrm: after the uninstallation

Those scripts are the place where specific users are created or some services that need to be restarted or other preliminaries that are needed for the package to work.

Besides those scripts, the package system has triggers that are intended for specific events. For example, the regeneration of initrds when installing a new kernel version or ldconfig or the man-db. They are activated by one or more packages and run in the end of the whole installation process.

There is an interesting picture, showing the procedure of an installation of a new package:

installation

There are also more control-files, the most important are as follows:

If you are interested, you can unpack a deb package (after downloading) manually and watch what's inside:

# to only download the package (no installation)
apt-get download package
# to unpack the deb file
ar x package.deb

Now you see a file called data.tar.gz containing the files and a file called control.tar.gz containing the four maintainer scripts and the above-mentioned control-files.

chaos

Posted 2015-02-11T09:14:13.130

Reputation: 3 704

Nowadays I believe it'll be better to use dpkg-deb -x package.deb instead of ar x package.deb, since dpkg is the official deb package manager (over which apt-get is used). – Fanatique – 2019-05-28T11:26:42.180