# ProteanOS Development Kit # lib/feed.sh # Functions for handling feed index files # # Copyright (C) 2013 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 3 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${_FEED_SM+set}" = 'xset' ] && return 0 _FEED_SM=1 use fd use control feed_pkg_cb= feed_dep_fields= feed_pkgs= feed_deps_fd= feed_fnames_fd= feed_pkg_include= feed_pkg= feed_deps= feed_download() { local feed_index="${1}" wget -O - "${feed_index}" return 0 } # TODO: Write to a filenames file. feed_find_pkgs() { local pkg_cb="${1}" local dep_fields="${2}" local deps_file="${3}" local fnames_file="${4}" feed_pkg_cb="${pkg_cb}" feed_dep_fields=" $(printf '%s ' ${dep_fields})" feed_pkgs='' fopen "${deps_file}" 'a' feed_deps_fd=${FD} fopen "${fnames_file}" 'a' feed_fnames_fd=${FD} feed_pkg_include='false' feed_pkg='' feed_deps='' parse_control '-' feed_field_cb feed_para_cb 'Package' fclose ${feed_deps_fd} printf '%s\n' "${feed_pkgs# }" return 0 } feed_field_cb() { local name="${1}" local value="${2}" if [ "x${name}" = 'xPackage' ]; then feed_pkg="${value}" elif [ "x${name}" = 'xFilename' ]; then printf '%s %s\n' "${feed_pkg}" "${value}" >&${feed_fnames_fd} 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="${dep##[ ${HT}${LF}]}" dep="${dep%%[ ${HT}${LF}]}" new_deps="${new_deps} ${dep}" done unset IFS printf '%s%s\n' "${feed_pkg}" "${new_deps}" >&${feed_deps_fd} feed_pkg_include='false' feed_pkg='' feed_deps='' return 0 }