randrss/randrss

62 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
set -x
set -e
#TODO: make this more robust
export RANDRSS_ROOT=$(pwd)
random_default=$( shuf -n 1 -i720-753)
DEFAULT_PER_ITEM="1-$random_default"
echo "Current default sleep seconds range: $DEFAULT_PER_ITEM"
if [ $# -lt 1 ] ; then
echo "Usage: $0 feedsconfigdir fetchersfile [syncnow]"
exit
fi
feedsconfigdir="$1"
fetchersfile="$2"
if [ ! -d "$feedsconfigdir" ] ; then
echo "$feedsconfigdir does not exist or is not readable" 1>&2
exit 1
fi
if [ ! -f "$fetchersfile" ] ; then
echo "fetchersfile does not exist or is not readable" 1>&2
exit 1
fi
syncnow=0
if [ "$3" = "syncnow" ] ; then
syncnow=1
fi
while true ; do
ls "$feedsconfigdir" | shuf | while read line ; do
source "$feedsconfigdir/$line"
sleepfor=0
if [ -n "$FEED_RANGE" ] ; then
sleepfor=$( shuf -i "$range" -n 1)
else
sleepfor=$( shuf -i "$DEFAULT_PER_ITEM" -n 1)
fi
fetcher="$FEED_FETCHER"
if [ -z "$fetcher" ] ; then
fetcher=$( shuf -n 1 "$fetchersfile" )
fi
if [ ! -e "$fetcher" ] ; then
echo "$fetcher does not exist" 1>&2
exit 1
fi
proxycommand="$FEED_PROXYCOMMAND"
if [ -z "$proxycommand" ] ; then
proxycommand="torsocks"
fi
[ $syncnow -eq 1 ] || ( echo "Sleeping for $sleepfor seconds for $url, chosen fetcher $fetcher" && sleep "$sleepfor" )
echo "Fetching $FEED_URL with $fetcher"
"$proxycommand" "$fetcher" "$FEED_URL" "$FEED_OUTPUT" || echo "Failed to fetch $FEED_URL"
done
[ $syncnow -eq 1 ] && exit
done