2

How can I view the differences between the current state of a conffile and the clean state when the package was installed?

I am running Ubuntu Server upgrade from 12.04 to 14.04. The installer claims that several configuration files were changed locally:

Configuration file `/etc/bash.bashrc'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** bash.bashrc (Y/I/N/O/D/Z) [default=N] ?

(Source of the example: https://raphaelhertzog.com/2010/09/21/debian-conffile-configuration-file-managed-by-dpkg/)

When I choose D to check differences, my current conffile is compared to the clean state in the new package version.

Sometimes there are lots of lines that were changed between the package versions and are not local modifications for sure. I would like to filter such changes and display the true local modifications. Otherwise an important single-line local modification can be easily overlooked.

For example php.ini has 447 changed lines according to:

diff /usr/share/php5/php.ini-production /etc/php5/apache2/php.ini | grep -E '^[<>]' -c
5
  • 2
    Install etckeeper and keep your config files in version control.
    – muru
    Dec 6, 2016 at 12:43
  • @muru Thank you, etckeeper could help during future upgrades. However, I am primarily asking about the current one while etckeeper has not been previously installed.
    – Melebius
    Dec 7, 2016 at 6:21
  • Without version control, you'd probably have to obtain the original files from packages of the corresponding versions, since all dpkg does is keep track of the md5sums of conffiles.
    – muru
    Dec 7, 2016 at 6:29
  • @muru Yes, that’s exactly what I was thinking about. Is there any way to extract them without actually reinstalling the package?
    – Melebius
    Dec 7, 2016 at 6:31
  • 1
    Depending on what you consider reinstalling, one of my related posts could help: askubuntu.com/a/627018/158442
    – muru
    Dec 7, 2016 at 6:35

2 Answers 2

0

Archive(backup) your config files before modifying them.

A possible system would result in...

/etc
/etc/.archives
/etc/.archives/bash.bashrc.00
/etc/.archives/bash.bashrc.01
/etc/bash.bashrc

/etc/.archives/bash.bashrc.00 would be the original distributed version. You could use dates instead of numbers if you don't mind long names...

/etc/.archives/bash.bashrc.20161206.003200

You could write a script to make this easier too.

1
  • 1
    This is what version control is for - you should use git, mercurial, etc instead of rolling your own.
    – muru
    Dec 7, 2016 at 5:50
0
  1. Press Z to enter shell.

  2. Get the name of the package which provided the file. During a system upgrade, apt and dpkg commands point to the new version already, so you need another source to check your previous version: Open http://packages.ubuntu.com/ and enter the file name in Search the contents of packages. Select the system version (“distribution”) you are upgrading from.

    If you found nothing, return to the conflict resolution interface (exit) and press D to display differences. Check the diff header, it shows the desired file name:

    --- /etc/php5/apache2/php.ini 2014-01-08 00:58:08.000000000 +0100
    +++ /usr/share/php5/php.ini-production 2016-10-03 15:14:37.000000000 +0200
    

    In this case, it is /usr/share/php5/php.ini-production. Search the webpage for this file.

  3. Choose the correct package name, your system’s architecture and get the URL of the package (the link below You can download the requested file from…).

  4. Download the package.

    wget http://security.ubuntu.com/ubuntu/pool/main/p/php5/php5-common_5.3.10-1ubuntu3.25_amd64.deb
    
  5. Extract the file you want to compare.

    dpkg-deb --fsys-tarfile php5-common_5.3.10-1ubuntu3.25_amd64.deb | tar -x ./usr/share/php5/php.ini-production
    
  6. Check the difference.

    diff -u /etc/php5/apache2/php.ini ./usr/share/php5/php.ini-production | less
    

The instructions are based on https://askubuntu.com/a/627018/250300.

You must log in to answer this question.

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