-
Notifications
You must be signed in to change notification settings - Fork 6
/
shutdown.sh
59 lines (36 loc) · 1.83 KB
/
shutdown.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
if [ "$USER" == "root" ]; then
if [ ! -f /root/.config/pva.root.overwrite ]; then
echo "please, do not run this as root, it does only work for desktopsessions!"
exit;
fi
fi
cd /usr/share/pva/
PORT=$(LANG=C netstat -lna | grep -c -E ":39999.*LISTEN")
if [ "$PORT" == "1" ]; then
GREETING=$(grep "^conf:.*shutdown" /etc/pva/conf.d/* $HOME/.config/pva/conf.d/* | tail -n 1 | sed -e "s/^.*,//g" -e "s/\"//g")
if [ "$GREETING" != "" ]; then
SAY=$(grep say $HOME/.config/pva/pva.conf| sed -e "s/^.*,//g" -e "s/\"//g" -e "s/%VOICE/$MLANG/g" -e "s/x:x/ /g")
if [ "$SAY" == "" ]; then
SAY="/usr/local/sbin/say"
fi
$SAY "$GREETING" &
fi
NAME=$(grep "^conf:.*keyword" /etc/pva/conf.d/* $HOME/.config/pva/conf.d/* | tail -n 1 | sed -e "s/^.*,//g" -e "s/\"//g")
if [ "$NAME" == "" ]; then
NAME="Carola"
fi
EXIT=$(grep -E "command:.*\"AUTOEXIT\"" /etc/pva/conf.d/* $HOME/.config/pva/conf.d/*| tail -n 1| sed -e "s/^.*://g" | awk -F "," '{print $1;}'| sed -e "s/\"//g" -r -e "s/\\|/ /g")
echo -n "$NAME $EXIT" | openssl s_client -connect 127.0.0.1:39999 -nbio 1>/dev/null 2>/dev/null
CODE=$(grep -E "code:\"alpha\"" $HOME/.config/pva/conf.d/* | tail -n 1| sed -e "s/^.*://g" | awk -F "," '{print $2;}'| sed -e "s/\"//g" -r -e "s/\\|/ /g")
CMD=$(grep -E "command:.*\"SHUTDOWNAUTHORIZE\"" /etc/pva/conf.d/* $HOME/.config/pva/conf.d/*| tail -n 1| sed -e "s/^.*://g" | awk -F "," '{print $1;}'| sed -e "s/\"//g" -r -e "s/\\|/ /g")
echo -n "$NAME $CMD $CODE" | openssl s_client -connect 127.0.0.1:39999 -nbio 1>/dev/null 2>/dev/null
else
// this should not be happening
PID=$(/usr/bin/pgrep -u $USER -f server.PVA)
kill -9 $PID
fi
# PVA will shutdown now , which will call Plugin-Shutdown as well.
# old fashion way to stop it ...
PID=$(/usr/bin/pgrep -f ./pva.py)
kill -9 $PID