# ******************************************************************* # ** @file /var/install/include/eismanlib - common routines for eisman # ** # ** Creation: 2013-01-13 dv # ** Last update: $Id$ # ** # ** Copyright (c) 2013-@@YEAR@@ the eisfair team, team(at)eisfair(dot)org # ** # ** 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. # ******************************************************************* # header width in characters within package database FIELDHEADER="11" # ******************************************************************* # ** wait animation # ** @param $1 wait text # ** @return n/a # ******************************************************************* show_wait() { local length="$((${#1} + 4))" local state=0 echo -n "[ ] ${1}" echo -en "\033[${length}D" while [ -n "`ps --no-headers $!`" ] do case "${state}" in 0) echo -en "[/\033[2D" state=1 ;; 1) echo -en "[-\033[2D" state=2 ;; 2) echo -n "[\\" echo -en "\033[2D" state=3 ;; *) echo -en "[|\033[2D" state=0 ;; esac usleep 100000 done echo -n " " echo -en "\033[50D" } # ******************************************************************* # ** split a version string into it's parts # ** @param $1 version string # ** @return $major, $minor and $revision $cvs $cvs_time # ******************************************************************* split_version() { v=${1} cvs='' svn='' cvs_time='' 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 compares two version strings and outputs the result # ** to stdout # ** If version2 is more recent than version1, the function outputs # ** the result "new" # ** If version2 is equal to version1, the function outputs # ** the result "installed" # ** If version2 is older than version1, the function outputs # ** the result "old" # ** @param $1 version string 1 # ** @param $2 version string 2 # ** @return "new", "installed" or "old" on stdout # ******************************************************************* diff_version() { local new_status="new" local old_status="old" local inst_status="installed" 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 diff_status=${new_status} elif [ "${vv1_cvs}" != "" -a "${vv2_cvs}" = "" ] then diff_status=${old_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} ## 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 diff_status=${new_status} elif [ "${vv1_time}" != "" -a "${vv2_time}" = "" ] then diff_status=${old_status} ## now compare the cvs time elif [ `/usr/bin/expr "${vv1_time}" \< "${vv2_time}"` = "1" ] then diff_status=${old_status} elif [ `/usr/bin/expr "${vv1_time}" \> "${vv2_time}"` = "1" ] then diff_status=${new_status} ## now difference was found else diff_status=${inst_status} fi echo "${diff_status}" } # ******************************************************************* # ** strip filename and php call parameters from url, so that only the # ** static part remains. # ** @param $1 full qualified URL to a package resource # ** @return static part of the URL without file name # ******************************************************************* get_base_url() { local url="${1}" if [ -n "${url}" ] then echo "${url}" | cut -d '?' -f 1 | xargs dirname | sed -e 's|/[0-9]*$||' fi }