summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cookies_from_chromium32
-rwxr-xr-xbin/cookies_from_chromium.sh13
-rwxr-xr-xbin/fetch_input (renamed from bin/fetch_input.sh)0
-rwxr-xr-xbin/init_rust (renamed from bin/init_rust.sh)2
-rwxr-xr-xbin/init_year76
5 files changed, 109 insertions, 14 deletions
diff --git a/bin/cookies_from_chromium b/bin/cookies_from_chromium
new file mode 100755
index 0000000..b59e494
--- /dev/null
+++ b/bin/cookies_from_chromium
@@ -0,0 +1,32 @@
+#!/bin/sh -eu
+
+_aoc_config="${HOME}/.adventofcode.json"
+
+for _c in "${HOME}/.config/chrom"*/*'/Cookies'
+do
+ echo "${_c}"
+ printf '%s\n%s%s\n' '.headers on' \
+ 'SELECT name, value, hex(encrypted_value) FROM cookies ' \
+ 'WHERE host_key=".adventofcode.com";' | sqlite3 "${_c}"
+done
+
+echo 'This is a reminder of how cookies are encrypted.' \
+ 'Manual export is required.' >&2
+echo 'Ctrl-Shift-i > Application > Cookies' >&2
+
+read -p 'Session cookie: ' _session_cookie
+
+read -p "Create ${_aoc_config} (y/N)? " _input
+
+case "${_input}" in
+ 'y' | 'Y')
+ echo 'Ok. Creating the file.'
+ printf '{ "session-cookie": "%s" }' "${_session_cookie}" \
+ > "${_aoc_config}"
+ ;;
+ *)
+ echo 'Ok. Skipping it.'
+ ;;
+esac
+
+unset _c _input _session_cookie
diff --git a/bin/cookies_from_chromium.sh b/bin/cookies_from_chromium.sh
deleted file mode 100755
index 208cf14..0000000
--- a/bin/cookies_from_chromium.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh -e
-
-for C in "${HOME}/.config/chrom"*/*'/Cookies'
-do
- echo "${C}"
- printf '%s\n%s%s\n' '.headers on' \
- 'SELECT name, value, hex(encrypted_value) FROM cookies ' \
- 'WHERE host_key=".adventofcode.com";' | sqlite3 "${C}"
-done
-
-echo 'This is a reminder of how cookies are encrypted.' \
- 'Manual export is required.' >&2
-exit 1
diff --git a/bin/fetch_input.sh b/bin/fetch_input
index ec09328..ec09328 100755
--- a/bin/fetch_input.sh
+++ b/bin/fetch_input
diff --git a/bin/init_rust.sh b/bin/init_rust
index fc4e25d..1431b87 100755
--- a/bin/init_rust.sh
+++ b/bin/init_rust
@@ -1,4 +1,4 @@
-#!/bin/sh -e
+#!/bin/sh -eu
YEAR=${YEAR:-$(date +%Y)}
DAY=${DAY:-$(TZ=EST date '+%d')}
diff --git a/bin/init_year b/bin/init_year
new file mode 100755
index 0000000..494c86f
--- /dev/null
+++ b/bin/init_year
@@ -0,0 +1,76 @@
+#!/bin/sh -eu
+
+if [ "${1:-}" ]; then
+ _lang="$1"
+fi
+
+if [ "${2:-}" ]; then
+ _year="$2"
+else
+ _year=$( date +%Y )
+fi
+
+### FUNCTION ##################################################################
+
+rust() {
+ rust_dir="$1"
+
+ (
+ printf '%s\n%s\n' '[workspace]' 'members = ['
+ for day in $( seq 1 25 ); do
+ printf '# "day%02d",\n' "${day}"
+ done
+ echo ']'
+ ) > "${rust_dir}/Cargo.toml"
+
+ unset rust_dir
+}
+
+### MAIN ######################################################################
+
+_dir="$( pwd )/${_year}"
+
+if ! [ -d "${_dir}" ]; then
+ read -p "Create directory '${_dir}'?: " _input
+
+ case "${_input}" in
+ 'y' | 'Y')
+ mkdir "${_dir}"
+ ;;
+ *)
+ echo 'Okay, not doing anything then.'
+ exit 0
+ ;;
+ esac
+ unset _input
+fi
+
+[ "${_lang:-}" ] || read -p "Implementation language for '${_year}'?: " _lang
+
+if ! [ -d "${_dir}/${_lang}" ]; then
+ read -p "Create directory '${_dir}/${_lang}'?: " _input
+ case "${_input}" in
+ 'y' | 'Y')
+ mkdir "${_dir}/${_lang}"
+ ;;
+ *)
+ echo 'Okay, not doing that then.'
+ exit 0
+ ;;
+ esac
+ unset _input
+fi
+
+read -p "Run '${_lang}(\"${_dir}/${_lang}\")'?: " _input
+case "${_input}" in
+ 'y' | 'Y')
+ ${_lang} "${_dir}/${_lang}"
+ ;;
+ *)
+ echo 'Okay, not doing that then.'
+ exit 0
+ ;;
+esac
+unset _input
+
+unset _dir _lang _year