I have this script for freebsd-version(1) for systems with version before 10:
Is this right in your eyes?
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