.deb problem with conffiles

I am distributing one of my applications using the .deb package, but have a problem with one of the files.

The distribution file includes a database file that is constantly updated by the application, with a new installation I want the installer to copy a new, empty db file to the users system, but when updating, I want the installer to leave the existing copy in place (overwriting will lose all data users).

Currently, I have included the file in the file "conffiles", so the installer always asks the user whether to overwrite the existing file or not, but this is not what I want - overwriting the file will never be correct and I am worried that the user may choose wrong option during update and their data hoses.

Is there a way to tell the installer that if the db file already exists, just leave it alone and do not ask the user what to do?

+3
source share
1 answer

Yes, use preinst / postinst script. The usual method is the name of the file in the package with a special name ending in dpkg-new, for example /var/lib/myapp/mydb.data.dpkg-new. Then write a 'postinst' script to place your package in the DEBIAN directory to check for the presence of the database and rename or delete the dpkg-new file accordingly, for example:

#!/bin/bash

if [ -f /var/lib/myapp/mydb.data ]; then
    rm /var/lib/myapp/mydb.data.dpkg-new
else
   mv /var/lib/myapp/mydb.data.dpkg-new /var/lib/myapp/mydb.data
fi
+4
source

Source: https://habr.com/ru/post/1723220/


All Articles