-
Notifications
You must be signed in to change notification settings - Fork 0
/
aoc.sh
executable file
·53 lines (45 loc) · 1.24 KB
/
aoc.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
#!/bin/bash
#accessing through symlink?
if [ -h $0 ]
then
# change to directory of target of symlink
TARGET=`readlink $0`
cd $(dirname $TARGET)
else
# change to directory of this script
cd $(dirname $0)
fi
# If there are exactly 2 arguments...
if [[ $# -eq 2 ]]; then
YEAR=$1
DAY=$2
if [ $YEAR -lt 2015 -o $DAY -gt 25 ]; then
echo "Not a suitable AOC date"
echo "Expected: `aoc YEAR DAY`, or just `aoc` to get current day during the event"
exit 1
fi
# Exactly zero arguments
elif [[ $# -eq 0 ]]; then
YEAR=`date "+%Y"`
MONTH=`date "+%m"`
DAY=`date "+%-d"`
if [ $MONTH -ne 12 -o $DAY -gt 25 ]; then
echo "Arguments needed"
echo "Expected: `aoc YEAR DAY`, or just `aoc` to get current day during the event"
exit 1
fi
else
echo "Wrong number of arguments"
echo "Expected: `aoc YEAR DAY`, or just `aoc` to get current day during the event"
exit 1
fi
echo "Processing with year: $YEAR day: $DAY"
TARGET_DIR="./$YEAR/day$DAY"
TARGET_FILE="$TARGET_DIR/input"
if [ -e $TARGET_FILE ]; then
echo "Repeat invocation prevented!"
exit 1
fi
mkdir -p $TARGET_DIR
curl -s "https://adventofcode.com/$YEAR/day/$DAY/input" --cookie "session=$ADVENT_OF_CODE_SESSION" > $TARGET_FILE
echo "Downloaded $TARGET_FILE"