#! /bin/sh #---------------------------------------------------------------------------- # check-version - check a package-version # # usage: check-version package_name check_version # or: check-version -diff version-1 version-2 # # return values as output on stdout: # # new - version is newer than the installed package # old - version is older than the installed package # installed - version of package is identical (installed) # not-installed - package is not installed # # Copyright (c) 2003-2003 Frank Meyer # # Creation: 19.07.2003 fm # Last Update: $id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- new_status="new" old_status="old" inst_status="installed" notinst_status="not-installed" read_package_version () { f=$1 while read l do case "$l" in ""*) l=`echo "$l" | sed 's###g'` set -- $l have_package_version="$1" ;; esac done < $f } split_version () { v=$1 cvs='' case $v in 1.0beta) v=0.90.0 ;; 1.0beta-patch-*) IFS='-' set -- $v unset IFS v=0.90.$3 ;; *cvs*) cvs=`echo "$v" | sed 's/^.*cvs//'` v=`echo "$v" | sed 's/cvs.*$//'` ;; esac case "$v" in [0-9]*.[0-9]*.[0-9]*) IFS='.' set -- $v unset IFS major=$1 minor=$2 revision=$3 ;; [0-9]*.[0-9]*) IFS='.' set -- $v unset IFS major=$1 minor=$2 revision=0 ;; *) major=0 minor=0 revision=0 ;; esac } diff_version () { vv1=$1 vv2=$2 split_version $vv1 vv1_major=$major vv1_minor=$minor vv1_revision=$revision vv1_cvs=$cvs split_version $vv2 vv2_major=$major vv2_minor=$minor vv2_revision=$revision vv2_cvs=$cvs ### first compare major version if [ $vv1_major -lt $vv2_major ] then diff_status=$old_status elif [ $vv1_major -gt $vv2_major ] then diff_status=$new_status ### next try minor version elif [ $vv1_minor -lt $vv2_minor ] then diff_status=$old_status elif [ $vv1_minor -gt $vv2_minor ] then diff_status=$new_status ### last try revision elif [ $vv1_revision -lt $vv2_revision ] then diff_status=$old_status elif [ $vv1_revision -gt $vv2_revision ] then diff_status=$new_status ### if all is equal, look if a package has a cvs version elif [ "$vv1_cvs" = "" -a "$vv2_cvs" = "" ] then diff_status=$inst_status ### cvs versions always equals matching non-cvs versions elif [ "$vv1_cvs" = "" -a "$vv2_cvs" != "" ] then diff_status=$inst_status elif [ "$vv1_cvs" != "" -a "$vv2_cvs" = "" ] then diff_status=$inst_status ### now compare the cvs date elif [ `/usr/bin/expr "$vv1_cvs" \< "$vv2_cvs"` = "1" ] then diff_status=$old_status elif [ `/usr/bin/expr "$vv1_cvs" \> "$vv2_cvs"` = "1" ] then diff_status=$new_status ### now difference was found else diff_status=$inst_status fi } if [ "$1" = "-diff" ] then shift v1=$1 v2=$2 diff_version $v1 $v2 package_status="$diff_status" else package_name=$1 check_version=$2 if [ -f /var/install/packages/$package_name ] then read_package_version /var/install/packages/$package_name diff_version $check_version $have_package_version package_status="$diff_status" else package_status="$notinst_status" fi fi echo $package_status