summarylogtreecommitdiffstats
path: root/wfinfo.sh
blob: cff5ac7d909942a43408c4cf86d193cbc6b4f2b2 (plain)
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
#!/bin/sh
CACHEDIR=~/.cache/wfinfo-ng
mkdir -pv "$CACHEDIR"
cd "$CACHEDIR" || { echo Could not enter cache directory, exiting...; exit 1; }
# EE.log location as first parameter?
logloc="$1"; [ "$#" -ge 1 ] && shift
logloc="${logloc:-$(
# EE.log location set manually in cachedir?
cat "$CACHEDIR/EElogloc" 2>&- ||
# find EE.log with most recent modification time
locate \*/Warframe/EE.log |
xargs -rd \\n stat -c '%Y %n' |
sort -n | tail -n 1 | cut -d ' ' -f 2-
)}"
if ! [ "$logloc" ]; then
	echo No EE.log location '($1)', exiting...
	exit 3
fi
if ! [ -r "$logloc" ]; then
	echo Invalid or unreadable EE.log location \""$logloc"\", exiting...
	exit 4
fi
printf %s\\n "$logloc" > "$CACHEDIR/EElogloc" && echo Storing EE.log location...

wfinfo-update ||
if [ -f "$CACHEDIR/filtered_items.json" ] && [ -f "$CACHEDIR/prices.json" ]; then
	echo Update failed, continuing...
else
	echo Update failed and no cached price info, exiting...
	exit 2
fi
# wfinfo-ng will create multiple PNG files in $PWD
# this would delete them, but we've already got a cache directory anyway
#cleanup(){ echo Exit; rm ./*.png; exit 130; }; trap cleanup INT
exec wfinfo-ng "$logloc" "$@"