The little things give you away... A collection of various small helper stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

28 lines
1018 B

  1. #!/bin/bash
  2. if [[ "$#" -eq 0 || "$1" == '-h' || "$1" == '--help' ]]
  3. then
  4. echo 'Usage: curl-ia CURL-ARGUMENTS...' >&2
  5. echo 'Runs curl with the cookies from `ia`'"'s"' config file' >&2
  6. exit 1
  7. fi
  8. # 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.
  9. if [[ -z "${XDG_CONFIG_HOME}" || "${XDG_CONFIG_HOME}" != /* || ! -d "${XDG_CONFIG_HOME}" ]]
  10. then
  11. XDG_CONFIG_HOME="${HOME}/.config"
  12. fi
  13. for path in "${IA_CONFIG_FILE}" "${XDG_CONFIG_HOME}/internetarchive/ia.ini" ~/.config/ia.ini ~/.ia
  14. do
  15. if [[ -f "${path}" ]]
  16. then
  17. break
  18. fi
  19. done
  20. if [[ ! -f "${path}" ]]
  21. then
  22. echo 'Error: Could not find ia config file; did you run `ia configure`?' >&2
  23. exit 1
  24. fi
  25. 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}") "$@"