Zypper? remove a package and all its configuration files

I’m working in a new configuration of samba. If I don’t want to have problems with the new configuration (keeping parts of the old) I have to begin with a clean install. I removed the package, but the configuration files are still there. I would like to remove all samba related files, but it seems removing the package and installing it again does not clean all files.
Although I can list directories and files in the package and remove them by hand, I would like to know if there is a way to do it automatically (and with this package or any other).

For instance in debian apt remove removes a package but not the configuration files while apt purge removes the package and all configuration files. What I’m looking for is something equivalent to apt purge with zypper.

Which is unclear to me without any names given.

I do not know much about Samba (except that I tried to not install it on system installation), but in general:

  • Configuration files that belong to a package, but are in the domain of a user (mostly within ~/.local or ~/.conf) are not removed when the package is removed (and they are not created when the package is installed, at the most when the user uses them for the first time).
  • I also think that in he newer style of configuring, where the installation default configs are in /usr/share and the local to the system ones in /etc, those in /etc will not be removed (they are not part of the files installed with the package in the first place.

But of course not all software adheres (already) to the new ideas.

samba creates files in /var/lib, /etc/, /usr/lib …

dc1:~ # rpm --query --list samba
/etc/logrotate.d/samba
/etc/pam.d/samba
/etc/samba/smbpasswd
/etc/samba/smbusers
/etc/slp.reg.d
/etc/slp.reg.d/samba.reg
/usr/bin/smbstatus
/usr/lib/systemd/system/nmb.service
/usr/lib/systemd/system/smb.service
/usr/lib/sysusers.d/samba.conf
/usr/lib64/samba
/usr/lib64/samba/auth
/usr/lib64/samba/auth/unix.so
/usr/lib64/samba/config
/usr/lib64/samba/ldb
/usr/lib64/samba/rpc
/usr/lib64/samba/rpcd_classic
/usr/lib64/samba/rpcd_epmapper
/usr/lib64/samba/rpcd_fsrvp
/usr/lib64/samba/rpcd_lsad
/usr/lib64/samba/rpcd_mdssvc
/usr/lib64/samba/rpcd_spoolss
/usr/lib64/samba/rpcd_winreg
/usr/lib64/samba/samba-bgqd
/usr/lib64/samba/samba-dcerpcd
/usr/lib64/samba/vfs
/usr/lib64/samba/vfs/acl_tdb.so
/usr/lib64/samba/vfs/acl_xattr.so
/usr/lib64/samba/vfs/aio_fork.so
/usr/lib64/samba/vfs/aio_pthread.so
/usr/lib64/samba/vfs/audit.so
/usr/lib64/samba/vfs/btrfs.so
/usr/lib64/samba/vfs/cacheprime.so
/usr/lib64/samba/vfs/cap.so
/usr/lib64/samba/vfs/catia.so
/usr/lib64/samba/vfs/commit.so
/usr/lib64/samba/vfs/crossrename.so
/usr/lib64/samba/vfs/default_quota.so
/usr/lib64/samba/vfs/dirsort.so
/usr/lib64/samba/vfs/expand_msdfs.so
/usr/lib64/samba/vfs/extd_audit.so
/usr/lib64/samba/vfs/fake_perms.so
/usr/lib64/samba/vfs/fileid.so
/usr/lib64/samba/vfs/fruit.so
/usr/lib64/samba/vfs/full_audit.so
/usr/lib64/samba/vfs/glusterfs_fuse.so
/usr/lib64/samba/vfs/gpfs.so
/usr/lib64/samba/vfs/io_uring.so
/usr/lib64/samba/vfs/linux_xfs_sgid.so
/usr/lib64/samba/vfs/media_harmony.so
/usr/lib64/samba/vfs/offline.so
/usr/lib64/samba/vfs/preopen.so
/usr/lib64/samba/vfs/readahead.so
/usr/lib64/samba/vfs/readonly.so
/usr/lib64/samba/vfs/recycle.so
/usr/lib64/samba/vfs/shadow_copy.so
/usr/lib64/samba/vfs/shadow_copy2.so
/usr/lib64/samba/vfs/shell_snap.so
/usr/lib64/samba/vfs/snapper.so
/usr/lib64/samba/vfs/streams_depot.so
/usr/lib64/samba/vfs/streams_xattr.so
/usr/lib64/samba/vfs/syncops.so
/usr/lib64/samba/vfs/time_audit.so
/usr/lib64/samba/vfs/unityed_media.so
/usr/lib64/samba/vfs/virusfilter.so
/usr/lib64/samba/vfs/widelinks.so
/usr/lib64/samba/vfs/worm.so
/usr/lib64/samba/vfs/xattr_tdb.so
/usr/sbin/nmbd
/usr/sbin/rcnmb
/usr/sbin/rcsmb
/usr/sbin/smbd
/usr/share/fillup-templates/sysconfig.samba
/usr/share/man/man1/smbstatus.1.gz
/usr/share/man/man5/smbpasswd.5.gz
/usr/share/man/man8/nmbd.8.gz
/usr/share/man/man8/samba-bgqd.8.gz
/usr/share/man/man8/samba-dcerpcd.8.gz
/usr/share/man/man8/smbd.8.gz
/usr/share/man/man8/vfs_acl_tdb.8.gz
/usr/share/man/man8/vfs_acl_xattr.8.gz
/usr/share/man/man8/vfs_aio_fork.8.gz
/usr/share/man/man8/vfs_aio_pthread.8.gz
/usr/share/man/man8/vfs_audit.8.gz
/usr/share/man/man8/vfs_btrfs.8.gz
/usr/share/man/man8/vfs_cacheprime.8.gz
/usr/share/man/man8/vfs_cap.8.gz
/usr/share/man/man8/vfs_catia.8.gz
/usr/share/man/man8/vfs_commit.8.gz
/usr/share/man/man8/vfs_crossrename.8.gz
/usr/share/man/man8/vfs_default_quota.8.gz
/usr/share/man/man8/vfs_dirsort.8.gz
/usr/share/man/man8/vfs_expand_msdfs.8.gz
/usr/share/man/man8/vfs_extd_audit.8.gz
/usr/share/man/man8/vfs_fake_perms.8.gz
/usr/share/man/man8/vfs_fileid.8.gz
/usr/share/man/man8/vfs_fruit.8.gz
/usr/share/man/man8/vfs_full_audit.8.gz
/usr/share/man/man8/vfs_glusterfs_fuse.8.gz
/usr/share/man/man8/vfs_io_uring.8.gz
/usr/share/man/man8/vfs_linux_xfs_sgid.8.gz
/usr/share/man/man8/vfs_media_harmony.8.gz
/usr/share/man/man8/vfs_offline.8.gz
/usr/share/man/man8/vfs_preopen.8.gz
/usr/share/man/man8/vfs_readahead.8.gz
/usr/share/man/man8/vfs_readonly.8.gz
/usr/share/man/man8/vfs_recycle.8.gz
/usr/share/man/man8/vfs_shadow_copy.8.gz
/usr/share/man/man8/vfs_shadow_copy2.8.gz
/usr/share/man/man8/vfs_shell_snap.8.gz
/usr/share/man/man8/vfs_snapper.8.gz
/usr/share/man/man8/vfs_streams_depot.8.gz
/usr/share/man/man8/vfs_streams_xattr.8.gz
/usr/share/man/man8/vfs_syncops.8.gz
/usr/share/man/man8/vfs_time_audit.8.gz
/usr/share/man/man8/vfs_unityed_media.8.gz
/usr/share/man/man8/vfs_virusfilter.8.gz
/usr/share/man/man8/vfs_widelinks.8.gz
/usr/share/man/man8/vfs_worm.8.gz
/usr/share/man/man8/vfs_xattr_tdb.8.gz
/usr/share/omc/svcinfo.d/nmb.xml
/usr/share/omc/svcinfo.d/smb.xml
/usr/share/samba
/usr/share/samba/update-apparmor-samba-profile
/var/lib/samba/drivers
/var/lib/samba/drivers/IA64
/var/lib/samba/drivers/W32ALPHA
/var/lib/samba/drivers/W32MIPS
/var/lib/samba/drivers/W32PPC
/var/lib/samba/drivers/W32X86
/var/lib/samba/drivers/WIN40
/var/lib/samba/drivers/x64
/var/lib/samba/lock/msg.lock
/var/lib/samba/netlogon
/var/lib/samba/profiles
dc1:~ # 

That in installation. Once running it creates new files and directories under this dirs… OK, i could use this list to rm all files and dirs, but I would like to know if it can be done automatically.

I think this is what your looking for : zypper rm --clean-deps or short zypper rm -u

No! —clean-deps is something different. See man zypper.

No, that delete packages related to samba (in this case) but not the configuration files of samba

Your right, I"m sorry, did some googling and maybe try this, use the -f to force a reinstall that wont delete the old files but will over write them according to Google. Not exactly what your looking for but now I’m interested as well…

This will also not work. Force only reinstalls the files included in the package, but not the configuration files which are created after first start of the app.

I immediately will admit that I do not know anything about that tool (except that it is for software management in another Linux distribution), but I doubt it will be able to remove files (configuration ones or not) that are created by that software (or system managers, or users) when it is used beyond the files that are installed with the package (except maybe files created inside directories that were installed with the package by simply removing the directory)

Yes, thats it. It removes the package and all the system wide configuration, meaning all the configuration files and all the directories created by it, so if you purge a package and install it again you can fresh start configuration. It does not remove home user configuration.

But for what I’m looking for it seems there is no option similar with zypper. I think with a simple package, if you reinstall with --force and there is only one configuration file (typical /etc/program.conf the old file is keep as a backup and a new file from the package is installed, am I correct? but if it is a complex package like samba is, with configuration files in several directories and log files and databases created in different directories under its installation directories, there is no way but
-Remove the package
-Manually delete files and directories
-Install the package again.

I will not simply believe this. How can a package (de)installer know what files are created (configuration or not) during the life of the package? It only knows about files that are listed in the RPM.

It can’t know what the config files are, but it can know were they are located (except for home user configuration). As for samba, samba itselt says where they are:

dc1:~ # smbd -b 

Paths:
   SBINDIR: /usr/sbin
   BINDIR: /usr/bin
   CONFIGFILE: /etc/samba/smb.conf
   LOGFILEBASE: /var/log/samba
   LMHOSTSFILE: /etc/samba/lmhosts
   LIBDIR: /usr/lib64
   DATADIR: /usr/share
   SAMBA_DATADIR: /usr/share/samba
   MODULESDIR: /usr/lib64/samba
   SHLIBEXT: so
   LOCKDIR: /var/lib/samba/lock
   STATEDIR: /var/lib/samba
   CACHEDIR: /var/lib/samba
   PIDDIR: /run/samba
   SMB_PASSWD_FILE: /var/lib/samba/private/smbpasswd
   PRIVATE_DIR: /var/lib/samba/private
   BINDDNS_DIR: /var/lib/samba/bind-dns

System Headers:
..........

So, as I’m doing by hand, the package manager can remove all this directories

  • /etc/samba
  • /var/log/samba
  • /usr/share/samba
  • /var/lib/samba
  • /run/samba
  • /usr/lib64/samba

No. You are talking about the specific case of Samba. I am talking in general (and that is what you did in post #1 above). A software management tool will not know if a package includes a specific command (with specific options) to provide such information. Try this for the package MozillaFirefox .

No, but it knows what files an directories are created during the installation of the package, and use this information to remove them all if asked to do it (apt purge vs apt remove in debian).

This is different from what you are talking about all the time. You were talking about files created when used.

The config files created when used are stored in the configuration directories.
zypper rm does not remove them.
zypper in --force does not replace them.

apt remove does not remove them
apt purge does remove them.

I was looking for a similar option in zypper that the apt purge option. I see it is not there. It would be desirable it were.

Then this must have much additional information about what the software installed with a package might be able to create as configuration files. I doubt there is a feature in the RPM definition to facilitate that.

I also think that it requires a lot of manpower for the packager to gather and maintain that information from each and every package to be build.

Hmm… SailfishOS also uses or used zypper. There some users wrote bash scripts for that purpose. Maybe you (or somebody who knows bash scripting) can have a look at it to see if it might work in opensuse for you:

From the scripts shown there, you can detect that there is information to be get from the RPM

rpm -q --configfiles samba

But I am not sure if those are files created by RPM installation and marked as configuration files in the package or if they include extra configuration files created later (they could be there, they must not be there, but who knows?)

BTW, I would be very careful with the script itself. It also seems to check for certain files withing the home directory of one user (nemo) only, thus not for all users. And I personally would never meddle withing the home directories of any of my users.

Another BTW.
I have not seen any prove of what zypper rm removes. E.g. if it removes those files marked as “configuration files” in the RPM or not.

@fperal A lot of that is covered by the actual rpm install (eg %config (noreplace) or just %config), if the packager has configured it that way. Note that releases other than Leap are/have been transitioning to the /usr merge so anything (as it should) in /etc will not be touched as that’s for local admin to use and remember what they did…

2 Likes