#!/bin/sh # =================================================== # # lliurex-cdd-version # # # # Escrito por Luis GarcĂ­a # # para LliureX. Abril 2006 # # # # Devuelve la version de LliureX instalada # # =================================================== # # set -e # variables CDD_PATH="/usr/share/lliurex-cdd" CDD_TASKS_PATH="${CDD_PATH}/tasks" CDD_TASKS_LIST="classroom-srv classroom-ws desktop" CDD_NUMVERSION="" CDD_VERSION="Unknown LliureX version" RAW_CDD_VERSION="" #funciones usage(){ echo "Usage: $0 {-n|-v|-a|-h}" >&2 echo " $0 -t CDD_NAME" >&2 } get_cdd_version(){ local CTASK VERSION_FILE VERSION_FILE="${CDD_PATH}/version" if [ -r "$VERSION_FILE" ] ; then CDD_NUMVERSION="$(head -1 "${VERSION_FILE}")" RAW_CDD_VERSION="$(find "${CDD_PATH}" -name "cddversion" -exec cat {} \; |sort -u)" if [ "$RAW_CDD_VERSION" ] ; then CDD_VERSION="$(echo "${RAW_CDD_VERSION}" |tr "\n" "," |sed -e "s%[[:blank:]]*$%%;s%,$%%;s%,%, %g")" fi fi return 0 } say_cdd_version(){ get_cdd_version if [ -z "$CDD_NUMVERSION" ] ; then echo "${CDD_VERSION}" >&2 return 0 fi case "$1" in n) echo "${CDD_NUMVERSION}" ;; v) echo "${CDD_VERSION}" ;; a) echo "${CDD_VERSION} ${CDD_NUMVERSION}" ;; esac return 0 } test_cdd_version(){ get_cdd_version if [ "$RAW_CDD_VERSION" ] ; then if echo "$RAW_CDD_VERSION" |grep -q "^${1}$" ; then return 0 fi fi return 1 } case "$1" in "-h"|"--help") usage ;; "-n"|"--number") say_cdd_version n ;; "-v"|"--version") say_cdd_version v ;; "-t"|"--test") [ "$2" ] || exit 1 test_cdd_version "$2" || exit 1 ;; *) say_cdd_version a ;; esac exit 0