# opkbuild # lib/metadata.sh # Functions for parsing and validating package metadata. # # Copyright (C) 2012 Patrick "P. J." McDermott # # 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. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . [ x"${_OB_METADATA_SM+set}" = x'set' ] && return 0 _OB_METADATA_SM=1 ob_use 'metadata/@@METADATA@@' ob_validate_source_name() { local name= if [ ${#} -eq 1 ]; then name="${1}" else return 125 fi _ob_metadata_do 'validate_source_name' "${name}" return ${?} } ob_validate_binary_name() { local name= if [ ${#} -eq 1 ]; then name="${1}" else return 125 fi _ob_metadata_do 'validate_binary_name' "${name}" return ${?} } ob_parse_version() { local opt= local upstreamver_var= local distrev_var= local version= while getopts 'u:d:' opt; do case "${opt}" in u) upstreamver_var="${OPTARG}" if ! _ob_validate_var_name "${upstreamver_var}"; then return 125 fi ;; d) distrev_var="${OPTARG}" if ! _ob_validate_var_name "${distrev_var}"; then return 125 fi ;; ?) return 125 ;; esac done shift $(($OPTIND - 1)) if [ ${#} -eq 1 ]; then version="${1}" else return 125 fi if ! _ob_metadata_do 'validate_version' "${version}"; then return 1 fi if [ -n "${upstreamver_var}" ]; then eval ${upstreamver_var}="$(_ob_metadata_do 'get_upstreamver' \ "${version}")" fi if [ -n "${distrev_var}" ]; then eval ${distrev_var}="$(_ob_metadata_do 'get_distrev' \ "${version}")" fi return 0 } ob_get_system_arch() { if [ ${#} -gt 0 ]; then return 125 fi _ob_metadata_do 'get_system_arch' return ${?} } ob_get_system_plat() { if [ ${#} -gt 0 ]; then return 125 fi _ob_metadata_do 'get_system_plat' return ${?} } ob_match_arch() { local arch= local arch_field= local a= local a_ere= if [ ${#} -eq 2 ]; then arch="${1}" arch_field="${2}" else return 125 fi for a in ${arch_field}; do # "all" == "all" if [ "${arch}" = 'all' ]; then if [ "${a}" = 'all' ]; then return 0 else continue fi fi # "foo-bar-baz" == "any" if [ "${a}" = 'any' ]; then return 0 fi # Generate an ERE to match hyphenated architectures. a_ere="$(echo "${a}" | \ sed 's/^any-/[^-]+-/;s/-any-/-[^-]+-/g;s/-any$/-[^-]+/g')" # "foo-bar-baz" == "foo-any-any" if echo "${arch}" | grep -E "${a_ere}" >/dev/null 2>&1; then return 0 fi done # Nothing matched. return 1 } ob_match_plat() { local plat= local plat_field= local p= if [ ${#} -eq 2 ]; then plat="${1}" plat_field="${2}" else return 125 fi for p in ${plat_field}; do if [ "${plat}" = 'all' ]; then if [ "${p}" = 'all' ]; then return 0 else continue fi fi if [ "${p}" = 'any' ]; then return 0 fi done return 1 } ob_arch_is_concerned() { local host_arch= local arches= local arch= local not_arch= local seen_arch= if [ ${#} -eq 2 ]; then host_arch="${1}" arches="${2}" else return 125 fi seen_arch=1 if [ -z "${arches}" ]; then seen_arch=0 fi for arch in ${arches}; do not_arch="${arch#!}" if [ "${not_arch}" != "${arch}" ]; then if ob_match_arch "${host_arch}" "${not_arch}"; then seen_arch=1 break else seen_arch=0 fi elif ob_match_arch "${host_arch}" "${arch}"; then seen_arch=0 break fi done return ${seen_arch} } ob_plat_is_concerned() { local host_plat= local plats= local plat= local not_plat= local seen_plat= if [ ${#} -eq 2 ]; then host_plat="${1}" plats="${2}" else return 125 fi seen_plat=1 if [ -z "${plats}" ]; then seen_plat=0 fi for plat in ${plats}; do not_plat="${plat#!}" if [ "${not_plat}" != "${plat}" ]; then if ob_match_plat "${host_plat}" "${not_plat}"; then seen_plat=1 break else seen_plat=0 fi elif ob_match_plat "${host_plat}" "${plat}"; then seen_plat=0 break fi done return ${seen_plat} } ob_get_system_path() { local path_id= if [ ${#} -ge 1 ]; then path_id="${1}" shift 1 else return 125 fi _ob_metadata_do 'get_system_path' "${path_id}" "${@}" return ${?} } _ob_metadata_do() { local func= func="${1}" shift 1 "_ob_${func}_@@METADATA@@" "${@}" return ${?} }