Script "is_new_version_avail.sh"
#!/bin/sh

# -----------------------------
# is_new_version_avail.sh
# version 1.1.7.4
# -----------------------------

# check for parameters
_usage_str="Usage: ${0} package-name"
if [ $# -eq 0 ] || [ "${1}" = "--help" ] || [ "${1}" = "--usage" ]; then
  printf "%s\n" "${_usage_str}"
  exit 0
fi

PKGNAME=""
for arg in $@
do
  is_option=`echo ${arg} | grep '\-\-'`
  if [ -z "${is_option}" ]; then
    [ -z "${PKGNAME}" ] && PKGNAME="${arg}"
  else
    echo "${0}: unknown option '${arg}'"
  fi
done

if [ -z "${PKGNAME}" ]; then
  printf "%s\n" "${_usage_str}"
  exit 0
fi

# check the presence of required directories

cd `dirname "${0}"`

[ -z "${BUILD_FARM}" ] && BUILD_FARM="${HOME}/build-farm"
if [ ! -d "${BUILD_FARM}" ]; then
  echo "ERROR: base directory '${BUILD_FARM}' doesn't exist. Abort."
  exit 1
fi

[ -z "${VCHECKCMDS_DIR}" ] && VCHECKCMDS_DIR="VCHECKCMDS"
if [ ! -d ./"${VCHECKCMDS_DIR}" ]; then
  echo "ERROR: build farm is broken; version check commands directory doesn't exist. Abort."
  exit 1
fi

# A: Get the version of the current (already built) package

printf "  current version of package '%s': " "${PKGNAME}"
CURRENT_VERSION="(unknown)"

target_triplet=`gcc -v 2>&1 | grep "Target:" | awk '{print $2}' | tr '-' ' '`

if [ -z ${ARCH_NAME} ]; then
  case `uname -m` in
    ppc)
      ARCH_NAME="powerpc"
      ;;
    *)
      ARCH_NAME=`echo "${target_triplet}" | awk '{print $1}'`
      ;;
  esac
fi

if [ -z "${BINPACKAGES_DIR}" ]; then
  BINPACKAGES_DIR=PACKAGES/binpkg-"${ARCH_NAME}"
  [ -d "${BUILD_FARM}/${BINPACKAGES_DIR}" ] || BINPACKAGES_DIR=PACKAGES/binpkg
fi
if [ -d "${BUILD_FARM}/${BINPACKAGES_DIR}" ]; then
  package_for_pkgname=`ls -tp "${BUILD_FARM}/${BINPACKAGES_DIR}"/*"${PKGNAME}"* 2>/dev/null | head -1`
  if [ ! -z "${package_for_pkgname}" ]; then
    CURRENT_VERSION=`basename "${package_for_pkgname}" | cut -d'-' -f2`
  ##else
    ##printf "ERROR: no such package '%s'. Abort.\n" "${PKGNAME}"
    ##exit 1
  fi
fi

echo "${CURRENT_VERSION}"

# B: Get the version of the available package

# check for required binaries; version check commands may be sure that they are available for them
REQD_BINS=""
which sed >/dev/null 2>&1 || type sed >/dev/null 2>&1 || REQD_BINS="sed,${REQD_BINS}"
which wget >/dev/null 2>&1 || type wget >/dev/null 2>&1 || REQD_BINS="wget,${REQD_BINS}"
which lynx >/dev/null 2>&1 || type lynx >/dev/null 2>&1 || REQD_BINS="lynx,${REQD_BINS}"
if [ -n "${REQD_BINS}" ]; then
  echo -e `basename ${0}`: "Required binaries (${REQD_BINS}\010) are not present."
  exit 1
fi

SCRIPT_DIR=`pwd`
VCHECK_TEMPDIR="${VCHECKCMDS_DIR}"/.tmp
mkdir -p "${SCRIPT_DIR}/${VCHECK_TEMPDIR}"
cd "${SCRIPT_DIR}/${VCHECK_TEMPDIR}"

if [ -f "${SCRIPT_DIR}/${VCHECKCMDS_DIR}"/vcheck-"${PKGNAME}" ]; then
  # version check commands do something and set NEW_VERSION variable
  source "${SCRIPT_DIR}/${VCHECKCMDS_DIR}"/vcheck-"${PKGNAME}"
  if [ ! -z "${NEW_VERSION}" ]; then
    printf "available version of package '%s': %s\n" "${PKGNAME}" "${NEW_VERSION}"
  else
    echo "Sorry, can't get available version for this package."
  fi
else
  printf "Sorry, version check commands for '%s' cannot be found.\n" "${PKGNAME}"
fi

# clean up
cd "${SCRIPT_DIR}"
if [ ! -z "${VCHECK_TEMPDIR}" ]; then
  [ -d ./"${VCHECK_TEMPDIR}" ] && rm -rf ./"${VCHECK_TEMPDIR}"
fi
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.