diff options
author | cos <cos> | 2022-12-01 16:14:20 +0000 |
---|---|---|
committer | cos <cos> | 2022-12-01 17:27:23 +0000 |
commit | 1773627631cc873b6a09098dda1cac14c6ed03fa (patch) | |
tree | 13e34a2c0348fe20cf2283321189a59c91641f94 /bin | |
parent | 4a54a0d97a57df6c1525b9bbfcabdf829e44a4d1 (diff) | |
download | adventofcode-1773627631cc873b6a09098dda1cac14c6ed03fa.zip |
Initial commit of init_year, poke support scripts
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cookies_from_chromium | 32 | ||||
-rwxr-xr-x | bin/cookies_from_chromium.sh | 13 | ||||
-rwxr-xr-x | bin/fetch_input (renamed from bin/fetch_input.sh) | 0 | ||||
-rwxr-xr-x | bin/init_rust (renamed from bin/init_rust.sh) | 2 | ||||
-rwxr-xr-x | bin/init_year | 76 |
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 |