blob: f8ee8e7022f37f7ffc28613487137fc56c042059 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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}
|