recover installed package list based on file list content of /usr/local/bin

OP
Alain De Vos

Alain De Vos

Aspiring Daemon

Reaction score: 161
Messages: 608

I found as alternative "pkg backup" , but as /var was completely lost this cannot be used.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 9,279
Messages: 33,825

I'm going to say, you're screwed. There's pkg-which(8) which might be useful, but that too relies on information stored in /var. So you're left with a lot of guesswork. It's usually quite obvious where things came from but it's going to take a lot of work and guessing to figure it out.
 

Crivens

Moderator
Staff member
Moderator

Reaction score: 1,260
Messages: 2,246

You may compare the content with the pkg-plist files in the ports, that should give you a good idea. Kernel modules will not be found that way. Some shell-fu with a |sort|uniq will give you a starting point.
My shell skills are not up to speed any my linear thinking mode is offline since I'm busy since oh-dark-stupid (0430 to be precise).
 
OP
Alain De Vos

Alain De Vos

Aspiring Daemon

Reaction score: 161
Messages: 608

Lol. Luckely i have found a two months old "pkg info" output .
In fact I'll write a daily "pkg info" script in crontab. Lessons learned.
 

olli@

Aspiring Daemon
Developer

Reaction score: 712
Messages: 693

Lol. Luckely i have found a two months old "pkg info" output .
In fact I'll write a daily "pkg info" script in crontab. Lessons learned.
Don’t you have a regular backup of that machine? You can simply recover /var/db/pkg from your latest backup.
 

ralphbsz

Son of Beastie

Reaction score: 1,609
Messages: 2,536

Theoretically, this should work: Set up a test system, and install *all* packages on it. Then, for every thing you find in /usr/local/bin run "pkg which <thing>", and collate the output. Let's assume you have a complete list of file names in old_system.list, then seomthing like this should work (not tested):
Code:
( cat old_system.list | \
  while  read old_file
  do
    pkg which $old_file | \
    awk '{print $NF}'
  done ) | \
sort | uniq -c
That should give a list of packages, sorted, with a count of how many files were found for each. This is sort of the thing that crivens suggested above, just using a sacrificial test system instead of parsing the package plists.
 

Phishfry

Son of Beastie

Reaction score: 1,962
Messages: 4,960

Have you looked at your user history file for possible pkg clues?
I typically increase history threshold to "set history = 10000" in .cshrc for exactly this reason.

pkg install &{up key}

Obviously this would only work for pkg based installs.
 

jmos

Member

Reaction score: 64
Messages: 84

In fact I'll write a daily "pkg info" script in crontab.
Loosely based on my backup:

pkg info > /path/to/mount/packages_all.txt
pkg query -e '%a = 0' %o > /path/to/mount/packages_base.txt
pkg query -e '%#r == 0' '%n-%v' > /path/to/mount/packages_nodeps.txt


pkg info is the least important - would only result in having packages restored as manually installed while they were automatic before. Only makes sense for a final comparison. But the other two are also great to set up new machines ;)
 

Crivens

Moderator
Staff member
Moderator

Reaction score: 1,260
Messages: 2,246

My root user has an "install.sh" script which contains all the commands I use for installing. One only needs to add to it. It also takes care of ports with changed flags or versions, like lame and drm-kmod.
Just my 2c.
 
OP
Alain De Vos

Alain De Vos

Aspiring Daemon

Reaction score: 161
Messages: 608

In such a script I would backup /usr/local/etc and remove /usr/local
 

mjollnir

Daemon

Reaction score: 699
Messages: 1,154

Loosely based on my backup:

pkg info > /path/to/mount/packages_all.txt
pkg query -e '%a = 0' %o > /path/to/mount/packages_base.txt
pkg query -e '%#r == 0' '%n-%v' > /path/to/mount/packages_nodeps.txt


pkg info is the least important - would only result in having packages restored as manually installed while they were automatic before. Only makes sense for a final comparison. But the other two are also great to set up new machines ;)
I find descriptive aliases for leaf & prime-* in pkg alias. IMHO better use these, especially in a posting, because we can quickly guess what these commands do, instead of looking it up by pkg help query.
My root user has an "install.sh" script which contains all the commands I use for installing. One only needs to add to it. It also takes care of ports with changed flags or versions, like lame and drm-kmod.
Just my 2c.
Please post that script to Usefull Scripts?
 
Top