#!/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 ## TODO: further processing for feed metadata # ${sfeedtmpdir}/feeds/* # cleanup temporary files etc. cleanup exit ${status}