sfeed_update_xargs - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
sfeed_update_xargs (1120B)
---
1 #!/bin/sh
2 # update feeds, merge with old feeds using xargs in parallel mode (non-POSIX).
3
4 # include script and reuse its functions, but do not start main().
5 SFEED_UPDATE_INCLUDE="1" . sfeed_update
6 # load config file, sets $config.
7 loadconfig "$1"
8
9 # process a single feed.
10 # args are: config, tmpdir, name, feedurl, basesiteurl, encoding
11 if [ "${SFEED_UPDATE_CHILD}" = "1" ]; then
12 sfeedtmpdir="$2"
13 _feed "$3" "$4" "$5" "$6"
14 exit $?
15 fi
16
17 # ...else parent mode:
18
19 # feed(name, feedurl, basesiteurl, encoding)
20 feed() {
21 # workaround: *BSD xargs doesn't handle empty fields in the middle.
22 name="${1:-$$}"
23 feedurl="${2:-http://}"
24 basesiteurl="${3:-${feedurl}}"
25 encoding="$4"
26
27 printf '%s\0%s\0%s\0%s\0%s\0%s\0' "${config}" "${sfeedtmpdir}" \
28 "${name}" "${feedurl}" "${basesiteurl}" "${encoding}"
29 }
30
31 # fetch feeds and store in temporary directory.
32 sfeedtmpdir="$(mktemp -d '/tmp/sfeed_XXXXXX')"
33 # make sure path exists.
34 mkdir -p "${sfeedpath}"
35 # print feeds for parallel processing with xargs.
36 feeds | SFEED_UPDATE_CHILD="1" xargs -r -0 -P "${maxjobs}" -L 6 "$(readlink -f "$0")"
37 # cleanup temporary files etc.
38 cleanup