# Functions for handling feed index files # # Copyright (C) 2013, 2014 Patrick McDermott # # This file is part of the ProteanOS Development Kit. # # The ProteanOS Development Kit 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 3 of the # License, or (at your option) any later version. # # The ProteanOS Development Kit 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 the ProteanOS Development Kit. If not, see # . _feed_dep_fields= _feed_pkg_cb= _feed_deps_cb= _feed_fname_cb= _feed_md5sum_cb= _feed_sha256sum_cb= _feed_pkgs= _feed_pkg_include= _feed_pkg= _feed_deps= feed_download() { local base_url="${1}" local list_file="${2}" local use_gzip="${3}" local root="${4}" shift 4 local url= local gunzip= if ${use_gzip}; then url="${base_url}/Packages.gz" case "${list_file}" in *.gz) gunzip='cat';; *) gunzip="${GUNZIP}";; esac else url="${base_url}/Packages" fi if ! ${WGET} -q -O "${list_file}.tmp" -- "${url}"; then return 1 fi if ! ${gunzip} <"${list_file}.tmp" >"${list_file}"; then rm -f -- "${list_file}.tmp" return 1 fi rm -f -- "${list_file}.tmp" return 0 } feed_download_cert() { local base_url="${1}" local list_file="${2}" local use_gzip="${3}" local root="${4}" shift 4 local url= local usign= local opkg_cert= if ${use_gzip}; then url="${base_url}/Packages.gz" # Don't bother with gunzip, because only opkg-lede after storing # compressed package lists (commit cd113c7) supports signature # checking with usign (commit 71f02a3). else url="${base_url}/Packages" fi if ! ${WGET} -q -O "${list_file}.tmp" -- "${url}"; then return 1 fi if ! ${WGET} -q -O "${list_file}.sig" -- "${base_url}/Packages.sig" then rm -f -- "${list_file}.tmp" return 1 fi if ${in_place} && ${USIGN_EMBEDDED}; then usign="${builddir}/3rdparty/usign/usign" else usign="${USIGN}" fi if ${in_place}; then opkg_cert="${builddir}/opkg-cert" else opkg_cert="${OPKG_CERT}" fi if ! ROOT="${root}" TMPDIR="${root}" USIGN="${usign}" \ WGET="${WGET}" GUNZIP="${GUNZIP}" "${opkg_cert}" \ verify "${list_file}.sig" "${list_file}.tmp"; then rm -f -- "${list_file}.tmp" "${list_file}.sig" return 1 fi mv -- "${list_file}.tmp" "${list_file}" return 0 } _feed_field_cb() { local name="${1}" local value="${2}" shift 2 name="$(printf '%s\n' "${name}" | tr 'A-Z' 'a-z')" if [ "x${name}" = 'xpackage' ]; then _feed_pkg="${value}" elif [ "x${name}" = 'xfilename' ]; then ${_feed_fname_cb} "${_feed_pkg}" "${value}" elif [ "x${name}" = 'xmd5sum' ]; then ${_feed_md5sum_cb} "${_feed_pkg}" "${value}" elif [ "x${name}" = 'xsha256sum' ]; then ${_feed_sha256sum_cb} "${_feed_pkg}" "${value}" elif [ "x${_feed_dep_fields#* ${name} }" != "x${_feed_dep_fields}" ] then _feed_deps="${_feed_deps}${value}, " fi if ${_feed_pkg_cb} ${name} ${value}; then _feed_pkg_include='true' fi return 0 } _feed_para_cb() { local new_deps= local dep= if ${_feed_pkg_include}; then _feed_pkgs="${_feed_pkgs} ${_feed_pkg}" fi new_deps='' IFS=',' for dep in ${_feed_deps%, }; do unset IFS # Trim off versions and disjunctions. dep="${dep%%(*}" dep="${dep%%|*}" # Trim whitespace. dep="$(printf '%s\n' "${dep}" | sed 's/^ *//; s/ *$//')" # In practice, this would suffice for control files generated by # opkbuild: # dep="${dep#[ ${HT}${LF}]}" # dep="${dep%[ ${HT}${LF}]}" new_deps="${new_deps} ${dep}" done unset IFS ${_feed_deps_cb} "${_feed_pkg}" "${new_deps# }" _feed_pkg_include='false' _feed_pkg='' _feed_deps='' return 0 } feed_find_pkgs() { local feed_idx="${1}" local dep_fields="${2}" local pkg_cb="${3}" local deps_cb="${4}" local fname_cb="${5}" local md5sum_cb="${6}" local sha256sum_cb="${7}" shift 7 _feed_dep_fields=" $(printf '%s ' ${dep_fields} | tr 'A-Z' 'a-z')" _feed_pkg_cb="${pkg_cb}" _feed_deps_cb="${deps_cb}" _feed_fname_cb="${fname_cb}" _feed_md5sum_cb="${md5sum_cb}" _feed_sha256sum_cb="${sha256sum_cb}" _feed_pkgs='' _feed_pkg_include='false' _feed_pkg='' _feed_deps='' parse_control '-' _feed_field_cb _feed_para_cb 'Package' <<-EOF $({ ${GUNZIP} -c -- "${feed_idx}" || cat "${feed_idx}"; } \ 2>/dev/null) EOF printf '%s\n' "${_feed_pkgs# }" return 0 }