-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_day.sh
executable file
·50 lines (40 loc) · 1.35 KB
/
init_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
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
year=$1; shift
day=$1; shift
dayDir=${DIR}/${year}/day${day}
if [ -e ${dayDir} ]; then
echo "Directory $dayDir already exists! Exiting"
exit 1
fi
mkdir -p ${dayDir}
file=${dayDir}/Makefile
echo "include ../../Makefile.conf" > ${file}
echo "" >> ${file}
echo "SRCS_A += main.cpp" >> ${file}
echo "" >> ${file}
echo "include ../../Makefile.rules" >> ${file}
file=${dayDir}/main.cpp
echo "#include \"common/types.h\"" > ${file}
echo "" >> ${file}
echo "#include \"utils/file.h\"" >> ${file}
echo "#include \"utils/utils.h\"" >> ${file}
echo "" >> ${file}
echo "#define DEBUG_LEVEL 5" >> ${file}
echo "#include \"common/debug.h\"" >> ${file}
echo "" >> ${file}
echo "int main(int argc, char *argv[]) {" >> ${file}
echo " auto lines = File::readAllLines(argv[1]);" >> ${file}
echo "" >> ${file}
echo " return 0;" >> ${file}
echo "}" >> ${file}
if [ ! -e $DIR/cookie.txt ]; then
echo "No cookie file present! No input data will be downloaded!"
else
curl --silent -L --cookie $DIR/cookie.txt --fail https://adventofcode.com/${year}/day/${day}/input -o ${dayDir}/data.txt
if [ $? -ne 0 ]; then
echo "Cannot download input data for day ${day} of year ${year}"
rm -f ${dayDir}/data.txt
fi
fi
cd ${dayDir}