# Introducing freebsd-update-probe (freebsd-update-probe.sh)



## tux2bsd (Mar 26, 2022)

I've written a script that improves the efficiency of updating FreeBSD.  Some backstory, last year I worked with Colin Percival, and others, to improve `freebsd-update` but the intertwined nature of `freebsd-update` with many permutations of run modes, jails/rollback and so on. Colin's lack of time meant that it was not going to fruitful so I stopped working on it.  Also, Colin's focus is elsewhere (improved boot times) so it's better for everyone if he continues with that.

Recently I had an epiphany that I could implement my improvement a different way, `freebsd-update-probe.sh` is the result:









						GitHub - tux2bsd/freebsd-update-probe
					

Contribute to tux2bsd/freebsd-update-probe development by creating an account on GitHub.




					github.com
				




Written and tested on FreeBSD 13.1, 13.0, reported working on 12.2, 12.3.  Not intended for use with the development versions STABLE / CURRENT (mentioned by grahamperrin below).

edit:
_But I've got no updates how will I test what it will do when there are updates?_
You can remove or edit /var/db/freebsd-update/tag, change/remove a single character in the file is enough.  `freebsd-update` regenerates that file.

edit: added 13.1 to list, as mentioned below


----------



## Geezer (Mar 26, 2022)

Tried it out and it works, of course. I am sure this will be useful.


----------



## mer (Mar 26, 2022)

That is nice and simple.  Good stuff.  Comments in the code, how dare you!  ( kidding of course ).


----------



## grahamperrin@ (Mar 26, 2022)

Thanks! 

Maybe add a line to clarify that it's not intended for use with STABLE or CURRENT. 









						freebsd-update-probe/README.md at master · tux2bsd/freebsd-update-probe
					

Contribute to tux2bsd/freebsd-update-probe development by creating an account on GitHub.




					github.com
				




Most people who are already familiar with freebsd-update(8) will know that it does not apply to STABLE or CURRENT.

People who find _freebsd-update-probe_ in GitHub via Google or whatever might lack that knowledge.


----------



## tux2bsd (Mar 26, 2022)

grahamperrin said:


> Maybe add a line to clarify that it's not intended for use with STABLE or CURRENT.


I've added some info, specifying *Written on FreeBSD 13.0* and noting it should be good for 12.2 (`freebsd-update` still works the same way)

I would like some more information though, I've read this:


> _FreeBSD-STABLE is the *development branch *from which major releases are made
> FreeBSD-CURRENT is the *"bleeding edge"* of FreeBSD *development*_



I haven't used FreeBSD *14*.x (*development* at this point in time), are they removing or changed away from `freebsd-update`?  Or is it that development branches don't use `freebsd-update` anyway?


----------



## mer (Mar 26, 2022)

I think that freebsd-update was only intended for use on -RELEASE of things.  I believe there is also a potential for issues when
using a non GENERIC kernel.
I can almost see this as being a wrapper or precursor to calling freebsd-update proper.
Maybe need to handle a couple of things across releases ( the -r option on freebsd-update)
but this is good stuff.


----------



## tux2bsd (Mar 26, 2022)

mer said:


> I can almost see this as being a wrapper or precursor to calling freebsd-update proper.


That is exactly what it is, by design.  Though it is intended for a stock standard environment, for boring people like me.

I suspect a non-generic kernel would work fine.

Jails are a different animal, it was the jail stuff that ultimately stopped my fix going into `freebsd-update` 4 odd months ago (deep dive the bug report in the readme if you're really bored).


----------



## Mayhem30 (Mar 27, 2022)

It appears to be working just fine on 12.2.

I created my own script for crontab to email me when updates are available. It's nothing fancy, but it works.


```
#!/usr/local/bin/bash

# Update the probe.sh file from time to time
# https://github.com/tux2bsd/freebsd-update-probe

if [ `whoami` != 'root' ] ; then
   echo "You must be root to do this."
   exit
fi

OUTPUT="$(/home/<username>/freebsd-update-probe.sh)"

if [[ $OUTPUT == *"tag file: FAIL"* ]]; then
  echo -e "FreeBSD OS updates are available."
fi
```


----------



## tux2bsd (Mar 27, 2022)

```
OUTPUT="$(/home/<username>/freebsd-update-probe.sh)"

if [[ $OUTPUT == *"tag file: FAIL"* ]]; then
  echo -e "FreeBSD OS updates are available."
fi
```
this is where exit codes come into play, rather than relying on the text output:

```
/home/<username>/freebsd-update-probe.sh || echo -e "FreeBSD OS updates are available."
```
but I suspect you don't want the text output from freebsd-update-probe.sh, what you can do instead is (via redirection):

```
/home/<username>/freebsd-update-probe.sh 1>/dev/null || echo -e "FreeBSD OS updates are available."
```
since that's a one-liner you can just run it and see

```
if [ `whoami` != 'root' ] ; then
   echo "You must be root to do this."
   exit
fi
```
You can pop a 1 in there, i.e. exit 1, which means it's not successful, for what your script is mandating (if not root then no).

Mayhem30 you haven't done anything wrong, these are just hints for when you want to do more with your scripts.

Also, bash has a built-in $UID and root is UID 0 , so you can do a numeric test there instead.  ( $UID is bash specific i.e. not applicable with /bin/sh ).


----------



## tux2bsd (Mar 27, 2022)

I meant to post this earlier
_But I've got no updates how will I test what it will do when there are updates?_
You can remove or edit /var/db/freebsd-update/tag, change/remove a single character in the file is enough.  `freebsd-update` regenerates that file.


----------



## Mayhem30 (Mar 27, 2022)

tux2bsd said:


> _*Mayhem30*_ you haven't done anything wrong, these are just hints for when you want to do more with your scripts.
> 
> Also, bash has a built-in $UID and root is UID 0 , so you can do a numeric test there instead. ( $UID is bash specific i.e. not applicable with /bin/sh ).



Thanks for the tips!


----------



## tux2bsd (Mar 31, 2022)

Ever so slight changes, added a "Version".  Removed a sed, modifiy with awk gsub instead.  Added an extra script that Mayhem30 can learn a little bash trick from.


----------



## Mayhem30 (Mar 31, 2022)

Thank you, I'll check it out later tonight.


----------



## tux2bsd (Apr 7, 2022)

I hope you got your recent updates (13.0-p11) without any issues, mine worked fine but I got annoyed with the word FAIL.

New version, 20220407, Minor change: "wording.  PASS > MATCH, FAIL > CHECK.  FAIL was misleading"









						GitHub - tux2bsd/freebsd-update-probe
					

Contribute to tux2bsd/freebsd-update-probe development by creating an account on GitHub.




					github.com
				




(Mayhem30, this is prime example of not trusting text output from a program (the exit codes are still the same, those are set in stone))


----------



## tux2bsd (Apr 7, 2022)

p.s. if anyone has a FreeBSD 11 install somewhere I'd be interested to know if this works on it too.


----------



## Mayhem30 (Apr 7, 2022)

It worked great for me on the latest 12.3-RELEASE-p5 update.

It's difficult for me to break away from trusting text output, as that's the way I've been doing things for years now. I'm slowing breaking away from that though.


----------



## tux2bsd (May 17, 2022)

edit2 (top edit): freebsd-update-probe.sh works as expected on 13.1

Note freebsd-update-probe.sh this won't detect 13.1-RELEASE being available (neither does `freebsd-update fetch install`), upgrading releases is a separate and deliberate action. I should note that in the usage (todo done).

edit: I've updated the usage and README to reflect this, and version number bumped as the output of the usage changes.


----------

