Modernizing WolfPack to use systemd.timer and systemd-cat
This commit is contained in:
85
wolfpack
85
wolfpack
@@ -1,15 +1,10 @@
|
||||
#!/bin/bash
|
||||
source /usr/local/src/SharedLibraries/Bash/header
|
||||
source /opt/aninix/Uniglot/Bash/header
|
||||
export downloadtorrent="sudo -u deluge deluge-console 2>/dev/null add"
|
||||
|
||||
if [ -z "$3" ]; then
|
||||
configuretorrent /usr/local/etc/WolfPack/torrentengine
|
||||
else
|
||||
configuretorrent "$3"
|
||||
fi
|
||||
export IFS="
|
||||
"
|
||||
export logfile='/var/log/wolfpack.log'
|
||||
export servicename='wolfpack'
|
||||
|
||||
function helptext {
|
||||
echo '
|
||||
@@ -30,8 +25,6 @@ wolfpack --torrent-monitor ~~ Pull up the Deluge console
|
||||
for torrents.
|
||||
wolfpack --torrent-lookup ~~ Look up and add a torrent
|
||||
if user confirms.
|
||||
wolfpack --reset-log ~~ Clear the wolfpack log. This
|
||||
is in /var/log/wolfpack.log.
|
||||
wolfpack --help ~~ Show this helptext
|
||||
|
||||
Available pup types (all pups are line-delimited with the type and
|
||||
@@ -57,7 +50,7 @@ search ~~ Uses the Google search
|
||||
function privacycheck {
|
||||
ip="$(/usr/local/bin/whatismyip)"
|
||||
if [ -z "$ip" ] || [ "$ip" == "$(nslookup aninix.net | grep Address | cut -f 2 -d ' ' | tail -n 1)" ]; then
|
||||
echo "ERROR: Should not torrent directly from the AniNIX main IP for privacy reasons" 2>&1 | tee -a "$logfile"
|
||||
echo "ERROR: Should not torrent directly from the AniNIX main IP for privacy reasons" 2>&1 | systemd-cat -t "$servicename"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -67,15 +60,25 @@ function nextairdate {
|
||||
echo "Need a show to search for"
|
||||
exit 1;
|
||||
fi
|
||||
lynx -read_timeout=5 -connect_timeout=5 --dump "https://www.episodate.com/tv-show/$(echo $1 | tr '[:upper:]' '[:lower:]' | tr ' ' '-')?season=99" 2>&1 | grep 'and airs on' | sed 's# Season [0-9]\+ / Episode [0-9]\+ and airs on ##'
|
||||
timeout 5 elinks --dump "https://www.episodate.com/tv-show/$(echo $1 | tr '[:upper:]' '[:lower:]' | tr ' ' '-')?season=99" 2>&1 | grep 'and airs on' | sed 's# Season [0-9]\+ / Episode [0-9]\+ and airs on ##'
|
||||
return
|
||||
}
|
||||
|
||||
function torrentConfigure {
|
||||
if [ -z "$3" ]; then
|
||||
configuretorrent /usr/local/etc/WolfPack/torrentengine
|
||||
else
|
||||
configuretorrent "$3"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function torrent {
|
||||
if [ "$1" == "" ] || [ $(wc -l "$1" | cut -f 1 -d ' ') -lt 3 ]; then
|
||||
echo "Need a valid argument."
|
||||
return;
|
||||
fi
|
||||
torrentConfigure
|
||||
privacycheck;
|
||||
export downloaddir=$(head -n 2 "$1" | tail -n 1)
|
||||
sudo -u deluge deluge-console config -s autoadd_location "$downloaddir" 2>/dev/null
|
||||
@@ -85,11 +88,11 @@ function torrent {
|
||||
if [ "$magnetlink" != "" ]; then
|
||||
/bin/bash -c "$downloadtorrent $magnetlink"
|
||||
sed -i "/$i/d" "$1"
|
||||
echo $magnetlink | tee -a "$logfile"
|
||||
echo Added magnet to deluged and removed $i | tee -a "$logfile"
|
||||
echo $magnetlink | systemd-cat -t "$servicename"
|
||||
echo Added magnet to deluged and removed $i | systemd-cat -t "$servicename"
|
||||
fi
|
||||
done
|
||||
if [ -x `which clamscan` ]; then clamscan -r -i "$downloaddir" | tee -a "$logfile"; fi
|
||||
if [ -x `which clamscan` ]; then clamscan -r -i "$downloaddir" | systemd-cat -t "$servicename"; fi
|
||||
}
|
||||
|
||||
function shows {
|
||||
@@ -116,12 +119,12 @@ function shows {
|
||||
fi
|
||||
if [ "$magnetlink" != "" ]; then
|
||||
# We found an episode.
|
||||
echo $i | tee -a "$logfile"
|
||||
echo $magnetlink | tee -a "$logfile"
|
||||
echo $i | systemd-cat -t "$servicename"
|
||||
echo $magnetlink | systemd-cat -t "$servicename"
|
||||
/bin/bash -c "$downloadtorrent $magnetlink"
|
||||
sed -i "s/$i/S${season}E${newep}#${showName}#${modifier}/" "$1"
|
||||
echo Downloaded and pup updated. | tee -a "$logfile"
|
||||
echo | tee -a "$logfile"
|
||||
echo Downloaded and pup updated. | systemd-cat -t "$servicename"
|
||||
echo | systemd-cat -t "$servicename"
|
||||
else
|
||||
# We didn't -- is there a new season?
|
||||
if [ -z "$modifier" ]; then
|
||||
@@ -130,24 +133,24 @@ function shows {
|
||||
getmagnetlink "$showName S${newseason}E01 $modifier"
|
||||
fi
|
||||
if [ "$magnetlink" != "" ]; then
|
||||
echo "S${newseason}E01" $showName | tee -a "$logfile"
|
||||
echo "$magnetlink" | tee -a "$logfile"
|
||||
echo "S${newseason}E01" $showName | systemd-cat -t "$servicename"
|
||||
echo "$magnetlink" | systemd-cat -t "$servicename"
|
||||
/bin/bash -c "$downloadtorrent $magnetlink"
|
||||
sed -i "s/$i/S${newseason}E02#$showName#$modifier/" "$1"
|
||||
else
|
||||
nextAirDate="$(nextairdate "$showName")"
|
||||
if [ ! -z "$nextAirDate" ]; then
|
||||
echo "No new season found for $showName -- next airs $(nextairdate "$showName")" | tee -a "$logfile"
|
||||
echo "No new season found for $showName -- next airs $(nextairdate "$showName")" | systemd-cat -t "$servicename"
|
||||
if [ "$(date -d "$nextAirDate" -u +%s)" -lt "$(date -u +%s)" ]; then
|
||||
echo ERROR: Should have found a new episode for $searchterms and did not -- check your provider\! | tee -a "$logfile"
|
||||
echo ERROR: Should have found a new episode for $searchterms and did not -- check your provider\! | systemd-cat -t "$servicename"
|
||||
fi
|
||||
else
|
||||
echo "No new season found for $showName" | tee -a "$logfile"
|
||||
echo "No new season found for $showName" | systemd-cat -t "$servicename"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [ -x `which clamscan` ]; then clamscan -r -i "$downloaddir" | tee -a "$logfile"; fi
|
||||
if [ -x `which clamscan` ]; then clamscan -r -i "$downloaddir" | systemd-cat -t "$servicename"; fi
|
||||
}
|
||||
|
||||
function download {
|
||||
@@ -170,15 +173,15 @@ function download {
|
||||
export filename="$downloaddir"/"$(echo "$nexturl" | rev | cut -f 1 -d \/ | rev)"
|
||||
#if file doesn't already exist....
|
||||
if [ ! -f "$filename" ]; then
|
||||
echo Downloading $nexturl to $filename ... | tee -a "$logfile"
|
||||
echo Downloading $nexturl to $filename ... | systemd-cat -t "$servicename"
|
||||
for i in $(find "$downloaddir" -type f | grep -i "$dedupterm"); do
|
||||
echo Deduped\! Removed $i from $downloaddir | tee -a "$logfile"
|
||||
rm -f "$i" 2>&1 | tee -a "$logfile"
|
||||
echo Deduped\! Removed $i from $downloaddir | systemd-cat -t "$servicename"
|
||||
rm -f "$i" 2>&1 | systemd-cat -t "$servicename"
|
||||
done
|
||||
wget --timeout=5 -q -O "$filename" "$nexturl"
|
||||
echo Downloaded | tee -a "$logfile"
|
||||
echo Downloaded | systemd-cat -t "$servicename"
|
||||
fi
|
||||
if [ -x `which clamscan` ]; then clamscan -r -i "$downloaddir" | tee -a "$logfile"; fi
|
||||
if [ -x `which clamscan` ]; then clamscan -r -i "$downloaddir" | systemd-cat -t "$servicename"; fi
|
||||
}
|
||||
|
||||
function search {
|
||||
@@ -191,7 +194,7 @@ function search {
|
||||
export searchstring=$(echo $i | sed 's/ /+/g')
|
||||
export file="$downloaddir"/$searchstring'.txt'
|
||||
echo | googler --count=5 -C -x "$searchstring" | grep -v 'Enter n, p, result' > "$file"
|
||||
echo "Ran search for $searchstring to $file" | tee -a "$logfile"
|
||||
echo "Ran search for $searchstring to $file" | systemd-cat -t "$servicename"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -200,25 +203,25 @@ if [ "$1" == "" ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo '---' $(date) '---' | tee -a "$logfile"
|
||||
echo '---' $(date) '---' | systemd-cat -t "$servicename"
|
||||
|
||||
case "$1" in
|
||||
"--alpha")
|
||||
echo Started alpha on `uname -n` | tee -a "$logfile"
|
||||
echo Started alpha on `uname -n` | systemd-cat -t "$servicename"
|
||||
if [ "$2" == "" ]; then
|
||||
export basedir="/usr/local/etc/WolfPack"
|
||||
else
|
||||
export basedir="$2";
|
||||
fi
|
||||
echo "Starting members from pup in "$basedir | tee -a "$logfile"
|
||||
echo "Starting members from pup in "$basedir | systemd-cat -t "$servicename"
|
||||
for i in $(find "$basedir" -type f | grep '.pup'); do
|
||||
/usr/local/bin/wolfpack --member "$i" "$3";
|
||||
done
|
||||
;;
|
||||
|
||||
"--member")
|
||||
echo "Spawning a $(head -n 1 "$2") member for $2 on `uname -n`" | tee -a "$logfile"
|
||||
(printf "IP: "; /usr/local/bin/whatismyip) | tee -a /var/log/wolfpack.log
|
||||
echo "Spawning a $(head -n 1 "$2") member for $2 on `uname -n`" | systemd-cat -t "$servicename"
|
||||
(printf "IP: "; /usr/local/bin/whatismyip) | systemd-cat -t "$servicename"
|
||||
case "$(head -n 1 "$2")" in
|
||||
"shows")
|
||||
shows "$2"
|
||||
@@ -237,16 +240,12 @@ case "$1" in
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
"--reset-log")
|
||||
cat /dev/null > "$logfile"
|
||||
exit 0;
|
||||
;;
|
||||
"--torrent-monitor")
|
||||
exec sudo -u deluge deluge-console 2>/dev/null;
|
||||
exit 0;
|
||||
;;
|
||||
"--torrent-lookup")
|
||||
configuretorrent /usr/local/etc/WolfPack/torrentengine
|
||||
torrentConfigure
|
||||
getmagnetlink "$(echo $2 | tr '#' "$searchunifier")"
|
||||
if [ -z "$magnetlink" ]; then
|
||||
echo Nothing found;
|
||||
@@ -269,6 +268,6 @@ case "$1" in
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Exited "$1 | tee -a "$logfile"
|
||||
echo '---' "$(date)" '---' | tee -a "$logfile"
|
||||
echo | tee -a "$logfile"
|
||||
echo "Exited "$1 | systemd-cat -t "$servicename"
|
||||
echo '---' "$(date)" '---' | systemd-cat -t "$servicename"
|
||||
echo | systemd-cat -t "$servicename"
|
||||
|
Reference in New Issue
Block a user