1
1

fix-src-case.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env bash
  2. # fixes image src casing, so thing aren't broken on case-sensitive file systems (Linux)
  3. # requirements: linux (GNU coreutils), ripgrep, latest images in images/
  4. exact_fix() {
  5. # fixes when src uses exact path, but incorrect casing
  6. images="$(find ./images -type f)"
  7. IFS=$'\n'
  8. for image in $images; do
  9. actual="${image:2}"
  10. echo "exact_fix: ${actual}"
  11. rg -il --type-add 'qsrc:*.qsrc' -tqsrc "${actual}" \
  12. | xargs -I {} sed -i -e "s|${actual}|${actual}|gI" '{}'
  13. done
  14. }
  15. subdir_fix() {
  16. # fixes subdirectory casings, when src uses variables
  17. # more a failsafe, since var_fix might have edge cases
  18. images="$(find ./images -type d | sed -e 's|$|/|')"
  19. IFS=$'\n'
  20. for image in $images; do
  21. actual="${image:2}"
  22. echo "subdir_fix: ${actual}"
  23. rg -il --type-add 'qsrc:*.qsrc' -tqsrc "${actual}" \
  24. | xargs -I {} sed -i -e "s|${actual}|${actual}|gI" '{}'
  25. done
  26. }
  27. var_fix() {
  28. # tries to fix casing when src uses variables
  29. # example:
  30. # images/locations/pavlovsk/resident/apartment/aptrolan/guavacoco'+rand(0,2)+'.jpg
  31. # images/characters/pavlovsk/school/girl/natasha/natsleep<<rand(1,4)>>.jpg
  32. images="$(find images -type f | grep -e '[0-9]\.[A-Za-z]*$' | sed -e 's|\(.*/\)\([^0-9]*\).*|\1\2|' -e '/\/$/d' | sort -u)"
  33. IFS=$'\n'
  34. for image in $images; do
  35. actual="${image}'"
  36. echo "var_fix: ${actual}"
  37. rg -il --type-add 'qsrc:*.qsrc' -tqsrc "${actual}" \
  38. | xargs -I {} sed -i -e "s|${actual}|${actual}|gI" '{}'
  39. actual="${image}<<"
  40. echo "var_fix: ${actual}"
  41. rg -il --type-add 'qsrc:*.qsrc' -tqsrc "${actual}" \
  42. | xargs -I {} sed -i -e "s|${actual}|${actual}|gI" '{}'
  43. done
  44. }
  45. var_fix
  46. subdir_fix
  47. exact_fix
  48. echo "Done!"