The little things give you away... A collection of various small helper stuff
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

38 lignes
1.4 KiB

  1. #!/bin/bash
  2. if [[ "$#" -eq 0 || ( "$1" != 'cookie' && "$1" != 'header' ) ]]
  3. then
  4. echo 'Usage: curl-ia MODE CURL-ARGUMENTS...' >&2
  5. echo 'Runs curl with the cookies from `ia`'"'s"' config file' >&2
  6. echo "MODE must be either cookie or header; in the latter case, the 'Authorization' header is added to *all* requests!" >&2
  7. exit 1
  8. fi
  9. mode="$1"
  10. shift
  11. # 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.
  12. if [[ -z "${XDG_CONFIG_HOME}" || "${XDG_CONFIG_HOME}" != /* || ! -d "${XDG_CONFIG_HOME}" ]]
  13. then
  14. XDG_CONFIG_HOME="${HOME}/.config"
  15. fi
  16. for path in "${IA_CONFIG_FILE}" "${XDG_CONFIG_HOME}/internetarchive/ia.ini" ~/.config/ia.ini ~/.ia
  17. do
  18. if [[ -f "${path}" ]]
  19. then
  20. break
  21. fi
  22. done
  23. if [[ ! -f "${path}" ]]
  24. then
  25. echo 'Error: Could not find ia config file; did you run `ia configure`?' >&2
  26. exit 1
  27. fi
  28. if [[ "${mode}" == 'cookie' ]]
  29. then
  30. 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}") "$@"
  31. else
  32. header="$(python3 -c 'import configparser, sys; config = configparser.RawConfigParser(); config.read(sys.argv[1]); print("LOW " + config["s3"]["access"] + ":" + config["s3"]["secret"])' "${path}")"
  33. exec curl --header "Authorization: ${header}" "$@"
  34. fi