configuration-templates – Blame information for rev 168

Subversion Repositories:
Rev:
Rev Author Line No. Line
168 office 1 #!/bin/bash
2 ###########################################################################
3 ## Copyright (C) Wizardry and Steamworks 2023 - License: GNU GPLv3 ##
4 ###########################################################################
5 # This script connects to rTorrent via SCGI, checks the hostname and the #
6 # current PID of the rTorrent process and then returns 0 if the hostname #
7 # and PID match the results from the system tools or 1 otherwise. #
8 # #
9 # Requirements: #
10 # * sed #
11 # * tr #
12 # * netcat #
13 # * grep #
14 # * xmlstarlet #
15 # #
16 ###########################################################################
17  
18 ###########################################################################
19 # CONFIGURATION #
20 ###########################################################################
21  
22 # These settings correspond to the rTorrent setting:
23 # network.scgi.open_port = "0.0.0.0:5000"
24 # that enables the SCGI remote access functionality.
25 RTORRENT_HOST="localhost"
26 RTORRENT_PORT=5000
27  
28 ###########################################################################
29 # INTERNALS #
30 ###########################################################################
31  
32 SESSION=$(cat <<EOF | \
33 sed -E 's/[ ]{2,}//g' | \
34 tr ' ' \\0 | \
35 tr -d '\n' | \
36 netcat "$RTORRENT_HOST" "$RTORRENT_PORT" | \
37 grep -Pzo "(?s)<methodResponse>.+?<\/methodResponse>" | \
38 xmlstarlet select -t -v /methodResponse/params/param[1]/value/string
39 63:
40 CONTENT_LENGTH 62
41 SCGI 1
42 REQUEST_METHOD POST
43 REQUEST_URI /RPC2
44 ,
45 <methodCall>
46 <methodName>session.name</methodName>
47 </methodCall>
48 EOF
49 )
50  
51 HOST=`echo $SESSION | awk -F':' '{ print $1 }'`
52 PID=`echo $SESSION | awk -F':' '{ print $2 }'`
53  
54 [ "$HOST" == `hostname` ] || exit 1
55 [ "$PID" == `pgrep -f /usr/bin/rtorrent` ] || exit 1
56  
57 exit 0