Shell Wrapper for freebsd-version(1)

I have this script for freebsd-version(1) for systems with version before 10:

Code:
#! /bin/sh
# Wrapper for `freebsd-version`
    s=$( which freebsd-version )
    if [ -n "$s" -a ! $( dirname "$0" ) = $( dirname "$s" ) ]; then
        # System `freebsd-version`
#echo "version from 'freebsd-version'"
        $s
    else
        # This `freebsd-version`
        # Check if sources are installed on the system, then get version from there, if not
        # version is from `uname`
        sUname=$( uname -r )
        s="/usr/src/sys/conf/newvers.sh"
        if [ -f "$s" ]; then
#echo "Version from sources"
            s=$( cat $s | egrep '^BRANCH=' )
            s=${s##*=}
            # Remove double quotes
            s=$( eval echo $s )
            s=${s##*-}
            echo "${sUname%-*}-${s}"
        else
            # `uname` is the only way
#echo "Version from 'uname'"
            echo "$sUname"
        fi
    fi
Is this right in your eyes?
 
Ok. My goal was to print the current patch level version, major and minor versions are always correct. Sometimes, on 9.x machines when freebsd-update cron runs (per month), it reports the system is out of date, i.e. not at current patch level, but it was because the kernel was not involved in patches (I guess). I'm not sure if it due to this. Running uname the patch level most of times is one or two number less than the real patch level (I hope my explanation is understandable).

So, freebsd-version on 10.x (and greater) machines, always report the current patch level, on 9.x (and lesser) there is no freebsd-version command, hence the script above.

The script must be placed on a path in $PATH with less priority the one freebsd-version is located, so if the real freebsd-version is present (on 10.x and greater) the script runs the real one, else (9.x or lesser) it looks at sources, if they are installed on the system get the patch level from there, if none of the above it ask to uname what it think about system version.

At the end of the game, when I (monthly) receive the mail from freebsd-update cron, before upgrading the system (if needed) I check the real patch level on that machine (whith freebsd-version). If it matches with the one in the mail I skip the update.
 
Top