-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunday
executable file
·49 lines (47 loc) · 1.41 KB
/
runday
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
#!/bin/zsh
# Copyright 2024 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# Run the AoC solution for a day on all of its input, saving logs to out/
# Run an each change with ./watch day1 or watchexec ./runday day1
YEAR="2024"
if [ $# -eq 0 ]; then
print -u 2 "Usage: runday day1"
exit 1
fi
BASEDIR="${0:h}"
ROOT="${BASEDIR:a:h}"
DAY="$1"
DAYDIR="$BASEDIR/$DAY"
if [[ ! -d "$DAYDIR" ]]; then
print -u 2 "No such directory: $DAYDIR"
exit 1
fi
PROGRAM="$DAYDIR/$1.ps"
if [[ ! -f "$PROGRAM" ]]; then
print -u 2 "Missing file: $PROGRAM"
exit 1
fi
DATEFMT='%Y%m%d-%H%M%S'
mkdir -p "$DAYDIR/out"
OUTFILE="$DAYDIR/out/$(date +$DATEFMT).log"
if [[ -s "$ROOT/.cookie-jar" && ! -s "$DAYDIR/input.actual.txt" ]]; then
input=$("$ROOT/fetchinput" "$YEAR" "$1")
# Don't directly send fetchinput to input.actual.txt to avoid changing mtime
# if input isn't avaliable yet
if [[ ! -z "$input" ]]; then
if [[ -d "$BASEDIR/input" ]] mkdir -p "$BASEDIR/input/$DAY"
cat <<< $input >| $DAYDIR/input.actual.txt
fi
fi
CMD=(gsnd -q -dNOSAFER -I"${BASEDIR:a}" --
$PROGRAM -v $DAYDIR/input.example*.txt $DAYDIR/input.actual.txt)
TIMEFMT="$PROGRAM > $OUTFILE %U user %S system %P cpu %*E total"
print -u 2
print -u 2 "$CMD > $OUTFILE"
print -u 2
time ($CMD 2>&1 | tee "$OUTFILE" ; exit ${pipestatus[1]})
res=$?
exit $res