Browse Source

Add curl-ia

master
JustAnotherArchivist 1 year ago
parent
commit
0f8a22f035
1 changed files with 27 additions and 0 deletions
  1. +27
    -0
      curl-ia

+ 27
- 0
curl-ia View File

@@ -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}") "$@"

Loading…
Cancel
Save