-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext-day.sh
executable file
·56 lines (44 loc) · 1.42 KB
/
next-day.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
#!/usr/bin/env bash
if [[ $# -ne 1 ]]; then
echo "A single argument with the day number must be provided"
exit
fi
# session ID from Developer Tools/Network/Headers in Chrome
export SESSION="`cat SESSION`"
printf -v day "day-%02d" $1
input_path="inst/extdata/${day}.txt"
test_path="tests/testthat/test-${day}.R"
run_path="inst/run-${day}.R"
curl -s https://adventofcode.com/2021/day/$1/input --cookie "session=$SESSION" -o ${input_path}
if grep -Eq '404 Not Found|endpoint' $input_path; then
echo "Puzzle for the given day ${1} not found"
rm $input_path
exit 1
else
echo "Puzzle input downloaded and saved as ${input_path}"
fi
echo "-----"
if [[ ! -f $test_path ]]; then
sed "s/__day__/${1}/g" inst/extdata/test-template.R > $test_path
echo "Test file created at ${test_path}"
else
echo "Test file already present at ${test_path}"
fi
echo "-----"
if grep -q "${day}" inst/run-all.R; then
echo "Run code for the day already present in inst/run-all.R"
else
cp inst/run-all.R inst/run-all.R.old
echo "source(\"inst/run-${day}.R\", local = TRUE)" > inst/run-all.R
cat inst/run-all.R.old >> inst/run-all.R
rm inst/run-all.R.old
fi
echo "-----"
if [[ ! -f $run_path ]]; then
sed "s/__DAY__/${day}/g; s/__day__/${1}/g" inst/extdata/run-template.R \
> $run_path
echo "Run script created at ${run_path}"
else
echo "Run script already present at ${run_path}"
fi
touch R/${day}.R