#! /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-2007 the eisfair team, team(at)eisfair(dot)org # # Creation: 2003-07-19 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. #---------------------------------------------------------------------------- #exec 2> /tmp/check-version-trace$$.log #set -x new_status="new" old_status="old" inst_status="installed" notinst_status="not-installed" read_package_version () { FNAME=${1} while read l do case "${l}" in ""*) l=`echo "${l}" | sed 's###g'` set -- ${l} have_package_version="${1}" ;; esac done < ${FNAME} } split_version () { v=${1} cvs='' svn='' case ${v} in 1.0beta) v=0.90.0 ;; 1.0beta-patch-*) IFS='-' set -- ${v} unset IFS v=0.90.${3} ;; *cvs*|*svn*) svn=`echo "${v}" | sed 's/^.*[cvs|svn]//'` v=`echo "${v}" | sed 's/[cvs|svn].*$//'` case "${svn}" in *:*) # this is for the svn_short tag MM-DDhh:mm # it comes with mktarball.sh -hometest cvs="`date +%Y`-"`echo "${svn}" | cut -c-5` cvs_time=`echo "${svn}" | cut -c6-` ;; *) cvs=${svn} ;; esac ;; 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} vv1_time=${cvs_time} split_version ${vv2} vv2_major=${major} vv2_minor=${minor} vv2_revision=${revision} vv2_cvs=${cvs} vv2_time=${cvs_time} ### 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 if [ ${use_eisler} -eq 0 ] then diff_status=${inst_status} else diff_status=${new_status} fi elif [ "${vv1_cvs}" != "" -a "${vv2_cvs}" = "" ] then if [ ${use_eisler} -eq 0 ] then diff_status=${inst_status} else diff_status=${old_status} fi ### now compare the cvs date elif [ `/usr/bin/expr "${vv1_cvs}" \< "${vv2_cvs}"` = "1" ] then if [ ${use_eisler} -eq 0 ] then diff_status=${inst_status} else diff_status=${old_status} fi elif [ `/usr/bin/expr "${vv1_cvs}" \> "${vv2_cvs}"` = "1" ] then if [ ${use_eisler} -eq 0 ] then diff_status=${inst_status} else diff_status=${new_status} fi ### if all is equal, look if a package has a cvs time elif [ "${vv1_time}" = "" -a "${vv2_time}" = "" ] then diff_status=${inst_status} ### cvs time always equals matching non-cvs time elif [ "${vv1_time}" = "" -a "${vv2_time}" != "" ] then if [ ${use_eisler} -eq 0 ] then diff_status=${inst_status} else diff_status=${new_status} fi elif [ "${vv1_time}" != "" -a "${vv2_time}" = "" ] then if [ ${use_eisler} -eq 0 ] then diff_status=${inst_status} else diff_status=${old_status} fi ### now compare the cvs time elif [ `/usr/bin/expr "${vv1_time}" \< "${vv2_time}"` = "1" ] then if [ ${use_eisler} -eq 0 ] then diff_status=${inst_status} else diff_status=${old_status} fi elif [ `/usr/bin/expr "${vv1_time}" \> "${vv2_time}"` = "1" ] then if [ ${use_eisler} -eq 0 ] then diff_status=${inst_status} else diff_status=${new_status} fi ### now difference was found else diff_status=${inst_status} fi } #----------------------------------------------------------------------------- # main #----------------------------------------------------------------------------- use_eisler=1 if [ "${1}" = "-diff" ] then if [ `grep eisler /var/install/url` ] then use_eisler=0 fi 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}