Solved FreeBSD-12.3p0 - pkg autoremove

I ran pkg autoremove -n to see if there was any clutter on my desktop. It reported some 380 packages to be removed. I ran pkg leaf and discovered that some packages I had installed were listed by pkg autoremove.
Code:
pkg autoremove -n > pkg.auto  # get list of pkgs to be removed.
pkg leaf > pkg.leaf  # get list of packages explicitly installed

# packages to be removed by autoremove
# list packages that are known to have been installed
pkg leaf > pkg.leaf

# list packages that autoremove reports
pkg autoremove -n > pkg.auto

# munge data files to get package names

# packages to be removed
# remove heading and training comment lines and version numbers
tail -n +5  pkg.auto | ghead -n -4 | gsed "s/^[ \t]*//" - | cut -d":" -f1 - | sort > pkg.remove

# packages installed
# remove version numbers
cat pkg.leaf | sort | rev | cut -d"-" -f 2- | rev > pkg.install

# find common packages (file1 and file2 must be sorted in the same order)
comm -1 -2 pkg.remove pkg.install > pkg.overlap

wc -l pkg.overlap
     154 pkg.overlap

It was my understanding that pkg autoremove would not attempt to remove pkgs that had been explicitly installed. Was I wrong?
 
It was my understanding that pkg autoremove would not attempt to remove pkgs that had been explicitly installed. Was I wrong?
No, that's correct. But your interpretation of a "leaf package" is wrong. A leaf package is an installed package no other installed package currently depends on. So, if you installed something that depends on package foo, then deinstall it, foo becomes a leaf package because nothing else depends on it any more.

If you want to list all explicitly installed packages, use pkg prime-list instead.

BTW, you can manually change the flag telling whether a package is considered "explicitly installed" (called "automatic", so, the opposite meaning) using pkg-set(8).
 
Thanks. I did use prime-list to solve this as you suggested. Something happened on my system to scramble pkg. I do not know what it was as I use binary packages from QUARTERLY and from Poudriere exclusively.

In the end I exited the desktop, from the console I ran sudo su, then as root created a file using pkg prime-list > pkg.prime, and then ran pkg autoremove.

As I suspected, this clobbered the desktop GUI ( mate). I then ran autoremove once more to assure myself that nothing was reported. Next I ran this one-liner to reinstall the packages in pkg.prime: for PKG in $(cat pkg.prime); do echo $PKG; pkg install -f -y $PKG; done. This did not restore mate however, so how I installed it to begin with escapes me. But this entire situation is bizarre since I ran pkg autoremove -n just before Christmas and it reported nothing.

Anyway, I installed mate. Exiting to my own user I ran startx and lo, my desktop was as I had left it.
 
You probably installed and later removed x11/mate. That is a so-called meta-port. Removing it won't change anything but everything it installed was installed as 'automatic'. And pkg-autoremove(8) correctly cleaned those. If you remove a port/package, make sure to always run pkg-autoremove(8) after it.

Exiting to my own user I ran startx and lo, my desktop was as I had left it.
Removing packages doesn't remove their configuration files. Certainly no configuration files that might be in a user's home directory. Once you reinstalled those packages everything will work as usual again.
 
Back
Top