#!/bin/bash
#
# This script is meant to test for the available OS version. It does allow
# checking for the exact version number of the currently installed OS and this
# way some filtering for an available feature in an installed lib (like libSDL)
# can be checked more easily.

REQUIRED_MAJOR=1
REQUIRED_MINOR=7
REQUIRED_RELEASE=0
REQUIRED_BUILD=0

REQUIRED_VERSION_FOUND="no"

OS_MAJOR=`cat /etc/op-version | grep -e "^Version" | cut -d " " -f 2 | cut -d "." -f 1`
OS_MINOR=`cat /etc/op-version | grep -e "^Version" | cut -d " " -f 2 | cut -d "." -f 2`
OS_RELEASE=`cat /etc/op-version | grep -e "^Version" | cut -d " " -f 2 | cut -d "." -f 3`
OS_BUILD=`cat /etc/op-version | grep -e "^Version" | cut -d " " -f 2 | cut -d "." -f 4`

if [ "$REQUIRED_MAJOR" -lt "$OS_MAJOR" ]
then
    REQUIRED_VERSION_FOUND="yes"
elif [ "$REQUIRED_MAJOR" -eq "$OS_MAJOR" ] && [ $REQUIRED_MINOR -lt $OS_MINOR ]
then
    REQUIRED_VERSION_FOUND="yes"
elif [ "$REQUIRED_MAJOR" -eq "$OS_MAJOR" ] && [ $REQUIRED_MINOR -eq $OS_MINOR ] && [ $REQUIRED_RELEASE -lt $OS_RELEASE ]
then
    REQUIRED_VERSION_FOUND="yes"
elif [ "$REQUIRED_MAJOR" -eq "$OS_MAJOR" ] && [ $REQUIRED_MINOR -eq $OS_MINOR ] && [ $REQUIRED_RELEASE -eq $OS_RELEASE ] && [ $REQUIRED_BUILD -lt $OS_BUILD ]
then
    REQUIRED_VERSION_FOUND="yes"
fi

echo $REQUIRED_VERSION_FOUND
