#!/usr/bin/env python3
# file: osversion.py
# vim:fileencoding=utf-8:fdm=marker:ft=python
#
# Author: R.F. Smith <rsmith@xs4all.nl>
# Created: 2018-04-06 22:34:00 +0200
# Last modified: 2018-07-06T22:54:44+0200

from ctypes import CDLL

with open('/usr/include/osreldate.h') as h:
    lines = h.readlines()
line = [ln for ln in lines if ln.startswith('#define')][0]
print('Compilation environment version:', line.split()[-1])

libc = CDLL("/lib/libc.so.7")
print('Execution environment version:', libc.getosreldate())

@@ -189,51 +189,238 @@
 18-0
-7-06T22:54:44+0200%0A%0Afrom ctypes import CDLL
+8-19T14:18:16+0200%0A%22%22%22Print the __FreeBSD_version. This is also called OSVERSION in scripts.%22%22%22%0A%0Afrom ctypes import CDLL%0Aimport sys%0A%0Aif 'freebsd' not in sys.platform:%0A    print('This script only works on FreeBSD!')%0A    sys.exit(1)
 %0A%0Awi

Print a warning and exit when not run on FreeBSD.