forked from iori-yja/WORD-bukkyo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·88 lines (70 loc) · 1.89 KB
/
run.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
81
82
83
84
85
86
87
#!/bin/zsh
function post_slack () {
curl "${slackurl}$(echo "${1}"| nkf -wMQ | sed 's/=$//g')" &
echo posting to slack..
}
function no_item_found () {
# no_item_found UI's pid item username
kill -USR2 "${1}"
sleep 0.1
echo "${2}, ${3}" >&p
echo "ありゃりゃ?商品が見つからないよ?" >&p
echo "配給担当までお問い合わせを" >&p
kill -USR1 "${1}"
sleep 3
}
# shellcheck disable=SC2034
fpath=(./routines)
autoload -U get_balance
autoload -U search_item
autoload -U get_itemname
autoload -U check_itemprice
autoload -U try_withdrawal
autoload -U barcode_listener
olduser=""
killall -9 title.wish
coproc "./title.wish" $$
guicpid=$(pgrep "title.wish" | awk '{print $1}' | head -1)
fdump=""
echo "${guicpid}"
slackurl=$(grep "slackurl:" ../bukkyo.conf| head -1 |awk '{print $2}')
trap barcode_listener USR1
sleep 1
while true;do
# Waiting for felica card
fdump=$(timeout 2 felica_dump)
if [ ! "$fdump" ]; then
kill -USR2 "${guicpid}"
olduser=""
elif [ "$fdump" = "error" ]; then
msg="No card Reader found"
kill -USR2 "${guicpid}"
sleep 0.1
echo "${msg}" >&p
echo "${msg}" >&p
echo "${msg}" >&p
kill -USR1 "${guicpid}"
sleep 10
else
dummy_username=$(echo "$fdump" | grep "0040:0003:" | sed -e "s/^.*0040:0003:\([A-Z,0-9]*\)$/\1/"|./hex2bin|nkf -Sw)
dummy_userid=$(echo "$fdump" | grep "0040:0000:" | sed -e "s/^.*0040:0000:\([A-Z,0-9]*\)$/\1/"|./hex2bin|nkf -Sw)
dummy_user=$((dummy_userid / 100000 - 1000000000))
dummy_balance=$(get_balance $dummy_user)
username="${dummy_username}"
# shellcheck disable=SC2034
userid="${dummy_userid}"
user="${dummy_user}"
balance="${dummy_balance}"
if [ "${olduser}" != "${user}" ]; then
echo "Card detected!"
echo "${username}"
echo "${user}"
echo "${balance}"
echo "${username}" >&p
echo "${user}" >&p
echo "${balance}" >&p
kill -USR1 "${guicpid}"
olduser="${user}"
fi
fi
done