-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.sh
executable file
·44 lines (41 loc) · 1 KB
/
script.sh
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
#!/bin/bash
json=$(curl -s -f 'https://thewhitehat.club/api/v1/status')
currentstate=$(echo $json | jq -r '.data.status')
development=false
if [[ $# != "2" && $# != "3" ]]; then
echo "$#"
echo "Usage: ./script.sh (-dev) <log_file> <server_url>"
exit
fi
if [[ $1 == "-dev" ]]; then
development=true
logfile=$2
url=$3
else
logfile=$1
url=$2
fi
if [[ $currentstate == 'open' ]]; then
echo "Starting Librespot..."
$(systemctl start librespot.service)
if [[ $(cat $logfile | tail -f -n 1) == "Playback:Halted" ]]
then
echo "Playback:Started" >> $logfile
fi
prevlog=$(cat $logfile | tail -f -n 1)
currentlog=$(systemctl status librespot.service --lines 1000 | grep spotify:track: | tail -n 1)
if [ "$currentlog" != "$prevlog" ]
then
echo "$currentlog" >> $logfile
curl $url/api/v1/refresh -d "data=test" -X PUT
fi
prevstate=false
else
echo "Stopping Librespot..."
$(systemctl stop librespot.service)
$(rm $logfile)
$(touch $logfile)
echo "Playback:Halted" >> $logfile
prevstate=true
fi
echo "Done!"