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.
 
 
 

44 lines
1.7 KiB

  1. #!/bin/bash
  2. # Fetch the SHA-1 hashes from an IA item and ensure that they match the local files (i.e. that the upload was successful)
  3. identifier="$1"
  4. escapedIdentifier="$(sed 's/[.[\*^$()+?{|]/\\&/g' <<<"${identifier}")"
  5. readarray -t iasha1sums < <(curl -sL "https://archive.org/download/${identifier}/${identifier}_files.xml" | tr -d '\n' | grep -Po '<file .*?</file>' | grep 'source="original".*<sha1>' | sed 's,^.*name=",,; s,".*<sha1>, ,; s,</sha1>.*$,,' | grep -Pv "^${escapedIdentifier}"'(\.cdx\.(gz|idx)|_meta\.(sqlite|xml)) ' | awk '{ print $2 " " $1 }')
  6. localFiles=()
  7. while IFS= read -r -d $'\0' f; do localFiles+=("${f:2}"); done < <(find . -type f -print0)
  8. readarray -t iaFiles < <(printf "%s\n" "${iasha1sums[@]}" | sed 's,^.\{40\} ,,')
  9. readarray -t localFilesSorted < <(printf "%s\n" "${localFiles[@]}" | sort)
  10. readarray -t iaFilesSorted < <(printf "%s\n" "${iaFiles[@]}" | sort)
  11. readarray -t localMissing < <(comm -13 <(printf "%s\n" "${localFilesSorted[@]}") <(printf "%s\n" "${iaFilesSorted[@]}"))
  12. readarray -t iaMissing < <(comm -23 <(printf "%s\n" "${localFilesSorted[@]}") <(printf "%s\n" "${iaFilesSorted[@]}"))
  13. status=0
  14. if [[ ${#localMissing[@]} -eq 0 && ${#iaMissing[@]} -eq 0 ]]
  15. then
  16. echo "File list comparison: OK"
  17. fi
  18. if [[ ${#iaMissing[@]} -gt 0 ]]
  19. then
  20. echo "Local files that are not in the IA item:"
  21. printf " %s\n" "${iaMissing[@]}"
  22. status=1
  23. fi
  24. if [[ ${#localMissing[@]} -gt 0 ]]
  25. then
  26. echo "IA item files that are not in the local directory:"
  27. printf " %s\n" "${localMissing[@]}"
  28. status=1
  29. fi
  30. echo "SHA-1 comparison:"
  31. sha1sum -c < <(printf "%s\n" "${iasha1sums[@]}") > >(sed 's,^, ,') 2>&1
  32. if [[ $? -ne 0 ]]
  33. then
  34. echo "SHA-1 comparison failed!"
  35. status=1
  36. fi
  37. exit ${status}