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.
 
 
 

36 lines
1.1 KiB

  1. #!/usr/bin/env bash
  2. if [[ $# -ne 1 || "$1" == '--help' || "$1" == '-h' ]]; then
  3. printf 'Usage: extract-urls-for-archiveteam-projects PREFIX\n' >&2
  4. printf 'Reads URLs from stdin, extracts interesting for the different currently relevant AT projects into files prefixed by PREFIX\n' >&2
  5. exit 1
  6. fi
  7. prefix="$1"
  8. if [[ "${prefix}" == *[*?[]* ]]; then
  9. printf 'Error: prefixes containing * ? [ not supported\n' >&2
  10. exit 1
  11. fi
  12. if compgen -G "${prefix}*" >/dev/null; then
  13. printf 'Error: there already exist files starting with %q\n' "${prefix}" >&2
  14. exit 1
  15. fi
  16. tee \
  17. >(grep -Fai imgur >"${prefix}-imgur.txt") \
  18. >(grep -Fai -e mediafire -e mfi.re >"${prefix}-mediafire.txt") \
  19. >(grep -Fai pastebin.com >"${prefix}-pastebin.txt") \
  20. >(grep -Fai -e blogspot -e blogger >"${prefix}-blogger.txt") \
  21. >(grep -Fai -e telegram.me -e //t.me/ >"${prefix}-telegram.txt") \
  22. >/dev/null
  23. # Wait for the procsubs to terminate
  24. wait
  25. for f in "${prefix}"-{imgur,mediafire,pastebin,blogger,telegram}.txt; do
  26. if [[ -f "${f}" && ! -s "${f}" ]]; then
  27. printf '%q is empty, deleting\n' "${f}" >&2
  28. rm -- "${f}"
  29. fi
  30. done