diff options
Diffstat (limited to 'sfeed_update_xargs')
-rwxr-xr-x | sfeed_update_xargs | 45 |
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(). | ||
6 | SFEED_UPDATE_INCLUDE="1" . sfeed_update | ||
7 | # load config file, sets $config. | ||
8 | loadconfig "$1" | ||
9 | |||
10 | # process a single feed. | ||
11 | # args are: config, tmpdir, name, feedurl, basesiteurl, encoding | ||
12 | if [ "${SFEED_UPDATE_CHILD}" = "1" ]; then | ||
13 | sfeedtmpdir="$2" | ||
14 | _feed "$3" "$4" "$5" "$6" | ||
15 | exit $? | ||
16 | fi | ||
17 | |||
18 | # ...else parent mode: | ||
19 | |||
20 | # feed(name, feedurl, basesiteurl, encoding) | ||
21 | feed() { | ||
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. | ||
33 | sfeedtmpdir="$(mktemp -d '/tmp/sfeed_XXXXXX')" | ||
34 | mkdir -p "${sfeedtmpdir}/feeds" | ||
35 | touch "${sfeedtmpdir}/ok" | ||
36 | # make sure path exists. | ||
37 | mkdir -p "${sfeedpath}" | ||
38 | # print feeds for parallel processing with xargs. | ||
39 | feeds | SFEED_UPDATE_CHILD="1" xargs -r -0 -P "${maxjobs}" -L 6 "$(readlink -f "$0")" | ||
40 | status=$? | ||
41 | # check error exit status indicator for parallel jobs. | ||
42 | test -f "${sfeedtmpdir}/ok" || status=1 | ||
43 | # cleanup temporary files etc. | ||
44 | cleanup | ||
45 | exit ${status} | ||