From 6997a76599d4aa338e9633db8f7cafc05083df63 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 02 Aug 2012 10:00:02 -0400 Subject: Fix problems is control parsing and generation. --- (limited to 'lib') diff --git a/lib/control.sh b/lib/control.sh index 6fa8931..821010b 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -92,25 +92,27 @@ _control_parse() { _control="${1}" _type="${2}" - _req=" $(eval echo \$\{OH_CONTROL_"${_type}"_FIELDS_REQUIRED) " - _opt=" $(eval echo \$\{OH_CONTROL_"${_type}"_FIELDS_OPTIONAL) " + _req=" $(eval echo \$\{OH_CONTROL_"${_type}"_FIELDS_REQUIRED\}) " + _opt=" $(eval echo \$\{OH_CONTROL_"${_type}"_FIELDS_OPTIONAL\}) " _all="${_req}${_opt}" _got=' ' # Initialize fields. - for _param in ${_all}; do + for _name in ${_all}; do + _param="OH_CONTROL_${_type}_FIELD_$(echo "${_name}" | \ + LC_CTYPE=C tr '[:lower:]-' '[:upper:]_')" eval "${_param}=" done _param= _line_nr=0 - while read -r _line; do + while IFS= read -r _line; do _line_nr=$(($_line_nr + 1)) if [ "${_line# }" = "${_line}" ]; then # "Name: Value" line. _name="${_line%%:*}" - _value="${_line#*:}" + _value="${_line#*: }" if [ -z "${_name}" -o "${_name}" = "${_line}" \ -o -z "${_value}" ]; then # Badly formatted control field. @@ -118,11 +120,11 @@ _control_parse() "${oh_str_control_bad_nv}" continue fi - if [ "${_all% ${_name} }" = "${_all}" ]; then + if [ "${_all% ${_name} *}" = "${_all}" ]; then # Unknown field. _control_parse_error "${_control}" "${_line_nr}" \ "${oh_str_control_unknown_field}" \ - "${_control}" "${_name}" + "${_name}" else # Remove field from list of required fields. _req="$(echo "${_req}" | sed "s/${_name}//")" @@ -131,13 +133,15 @@ _control_parse() # Duplicate field. _control_parse_error "${_control}" "${_line_nr}" \ "${oh_str_control_duplicate_field}" \ - "${_control}" "${_field}" + "${_field}" else _got="${_got}${_field} " fi _param="OH_CONTROL_${_type}_FIELD_$(echo "${_name}" | \ LC_CTYPE=C tr '[:lower:]-' '[:upper:]_')" - eval "${_param}=\"${_value}\"" + # Escape the value. + _value="$(echo "${_value}" | sed "s/'/'\\\\''/g")" + eval "${_param}='${_value}'" else # Continuation line. if [ -z "${_param}" ]; then @@ -147,8 +151,9 @@ _control_parse() continue fi _value="${_line# }" - eval "${_param}=\"${_param} -${_value}\"" + _value="$(echo "${_value}" | sed "s/'/'\\\\''/g")" + eval "${_param}='${_param} +${_value}'" fi done <"${_control}" @@ -170,7 +175,7 @@ _control_parse_error() shift 3 if [ "${_line_nr}" -eq 0 ]; then - _file_info=$(printf '%20s:' "${_file}" "${_line_nr}") + _file_info=$(printf '%20s:' "${_file}") else _file_info=$(printf '%20s(l%d):' "${_file}" "${_line_nr}") fi @@ -181,7 +186,7 @@ _control_gen() { _type="${1}" _control="${2}" - _data="${2}" + _data="${3}" # TODO: Handle platforms and architectures like "any" and "any-linux-any". @@ -210,7 +215,9 @@ _control_gen() # pkg_size_kbs = (pkg->installed_size + 1023)/1024; # TODO: Further investigate opkg's disk space calculation and, if necessary, # patch opkg and submit a bug report. - _inst_size=$((($inst_size + 1023) / 1024)) + _inst_size=$((($_inst_size + 1023) / 1024)) + + mkdir -p "${_control%/*}" cat >"${_control}" <"${_control}" + printf '%s: %s\n' "${_name}" "${_value}" >>"${_control}" fi done - cat >"${_control}" <>"${_control}" <"${_control}" + >>"${_control}" fi } -- cgit v0.9.1