Search | Sailfish OS | Running | PineTime | All Posts

FreeBSD packages routine

November 15, 2023 — Nico Cartron

Again one of those articles I'm writting for myself, but could benefit others!


Context

I recently moved to a personal laptop running FreeBSD (a Lenovo T440p, for which I still need to write an article!)

I decided to stick to FreeBSD packages, and not mess around with ports this time.
But I wanted to have an easy way to maintain those packages.

FreeBSD Forums to the rescue

When searching on the FreeBSD forums, I found this excellent post which does exactly what I want: not only updating the packages, but also taking care of cleaning the unused ones, and showing me some potential security issues.

Here's what the approach looks like:

  1. pkg update -f
  2. pkg upgrade
  3. pkg autoremove
  4. pkg audit -F
  5. pkg clean
  6. pkg stats

What this does should be obvious:

  • update the local packages repository catalogue
  • upgrade the packages
  • removes the packages who got automatically installed (dependencies) and are no longer needed
  • show the security vulnerabilities for the installed packages (if any)
  • cleans the local cache
  • displays stats about the packages database

Quick and dirty Shell script

OK, nothing really fancy here, it's just a way for me to run this on a regular basis:

#!/bin/sh

echo "#############"
echo "# 1 - Updating Packages with 'pkg update -f'"
echo "#############"
pkg update -f
printf "%s " "Press enter to continue"
read ans

echo ""
echo "--------------------------------------"
echo ""
echo "#############"
echo "# 2 - Upgrading Packages with 'pkg upgrade'"
echo "#############"
pkg upgrade
printf "%s " "Press enter to continue"
read ans

echo ""
echo "--------------------------------------"
echo ""
echo "#############"
echo "# 3 - Removing Packages not required anymore with 'pkg autoremove'"
echo "#############"
pkg autoremove
printf "%s " "Press enter to continue"
read ans

echo ""
echo "--------------------------------------"
echo ""
echo "#############"
echo "# 4 - Auditing installed packages against known vulnerabilities with 'pkg audit -F'"
echo "#############"
pkg audit -F
printf "%s " "Press enter to continue"
read ans

echo ""
echo "--------------------------------------"
echo ""
echo "#############"
echo "# 5 - Cleaning the local cache of fetched remote packages with 'pkg clean'"
echo "#############"
pkg clean

printf "Do you want to display the stats with 'pkg stats'? (y/n)"
read ans
if [ "$ans" != "${ans#[Yy]}" ] ; 
then
    pkg stats
else
    exit
fi

Tags: FreeBSD


I don't have any commenting system, but email me (nicolas at ncartron dot org) your comments!
If you like my work, you can buy me a coffee!