-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_day.sh
More file actions
executable file
·42 lines (33 loc) · 1011 Bytes
/
setup_day.sh
File metadata and controls
executable file
·42 lines (33 loc) · 1011 Bytes
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
#!/bin/bash
set -euo pipefail
if [ "$#" -ne 1 ]; then
echo "Usage: $(basename "$0") <day-number>" >&2
exit 1
fi
if [ ! -d .git ]; then
echo "Must be run from the root of the advent-of-code repository" >&2
exit 1
fi
DAY_NUM=$1
NAME=$(printf "day_%02d" "$DAY_NUM")
if [ -d "$NAME" ]; then
echo "The project '$NAME' already exists." >&2
else
cargo new --vcs none "${NAME}"
if [ -f ./template_main.rs ]; then
cp -v ./template_main.rs ./"${NAME}"/src/main.rs
fi
cat ./release_profile >> ./"${NAME}"/Cargo.toml
fi
SESSION_COOKIE_FILE="./sessionCookie"
if [ ! -f "$SESSION_COOKIE_FILE" ]; then
echo "Session cookie file not found" >&2
exit 1
fi
INPUT_URL="http://adventofcode.com/2023/day/${DAY_NUM}/input"
curl -Ls -b session=$(cat "$SESSION_COOKIE_FILE") "$INPUT_URL" > "${NAME}/input.txt"
echo
echo "Project '${NAME}' created successfully with input file."
echo "--------HEAD-INPUT----------"
head "${NAME}/input.txt"
echo "----------------------------"