2017-04-15 16:24:28 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -x
|
|
|
|
set -e
|
2017-08-11 12:57:30 +02:00
|
|
|
#TODO: make this more robust
|
|
|
|
export RANDRSS_ROOT=$(pwd)
|
2017-04-15 16:33:48 +02:00
|
|
|
random_default=$( shuf -n 1 -i720-753)
|
2017-04-15 16:24:28 +02:00
|
|
|
DEFAULT_PER_ITEM="1-$random_default"
|
|
|
|
|
|
|
|
echo "Current default sleep seconds range: $DEFAULT_PER_ITEM"
|
|
|
|
if [ $# -lt 1 ] ; then
|
2017-08-11 13:14:39 +02:00
|
|
|
echo "Usage: $0 feedsconfigdir fetchersfile [syncnow]"
|
2017-04-15 16:24:28 +02:00
|
|
|
exit
|
|
|
|
fi
|
2017-08-11 13:14:39 +02:00
|
|
|
feedsconfigdir="$1"
|
2017-08-11 12:57:30 +02:00
|
|
|
fetchersfile="$2"
|
2017-08-11 13:14:39 +02:00
|
|
|
if [ ! -d "$feedsconfigdir" ] ; then
|
|
|
|
echo "$feedsconfigdir does not exist or is not readable" 1>&2
|
2017-06-21 12:23:53 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-08-11 12:57:30 +02:00
|
|
|
if [ ! -f "$fetchersfile" ] ; then
|
|
|
|
echo "fetchersfile does not exist or is not readable" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-06-21 12:23:53 +02:00
|
|
|
syncnow=0
|
|
|
|
if [ "$3" = "syncnow" ] ; then
|
|
|
|
syncnow=1
|
2017-04-15 16:24:28 +02:00
|
|
|
fi
|
|
|
|
while true ; do
|
2017-08-11 13:42:29 +02:00
|
|
|
ls "$feedsconfigdir" | shuf | while read line ; do
|
2017-08-11 13:14:39 +02:00
|
|
|
source "$feedsconfigdir/$line"
|
|
|
|
|
2017-04-15 16:24:28 +02:00
|
|
|
sleepfor=0
|
2017-08-11 13:14:39 +02:00
|
|
|
if [ -n "$FEED_RANGE" ] ; then
|
2017-04-15 16:24:28 +02:00
|
|
|
sleepfor=$( shuf -i "$range" -n 1)
|
|
|
|
else
|
|
|
|
sleepfor=$( shuf -i "$DEFAULT_PER_ITEM" -n 1)
|
|
|
|
fi
|
2017-08-11 13:14:39 +02:00
|
|
|
|
|
|
|
fetcher="$FEED_FETCHER"
|
2017-08-11 16:42:37 +02:00
|
|
|
if [ -z "$fetcher" ] ; then
|
2017-08-11 13:14:39 +02:00
|
|
|
fetcher=$( shuf -n 1 "$fetchersfile" )
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e "$fetcher" ] ; then
|
|
|
|
echo "$fetcher does not exist" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-08-11 16:42:37 +02:00
|
|
|
proxycommand="$FEED_PROXYCOMMAND"
|
|
|
|
if [ -z "$proxycommand" ] ; then
|
|
|
|
proxycommand="torsocks"
|
|
|
|
fi
|
2017-08-11 12:57:30 +02:00
|
|
|
|
|
|
|
[ $syncnow -eq 1 ] || ( echo "Sleeping for $sleepfor seconds for $url, chosen fetcher $fetcher" && sleep "$sleepfor" )
|
2017-08-11 13:14:39 +02:00
|
|
|
echo "Fetching $FEED_URL with $fetcher"
|
2017-08-11 16:42:37 +02:00
|
|
|
"$proxycommand" "$fetcher" "$FEED_URL" "$FEED_OUTPUT" || echo "Failed to fetch $FEED_URL"
|
2017-04-15 16:24:28 +02:00
|
|
|
done
|
2017-06-21 12:23:53 +02:00
|
|
|
[ $syncnow -eq 1 ] && exit
|
2017-04-15 16:24:28 +02:00
|
|
|
done
|