-
Notifications
You must be signed in to change notification settings - Fork 0
/
sgcli.sh
executable file
·80 lines (65 loc) · 1.32 KB
/
sgcli.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Removes all created pipes
function rmPipes() {
sendPipe=$1
receivePipe=$2
if [ -p "$sendPipe" ]
then
rm $sendPipe
fi
if [ -p "$receivePipe" ]
then
rm $receivePipe
fi
}
# Create pipes
sendPipe="/tmp/sgcli-send"
receivePipe="/tmp/sgcli-receive"
rmPipes $sendPipe $receivePipe
mkfifo $sendPipe
cat > $sendPipe &
sendPid=$!
mkfifo $receivePipe
cat > $receivePipe &
receivePid=$!
# Spawn background Python process
python sgrunner.py &
# Check to see if the user specified an action
if [[ $# -eq 0 ]]
then
echo "No action specified. Try one of the following:"
echo "--order"
echo "--scheduledOrder"
echo "--removeScheduledOrder"
echo "--addAccount"
echo "--removeAccount"
echo "--changeAccount"
else
case ${1} in
"--order")
./actions/performOrder.sh
;;
"--scheduledOrder")
./actions/performOrder.sh "-s"
;;
"--removeScheduledOrder")
./actions/performRemoveScheduledOrder.sh
;;
"--addAccount")
./actions/performAddAccount.sh
;;
"--removeAccount")
./actions/performRemoveAccount.sh
;;
"--changeAccount")
./actions/performChangeAccount.sh
;;
esac
fi
# Remove all pipes, destroy all created processes
rmPipes $sendPipe $receivePipe
disown $sendPid
kill -9 $sendPid &> /dev/null
disown $receivePid
kill -9 $receivePid &> /dev/null
pkill -f sgrunner.py > /dev/null