diff --git a/curl-ia b/curl-ia new file mode 100755 index 0000000..676d3b2 --- /dev/null +++ b/curl-ia @@ -0,0 +1,27 @@ +#!/bin/bash +if [[ "$#" -eq 0 || "$1" == '-h' || "$1" == '--help' ]] +then + echo 'Usage: curl-ia CURL-ARGUMENTS...' >&2 + echo 'Runs curl with the cookies from `ia`'"'s"' config file' >&2 + exit 1 +fi + +# Logic for the config file location is the same as upstream: the first one of $IA_CONFIG_FILE, ${XDG_CONFIG_HOME}/internetarchive/ia.ini, ~/.config/ia.ini, ~/.ia that exists is used. +if [[ -z "${XDG_CONFIG_HOME}" || "${XDG_CONFIG_HOME}" != /* || ! -d "${XDG_CONFIG_HOME}" ]] +then + XDG_CONFIG_HOME="${HOME}/.config" +fi +for path in "${IA_CONFIG_FILE}" "${XDG_CONFIG_HOME}/internetarchive/ia.ini" ~/.config/ia.ini ~/.ia +do + if [[ -f "${path}" ]] + then + break + fi +done +if [[ ! -f "${path}" ]] +then + echo 'Error: Could not find ia config file; did you run `ia configure`?' >&2 + exit 1 +fi + +exec curl --cookie <(python3 -c 'import configparser, sys; config = configparser.RawConfigParser(); config.read(sys.argv[1]); {print(f".archive.org\tTRUE\t/\tFALSE\t0\t{k}\t{v}") for k, v in config["cookies"].items()}' "${path}") "$@"