-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogreader.sh
More file actions
executable file
·76 lines (56 loc) · 1.84 KB
/
logreader.sh
File metadata and controls
executable file
·76 lines (56 loc) · 1.84 KB
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
#!/bin/sh
# for any future readers, this script has been kept strictly POSIX and shellcheck compliant
# if it appears to be written moderately strangely
# modify as needed
logfile="${PWD}/iw4xchat.log"
# probably don't modify
RED='\033[0;31m'
BOLD='\033[1m'
CLEAR='\033[0m'
die() {
printf "%b\n" "${RED}FATAL:${CLEAR} $1"
exit 1
}
# jq is required to read the log with this shell script
# everything else here should be covered by coreutils
! command -v jq > /dev/null &&
die "jq binary not found in PATH, cannot continue"
help() {
printf "%b\n\n" "${BOLD}Usage:${CLEAR}
./logreader.sh -a <author_id> -c <channel_id> -m <message_id> -e -d
${BOLD}Options:${CLEAR}
-a Specify the author ID to query the log for
-c Specify the channel ID to query the log for
-m Specify the message ID to query the log for
-e Search for only edited messages
-d Search for only deleted messages"
exit
}
case "$1" in
help|--h|-h|'') help ;;
*)
while getopts "a:c:m:ed" opts ; do
case "${opts}" in
a) author_id="$OPTARG";;
c) channel_id="$OPTARG" ;;
m) message_id="$OPTARG" ;;
e) edited=true ;;
d) deleted=true ;;
*) help ;;
esac
done
;;
esac
# this is going to have to be slightly messy given the amount of ways this can be invoked, my apologies
query='.'
[ -n "$author_id" ] &&
query="$query | select(.author_ID == \"$author_id\")"
[ -n "$channel_id" ] &&
query="$query | select(.channel_ID == \"$channel_id\")"
[ -n "$message_id" ] &&
query="$query | select(.message_ID == \"$message_id\")"
[ -n "$edited" ] &&
query="$query | select(.type == \"edit\")"
[ -n "$deleted" ] &&
query="$query | select(.type == \"deletion\")"
jq "$query" "$logfile" || die "Query invalid."