Finding all installed packages that do not have a corresponding remote package

tobik@

Developer
This is for the following scenario, but should work for the official package repository too:
  • You have setup your own package repository with ports-mgmt/poudriere and use that for installing packages.
  • You have installed (tried out) ports that are not in that repository.

Create /usr/local/sbin/localonlypackages with:
Code:
#!/bin/sh
cat <<EOF | sort | uniq -u
`pkg query %n | xargs pkg rquery %n`
`pkg query %n`
EOF
Substitute %n with %o to get a list of port origins instead of package names.
Make it executable: chmod +x /usr/local/sbin/localonlypackages.

To list all of those packages run localonlypackages and to remove them localonlypackages | xargs pkg remove -y.
 
Nice. We can take this a step further now and define an alias in /usr/local/etc/pkg.conf. Under the ALIAS key add the following:
Code:
ALIAS              : {
  # ...
  localonly: version -vRl?,
  # ...
  }
pkg localonly will list the packages now and to remove them we can run pkg localonly | cut -f1 -w | xargs pkg remove -y.
 
This is nice but won't this also remove RESTRICTED ports with no remote(official) packages due to licensing and locally merged out of tree ports? audio/lame comes to mind.
 
Sure if it's not in the remote repository. I see no way of filtering for that generically however. Packages do not seem to be annotated with that information.

If you use my first solution I suppose you could whitelist audio/lame so that it won't appear in the output ( uniq -u will remove any port that appears more than once in the list).
Code:
#!/bin/sh
RESTRICTED_PORTS="audio/lame anyother/restricted-port"
cat <<EOF | sort | uniq -u | grep -v '^$'
`pkg query %o ${RESTRICTED_PORTS}`
`pkg query %o | xargs pkg rquery %o`
`pkg query %o`
EOF
 
Back
Top