#---------------------------------------------------------------------------- # /var/install/include/packagelib - library for eisfair scripts # # Copyright (c) 2006 the eisfair team, c/o Frank Meyer, frank(at)eisfair(dot)org # # Creation : 2005-11-29 jed # 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. #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # interface description #---------------------------------------------------------------------------- # parse_infofile() : parse infofile content and make it available via # environment variables, e.g. # parse_infofile mailquota MQ # # strip_extension(): strip extension from given variable, e.g. # strip_extension _PACKAGE_REQUIRE_PACKAGE_2_NAME .tar #---------------------------------------------------------------------------- #============================================================================ # only include this file once #============================================================================ if [ "$_PACKAGELIB" != "true" ] then _PACKAGELIB='true' # sub normalize_version # ===================== # reads the version of the package and normalizes the value (to provide # compatibility to older versions). normalize_version () { case "$1" in 1.0beta) echo "0.90.0";; 1.0beta-patch-[0-9]*) echo "$1" | sed -e 's#^1.0beta-patch-\([0-9]*\)#0.90.\1#';; [0-9]*.[0-9]*.[0-9]*) echo "$1" | sed -e 's#^\([0-9]*\)[^0-9]*\.\([0-9]*\)[^0-9]*\.\([0-9]*\).*#\1.\2.\3#';; [0-9]*.[0-9]*) echo "$1" | sed -e 's#^\([0-9]*\)[^0-9]*\.\([0-9]*\).*#\1.\2.0#';; *) echo "0.0.0" ;; esac } # parse_infofile # ============== # parameters: $1 name of infofile in /var/install/package # $2 [variable_prefix] # e.g. if "variable_prefix" has been set to FOO the variables # will be prefixed as FOO_PACKAGE_NAME. # # output : list of variables in alphabetic order: # _PACKAGE_AUTHOR # _PACKAGE_DATE # _PACKAGE_DESCRIPTION # _PACKAGE_NAME # _PACKAGE_REQUIRE_N # _PACKAGE_REQUIRE_1_PACKAGE ... # _PACKAGE_REQUIRE_LIB_N # _PACKAGE_REQUIRE_LIB_1_PACKAGE ... # _PACKAGE_REQUIRE_LIB_1_VERSION ... # _PACKAGE_REQUIRE_PACKAGE_N # _PACKAGE_REQUIRE_PACKAGE_1_PACKAGE ... # _PACKAGE_REQUIRE_PACKAGE_1_VERSION ... # _PACKAGE_SECTION # _PACKAGE_SHA1SUM # _PACKAGE_SHORT # _PACKAGE_STATUS # _PACKAGE_SUB_PACKAGE_N # _PACKAGE_SUB_PACKAGE_1_PACKAGE ... # _PACKAGE_SUB_PACKAGE_1_PARAM ... # _PACKAGE_VERSION parse_infofile () { if [ $# -eq 0 ] then echo "Usage: parse_infofile infofile [variable-prefix]" else # complete path of infofile if [ -f "$1" ] then _packagelib_infofile="$1" elif [ -f "/var/install/packages/$1" ] then _packagelib_infofile="/var/install/packages/$1" else mecho -error "The infofile '$1' could not be found!" return 1 fi if [ "$2" != "" ] then _packagelib_var_prefix="$2" else _packagelib_var_prefix='' fi # clear old values eval "${_packagelib_var_prefix}_PACKAGE_AUTHOR"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_DATE"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_DESCRIPTION"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_NAME"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_REQUIRE_N"=0 eval "${_packagelib_var_prefix}_PACKAGE_REQUIRE_1_PACKAGE"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_REQUIRE_LIB_N"=0 eval "${_packagelib_var_prefix}_PACKAGE_REQUIRE_LIB_1_PACKAGE"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_REQUIRE_LIB_1_VERSION"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_REQUIRE_PACKAGE_N"=0 eval "${_packagelib_var_prefix}_PACKAGE_REQUIRE_PACKAGE_1_PACKAGE"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_REQUIRE_PACKAGE_1_VERSION"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_SECTION"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_SHA1SUM"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_SHORT"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_STATUS"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_SUB_PACKAGE_N"=0 eval "${_packagelib_var_prefix}_PACKAGE_SUB_PACKAGE_1_PACKAGE"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_SUB_PACKAGE_1_PARAM"=\'\' eval "${_packagelib_var_prefix}_PACKAGE_VERSION"=\'\' while read _packagelib_line do case "${_packagelib_line}" in ""*) _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_AUTHOR="${_packagelib_value}" ;; ""*) _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_DATE="${_packagelib_value}" ;; ""*"") _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_DESCRIPTION="${_packagelib_value}" ;; ""*) _packagelib_value="`sed -e '1,//d' -e '/<\/description>/,//d' $_packagelib_infofile`" export ${_packagelib_var_prefix}_PACKAGE_DESCRIPTION="${_packagelib_value}" ;; ""*) _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_NAME="${_packagelib_value}" ;; ""*) eval _packagelib_value='$'"${_packagelib_var_prefix}_PACKAGE_NAME" if [ "$_packagelib_value" = "" ] then _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_NAME="${_packagelib_value}" fi ;; ""*) eval _packagelib_idx='$'"${_packagelib_var_prefix}_PACKAGE_REQUIRE_N" _packagelib_idx=`/usr/bin/expr ${_packagelib_idx} + 1` export ${_packagelib_var_prefix}_PACKAGE_REQUIRE_N="${_packagelib_idx}" _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_REQUIRE_${_packagelib_idx}_PACKAGE="${_packagelib_value}" ;; ""*) eval _packagelib_idx='$'"${_packagelib_var_prefix}_PACKAGE_REQUIRE_LIB_N" _packagelib_idx=`/usr/bin/expr ${_packagelib_idx} + 1` export ${_packagelib_var_prefix}_PACKAGE_REQUIRE_LIB_N="${_packagelib_idx}" _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g;s#[[:space:]].*##'`" export ${_packagelib_var_prefix}_PACKAGE_REQUIRE_LIB_${_packagelib_idx}_PACKAGE="${_packagelib_value}" _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g;s#.*[[:space:]]##'`" export ${_packagelib_var_prefix}_PACKAGE_REQUIRE_LIB_${_packagelib_idx}_VERSION="${_packagelib_value}" ;; ""*) eval _packagelib_idx='$'"${_packagelib_var_prefix}_PACKAGE_REQUIRE_PACKAGE_N" _packagelib_idx=`/usr/bin/expr ${_packagelib_idx} + 1` export ${_packagelib_var_prefix}_PACKAGE_REQUIRE_PACKAGE_N="${_packagelib_idx}" _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g;s#[[:space:]].*##'`" export ${_packagelib_var_prefix}_PACKAGE_REQUIRE_PACKAGE_${_packagelib_idx}_PACKAGE="${_packagelib_value}" _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g;s#.*[[:space:]]##'`" export ${_packagelib_var_prefix}_PACKAGE_REQUIRE_PACKAGE_${_packagelib_idx}_VERSION="${_packagelib_value}" ;; "
"*) _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_SECTION="${_packagelib_value}" ;; ""*) _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_SHA1SUM="${_packagelib_value}" ;; ""*) _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_SHORT="${_packagelib_value}" ;; ""*) _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" export ${_packagelib_var_prefix}_PACKAGE_STATUS="${_packagelib_value}" ;; ""*) eval _packagelib_idx='$'"${_packagelib_var_prefix}_PACKAGE_SUB_PACKAGE_N" _packagelib_idx=`/usr/bin/expr ${_packagelib_idx} + 1` export ${_packagelib_var_prefix}_PACKAGE_SUB_PACKAGE_N="${_packagelib_idx}" _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g;s#[[:space:]].*##'`" export ${_packagelib_var_prefix}_PACKAGE_SUB_PACKAGE_${_packagelib_idx}_PACKAGE="${_packagelib_value}" _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g;s#.*[[:space:]]##'`" export ${_packagelib_var_prefix}_PACKAGE_SUB_PACKAGE_${_packagelib_idx}_PARAM="${_packagelib_value}" ;; ""*) _packagelib_value="`echo "${_packagelib_line}" | sed -e 's#[[:space:]]*[[:space:]]*##g'`" _packagelib_value=`normalize_version "${_packagelib_value}"` export ${_packagelib_var_prefix}_PACKAGE_VERSION="${_packagelib_value}" ;; *) ;; esac done < $_packagelib_infofile unset _packagelib_idx _packagelib_value _packagelib_infofile fi return 0 } # strip_extension # =============== # parameters: $1 name of variable # $2 name of extension # # output : modified variable strip_extension () { _packagelib_var_name="${1}" _packagelib_var_ext="$2" eval _packagelib_var_tmp="\$$_packagelib_var_name" echo "$_packagelib_var_tmp" | grep -q "$_packagelib_var_ext" if [ $? -eq 0 ] then eval $_packagelib_var_name=\"`echo "$_packagelib_var_tmp" | sed "s/${_packagelib_var_ext}.*//g"`\" fi } fi #============================================================================ # end #============================================================================