-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch.sh
43 lines (36 loc) · 824 Bytes
/
fetch.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
yes=
if [ "$1" = "--yes" ]; then
yes=1
shift
fi
day=$1
if [ $# -eq 0 ]; then
day=$(TZ=UTC date +%-d)
echo "OK, we have to guess the day, let's guess $day???"
else
shift
if [ "$1" = "--yes" ]; then
yes=1
shift
fi
fi
daypad=$(seq -f %02g $day $day)
if [ "$yes" = "1" ]; then
if [ -f input$day ]; then
echo "THE INPUT ALREADY EXISTS!!!"
else
curl --cookie session=$(cat secrets/session) -o input$day https://adventofcode.com/2021/day/$day/input
fi
else
curl -o input$day http://example.com
fi
if [ -f $daypad.rb ]; then
backup="$daypad-$(date +%s).rb"
echo "I think we should back up $daypad.rb to $backup!"
mv $daypad.rb $backup
fi
if [ -f TEMPLATE.rb ]; then
cat TEMPLATE.rb input$day > $daypad.rb
elif [ -f template.rb ]; then
cat template.rb input$day > $daypad.rb
fi