-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-orders.sh
executable file
·74 lines (65 loc) · 1.58 KB
/
check-orders.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
#!/bin/sh
# Debug ouput
#set -x
GAME="$1"
WARNINGS=0
if [ -z "$ERESSEA" ] ; then
ERESSEA="$HOME/eressea"
fi
PYTHON_HOME="$ERESSEA/server/bin"
DBTOOL_HOME="$ERESSEA/orders-php"
GAME_HOME="$ERESSEA/game-$GAME"
TEXTDOMAIN="orders"
TEXTDOMAINDIR="$DBTOOL_HOME/locale"
export TEXTDOMAINDIR
GETTEXT() {
gettext "$TEXTDOMAIN" "$*"
}
checkpass() {
FACTION="$1"
PASSWORD="$2"
if [ -n "$PASSWORD" ]
then
if "$PYTHON_HOME/checkpasswd.py" "$GAME_HOME/eressea.db" "$FACTION" "$PASSWORD"
then
return 0
fi
fi
# shellcheck disable=SC2059
printf "$(GETTEXT 'WARNING: Unknown faction %s or invalid password!')\\n" "$FACTION"
WARNINGS=1
return 1
}
check() {
LANGUAGE="$1"
FILENAME="$2"
"echeck" -w1 -x -R "e$GAME" -L "$LANGUAGE" "$FILENAME"
}
orders() {
php "$DBTOOL_HOME/cli.php" "$@"
}
OUTPUT=$(mktemp)
cd "$ERESSEA/game-$GAME/orders.dir" || exit
orders -d orders.db select | while read -r LANGUAGE EMAIL FILENAME ; do
export LANGUAGE
SUBJECT="$(GETTEXT 'orders received')"
found=0
mkfifo check.pipe
orders info "$FILENAME" > check.pipe &
while read -r FACTION PASSWORD ; do
checkpass "$FACTION" "$PASSWORD" >> "$OUTPUT" 2>&1
found=1
done < check.pipe
rm -f check.pipe
if [ $found -ne 0 ]; then
check "$LANGUAGE" "$FILENAME" >> "$OUTPUT" 2>&1
else
WARNINGS=1
printf "$(GETTEXT 'WARNING: Unknown faction or invalid password in %s!')\\n" "$FILENAME" >> "$OUTPUT"
fi
orders update "$FILENAME" 2
if [ $WARNINGS -gt 0 ] ; then
SUBJECT="$(GETTEXT 'orders received (warning)')"
fi
mutt -s "[E$GAME] $SUBJECT" "$EMAIL" < "$OUTPUT"
done