How to Preview Pre/Post-Install Scripts in .deb Packages and Control Service Restarts During Upgrades


2 views

When dealing with .deb packages, you can examine the control scripts using dpkg with the following command:

dpkg --info /path/to/package.deb

For more detailed inspection of maintainer scripts:

dpkg-deb -c /path/to/package.deb | grep -E 'preinst|postinst|prerm|postrm'
ar p /path/to/package.deb control.tar.gz | tar -xzO

To preview what changes a package will make without actually installing it:

apt install -s package-name
# Or for local .deb files:
dpkg --dry-run -i package.deb

There are several approaches to prevent automatic service restarts:

# Method 1: Using policy-rc.d
echo "exit 101" > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
# Remember to remove or modify this after installation

# Method 2: Using debconf
echo "package package-name postrm abort-upgrade" | dpkg --set-selections

To check what services might be affected by package triggers:

# List all triggers
dpkg --triggers --list

# Check specific package triggers
apt-cache show package-name | grep -i trigger

For complete control, you can extract and modify the package scripts:

# Extract package contents
dpkg -x package.deb extract-dir
# Extract control scripts
dpkg-deb -e package.deb extract-dir/DEBIAN

# Modify scripts as needed, then repackage
dpkg-deb -b extract-dir modified-package.deb

Remember that modifying packages this way might affect their functionality and should only be done when absolutely necessary.


When managing Debian-based systems, you can examine package actions before installation using these commands:

# View package control scripts
dpkg-deb -c package.deb | grep -E 'preinst|postinst|prerm|postrm'

# Extract control scripts to inspect
dpkg-deb -e package.deb /tmp/extract
cat /tmp/extract/preinst
cat /tmp/extract/postinst

To preview what changes a package will make:

# Dry-run with apt
apt install -s package-name

# More detailed simulation with dpkg
dpkg --dry-run -i package.deb

To install packages without running maintenance scripts:

# Skip all maintainer scripts
dpkg --force-all --skip-same-version --no-triggers -i package.deb

# Alternative method using environment variable
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \\
  apt-get -o Dpkg::Options::="--force-confdef" \\
  -o Dpkg::Options::="--force-confold" \\
  install package-name

For packages that restart services, you can temporarily prevent this:

# Create policy-rc.d to block service restarts
echo 'exit 101' > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d

# After installation completes, remove the block
rm /usr/sbin/policy-rc.d

To check if a package has any triggers that might affect services:

# List all triggers in a package
dpkg-trigger --list package-name

# Check pending triggers
dpkg --triggers-only --pending

Here's how to inspect and control an apache2 package installation:

# First examine the post-installation script
dpkg-deb -e apache2_2.4.41-4ubuntu3.13_amd64.deb /tmp/apache
less /tmp/apache/postinst

# Then install while preventing service restart
echo 'exit 101' > /usr/sbin/policy-rc.d
apt-get install -y apache2