updatelanglist.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # helper script to check the local language list against mozilla
  3. export CARCH="${CARCH:-$(uname -m)}"
  4. prompt() {
  5. if cmp "$1"{,.pkgnew} > /dev/null; then
  6. echo "$1 unchanged"
  7. rm -f "$1.pkgnew"
  8. else
  9. diff -rupN "$1"{,.pkgnew}
  10. while true; do
  11. read -n1 -p "[a]pply, [d]elete, [m]erge, [s]kip, [q]uit " resp ; echo ;
  12. case $resp in
  13. a) mv "$1"{.pkgnew,}
  14. break
  15. ;;
  16. d) rm -f "$1".pkgnew
  17. break
  18. ;;
  19. m) vimdiff "$1"{,.pkgnew}
  20. rm "$1".pkgnew
  21. break
  22. ;;
  23. s) break
  24. ;;
  25. q) exit
  26. ;;
  27. *) ;;
  28. esac
  29. done
  30. fi
  31. }
  32. ## extract metadata from PKGBUILD ##
  33. pkgbase="$(bash -c "source PKGBUILD && echo \"\$_pkgbase\"")"
  34. url="$( bash -c "source PKGBUILD && echo \"\$_src_url\"")/"
  35. echo "attempting update to language lists for '$pkgbase'"
  36. echo -e " CARCH: $CARCH\n URL: $url"
  37. read -n1 -p "is this correct? [Yn] " resp ; echo ; [[ "$resp" =~ n|N ]] && exit ;
  38. ## generate new language list ##
  39. mkdir -p src
  40. echo "_languages=(" > "languages.$CARCH.pkgnew"
  41. echo "_sha512sums=(" > "sha512sums.$CARCH.pkgnew"
  42. for lang in $(curl -sL "$url" | grep '\.xpi' | cut -d'"' -f2 | rev | cut -d'/' -f1 | cut -d'.' -f2 | rev | sort); do
  43. printf "\r %-3s..." "${lang%%-*}"
  44. curl -s -o src/"$lang.xpi" "${url%/}/$lang.xpi"
  45. sha512sum="$(sha512sum "src/$lang.xpi" | cut -d' ' -f1)"
  46. name="$(unzip -p "src/$lang.xpi" manifest.json | grep " \"name" | cut -d':' -f2- | cut -d'"' -f2)"
  47. printf " '%-5s \"%s\"'\n" "$lang" "$name" >> "languages.$CARCH.pkgnew"
  48. printf " '%s'\n" "$sha512sum" >> "sha512sums.$CARCH.pkgnew"
  49. done
  50. echo
  51. echo ")" >> "languages.$CARCH.pkgnew"
  52. echo ")" >> "sha512sums.$CARCH.pkgnew"
  53. ## compare and update lang-pack/checksums lists ##
  54. prompt "languages.$CARCH"
  55. prompt "sha512sums.$CARCH"
  56. ## update PKGBUILD checksums for lang-pack/checksums lists ##
  57. _languages_shasum="$( sha512sum "languages.$CARCH" | cut -d' ' -f1)"
  58. _sha512sums_shasum="$(sha512sum "sha512sums.$CARCH" | cut -d' ' -f1)"
  59. sed -e "s/^_languages_${CARCH}_shasum=.*/_languages_${CARCH}_shasum=\"${_languages_shasum}\"/" \
  60. -e "s/^_sha512sums_${CARCH}_shasum=.*/_sha512sums_${CARCH}_shasum=\"${_sha512sums_shasum}\"/" \
  61. PKGBUILD > PKGBUILD.pkgnew
  62. prompt "PKGBUILD"