about summary refs log tree commit diff stats
path: root/sfeed_update_xargs
diff options
context:
space:
mode:
authorCase Duckworth2022-07-17 23:10:22 -0500
committerCase Duckworth2022-07-17 23:10:22 -0500
commit6aa64d77e0f8ef2e42bdb90bc5ed3f6557e3ed81 (patch)
treed54f6332408be6add8865714cb2bf1ef54160bdf /sfeed_update_xargs
downloadsfeed-6aa64d77e0f8ef2e42bdb90bc5ed3f6557e3ed81.tar.gz
sfeed-6aa64d77e0f8ef2e42bdb90bc5ed3f6557e3ed81.zip
Initial commit
Diffstat (limited to 'sfeed_update_xargs')
-rwxr-xr-xsfeed_update_xargs45
1 files changed, 45 insertions, 0 deletions
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 @@
1#!/bin/sh
2# -*- sh -*-
3# update feeds, merge with old feeds using xargs in parallel mode (non-POSIX).
4
5# include script and reuse its functions, but do not start main().
6SFEED_UPDATE_INCLUDE="1" . sfeed_update
7# load config file, sets $config.
8loadconfig "$1"
9
10# process a single feed.
11# args are: config, tmpdir, name, feedurl, basesiteurl, encoding
12if [ "${SFEED_UPDATE_CHILD}" = "1" ]; then
13 sfeedtmpdir="$2"
14 _feed "$3" "$4" "$5" "$6"
15 exit $?
16fi
17
18# ...else parent mode:
19
20# feed(name, feedurl, basesiteurl, encoding)
21feed() {
22 # workaround: *BSD xargs doesn't handle empty fields in the middle.
23 name="${1:-$$}"
24 feedurl="${2:-http://}"
25 basesiteurl="${3:-${feedurl}}"
26 encoding="$4"
27
28 printf '%s\0%s\0%s\0%s\0%s\0%s\0' "${config}" "${sfeedtmpdir}" \
29 "${name}" "${feedurl}" "${basesiteurl}" "${encoding}"
30}
31
32# fetch feeds and store in temporary directory.
33sfeedtmpdir="$(mktemp -d '/tmp/sfeed_XXXXXX')"
34mkdir -p "${sfeedtmpdir}/feeds"
35touch "${sfeedtmpdir}/ok"
36# make sure path exists.
37mkdir -p "${sfeedpath}"
38# print feeds for parallel processing with xargs.
39feeds | SFEED_UPDATE_CHILD="1" xargs -r -0 -P "${maxjobs}" -L 6 "$(readlink -f "$0")"
40status=$?
41# check error exit status indicator for parallel jobs.
42test -f "${sfeedtmpdir}/ok" || status=1
43# cleanup temporary files etc.
44cleanup
45exit ${status}