summaryrefslogtreecommitdiffstats
path: root/src/feed.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/feed.sh')
-rw-r--r--src/feed.sh137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/feed.sh b/src/feed.sh
new file mode 100644
index 0000000..4288c2a
--- /dev/null
+++ b/src/feed.sh
@@ -0,0 +1,137 @@
+# Functions for handling feed index files
+#
+# Copyright (C) 2013, 2014 Patrick "P. J." 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
+# <http://www.gnu.org/licenses/>.
+
+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 feed_index="${1}"
+ local use_gzip="${2}"
+ local gzip=
+
+ if ${use_gzip}; then
+ gzip=gunzip
+ else
+ gzip=cat
+ fi
+
+ wget -q -O - "${feed_index}" | ${gzip}
+
+ 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}"
+
+ 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_idx}" feed_field_cb feed_para_cb 'Package'
+
+ printf '%s\n' "${feed_pkgs# }"
+
+ return 0
+}
+
+feed_field_cb()
+{
+ local name="${1}"
+ local value="${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
+}