-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·75 lines (64 loc) · 1.29 KB
/
setup.sh
File metadata and controls
executable file
·75 lines (64 loc) · 1.29 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
function real_base_name () {
target=$1
(
while true; do
cd "$(dirname "$target")"
target=$(basename "$target")
link=$(readlink "$target")
test "$link" || break
target=$link
done
echo "$(pwd -P)"
)
}
function output () {
echo "$@"
}
function output_error () {
>&2 echo "$@"
}
function fail () {
>&2 echo "$@"
exit 1
}
function usage {
output_error "Usage: $BASH_SOURCE [--year <YEAR> --day <DAY>]"
output_error "--year: Year, defaults to current"
output_error "--day: Day, defaults to current"
exit 1
}
YEAR="$(date +"%Y")"
DAY="$(date +"%-d")"
TOKEN="$AOC_SESSION_TOKEN"
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--help)
usage
;;
--day)
shift
DAY="$1"
;;
--year)
shift
YEAR="$1"
;;
--token)
shift
TOKEN="$1"
;;
*)
output_error "Unknown option: $key"
usage
;;
esac
shift # past argument or value
done
SCRIPT_DIR=$(real_base_name "$0")
cd "$SCRIPT_DIR"
./create-source.sh --day "$DAY" --year "$YEAR" || fail "Could not create source file"
./get-input.sh --day "$DAY" --year "$YEAR" --token "$TOKEN" || fail "Could not get input"
./get-sample.sh --day "$DAY" --year "$YEAR" --token "$TOKEN" || fail "Could not get input"