From 6aa64d77e0f8ef2e42bdb90bc5ed3f6557e3ed81 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 17 Jul 2022 23:10:22 -0500 Subject: Initial commit --- sfeed_update_xargs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 sfeed_update_xargs (limited to 'sfeed_update_xargs') diff --git a/sfeed_update_xargs b/sfeed_update_xargs new file mode 100755 index 0000000..f8ee8e7 --- /dev/null +++ b/sfeed_update_xargs @@ -0,0 +1,45 @@ +#!/bin/sh +# -*- sh -*- +# update feeds, merge with old feeds using xargs in parallel mode (non-POSIX). + +# include script and reuse its functions, but do not start main(). +SFEED_UPDATE_INCLUDE="1" . sfeed_update +# load config file, sets $config. +loadconfig "$1" + +# process a single feed. +# args are: config, tmpdir, name, feedurl, basesiteurl, encoding +if [ "${SFEED_UPDATE_CHILD}" = "1" ]; then + sfeedtmpdir="$2" + _feed "$3" "$4" "$5" "$6" + exit $? +fi + +# ...else parent mode: + +# feed(name, feedurl, basesiteurl, encoding) +feed() { + # workaround: *BSD xargs doesn't handle empty fields in the middle. + name="${1:-$$}" + feedurl="${2:-http://}" + basesiteurl="${3:-${feedurl}}" + encoding="$4" + + printf '%s\0%s\0%s\0%s\0%s\0%s\0' "${config}" "${sfeedtmpdir}" \ + "${name}" "${feedurl}" "${basesiteurl}" "${encoding}" +} + +# fetch feeds and store in temporary directory. +sfeedtmpdir="$(mktemp -d '/tmp/sfeed_XXXXXX')" +mkdir -p "${sfeedtmpdir}/feeds" +touch "${sfeedtmpdir}/ok" +# make sure path exists. +mkdir -p "${sfeedpath}" +# print feeds for parallel processing with xargs. +feeds | SFEED_UPDATE_CHILD="1" xargs -r -0 -P "${maxjobs}" -L 6 "$(readlink -f "$0")" +status=$? +# check error exit status indicator for parallel jobs. +test -f "${sfeedtmpdir}/ok" || status=1 +# cleanup temporary files etc. +cleanup +exit ${status} -- cgit 1.4.1-21-gabe81