#!/bin/bash if [[ "$#" -eq 0 || ( "$1" != 'cookie' && "$1" != 'header' ) ]] then echo 'Usage: curl-ia MODE CURL-ARGUMENTS...' >&2 echo 'Runs curl with the cookies from `ia`'"'s"' config file' >&2 echo "MODE must be either cookie or header; in the latter case, the 'Authorization' header is added to *all* requests!" >&2 exit 1 fi mode="$1" shift # 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 if [[ "${mode}" == 'cookie' ]] then 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}") "$@" else header="$(python3 -c 'import configparser, sys; config = configparser.RawConfigParser(); config.read(sys.argv[1]); print("LOW " + config["s3"]["access"] + ":" + config["s3"]["secret"])' "${path}")" exec curl --header "Authorization: ${header}" "$@" fi