2021-12-29 14:12:01 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e;
|
|
|
|
|
|
|
|
if ! command -v 'aoc' &> /dev/null
|
|
|
|
then
|
|
|
|
echo "command \`aoc\` not found. Try running \`cargo install aoc-cli\` to install it."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -n "$1" ]; then
|
|
|
|
>&2 echo "Argument is required for day."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
day=$(echo $1 | sed 's/^0*//');
|
|
|
|
day_padded=`printf %02d $day`;
|
|
|
|
|
2021-12-29 14:36:48 +01:00
|
|
|
filename="$day_padded";
|
2021-12-29 14:12:01 +01:00
|
|
|
input_path="src/inputs/$filename.txt";
|
|
|
|
|
|
|
|
tmp_dir=$(mktemp -d);
|
|
|
|
tmp_file_path="$tmp_dir/input";
|
|
|
|
|
|
|
|
aoc download --day $day --file $tmp_file_path;
|
|
|
|
cat $tmp_file_path > $input_path;
|
2021-12-29 14:36:48 +01:00
|
|
|
echo "---"
|
|
|
|
echo "🎄 Successfully wrote input to \"$input_path\"!"
|
2021-12-29 14:12:01 +01:00
|
|
|
|
|
|
|
# Make sure it gets removed even if the script exits abnormally.
|
2021-12-29 14:36:48 +01:00
|
|
|
trap "exit 1" HUP INT PIPE QUIT TERM
|
2021-12-29 14:12:01 +01:00
|
|
|
trap 'rm -rf "$tmp_dir"' EXIT
|