dejavusansmono 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/bash
  2. # helper script: downloads dejavu sans mono
  3. #
  4. # Copyright (C) 2021 Leah Rowe <info@minifree.org>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. [ "x${DEBUG+set}" = 'xset' ] && set -v
  20. set -u -e
  21. tarurl="http://sourceforge.net/projects/dejavu/files/dejavu/2.37/dejavu-fonts-ttf-2.37.tar.bz2"
  22. tarfilename="dejavu-fonts-ttf-2.37.tar.bz2"
  23. dirname="dejavu-fonts-ttf-2.37"
  24. tarchecksum="bafa39321021097432777f0825d700190c23f917d754a4504722cd8946716c22c083836294dab7f3ae7cf20af63c4d0944f3423bf4aa25dbca562d1f30e00654 ${tarfilename}"
  25. ttffilename="DejaVuSansMono.ttf"
  26. ttfchecksum="9c09b9d5bef34dd57f1dd9d98e7d92c1dd7892d22b4e7ca040a8130b3555aa19815b8a7c94b869ff436220e996a69847b46eaddf765c11569dffe9d72644ee38 ${ttffilename}"
  27. checkttf() {
  28. dirpath="${1}"
  29. if [ -d "${dirpath}" ]; then
  30. if [ -f "${dirpath}/ttf/${ttffilename}" ]; then
  31. cd "${dirpath}/ttf/"
  32. if [ "$(sha512sum ${ttffilename})" = "${ttfchecksum}" ]; then
  33. cd ../../
  34. printf "REMARK: '%s/ttf/%s' checksum verification passed.\n" "${dirpath}" "${ttffilename}"
  35. return 0
  36. fi
  37. cd ../../
  38. fi
  39. printf "REMARK: '%s/ttf/%s' checksum verification FAILED.\n" "${dirpath}" "${ttffilename}"
  40. fi
  41. return 1
  42. }
  43. if [ -d "dejavusansmono/" ]; then
  44. checkttf "dejavusansmono" || rm -Rf "dejavusansmono/"
  45. if [ -d "dejavusansmono/" ]; then
  46. rm -f "${tarfilename}"
  47. rm -Rf "${dirname}/"
  48. printf "REMARK: download/dejavusansmono: DeJavu already downloaded and checksum passed.\n"
  49. exit 0
  50. else
  51. printf "REMARK: download/dejavusansmono: DeJavu font will be re-downloaded.\n"
  52. fi
  53. fi
  54. if [ -d "${dirname}/" ]; then
  55. checkttf "${dirname}" || rm -Rf "${dirname}/"
  56. if [ ! -d "${dirname}/" ]; then
  57. printf "REMARK: download/dejavusansmono: DeJavu font will be re-downloaded.\n"
  58. fi
  59. fi
  60. if [ ! -d "${dirname}/" ]; then
  61. if [ -f "${tarfilename}" ]; then
  62. if [ "$(sha512sum ${tarfilename})" != "${tarchecksum}" ]; then
  63. printf "REMARK: download/dejavusansmono: archive already downloaded, but checksum failed. Re-downloading\n"
  64. printf "Deleting archive\n"
  65. rm -f "${tarfilename}"
  66. wget ${tarurl}
  67. else
  68. printf "REMARK: download/dejavusansmono: archive already downloaded, and checksum passed. Skipping download\n"
  69. fi
  70. else
  71. wget ${tarurl}
  72. fi
  73. if [ ! -f "${tarfilename}" ]; then
  74. printf "ERROR: download/dejavusansmono: archive not downloaded. Exiting.\n"
  75. exit 1
  76. fi
  77. if [ "$(sha512sum ${tarfilename})" != "${tarchecksum}" ]; then
  78. printf "ERROR: download/dejavusansmono: archive has invalid checksum. Exiting\n"
  79. printf "Deleting archive.\n"
  80. rm -f "${tarfilename}"
  81. exit 1
  82. fi
  83. tar -xf "${tarfilename}" || touch osbmk_error
  84. fi
  85. if [ -f osbmk_error ]; then
  86. rm -f osbmk_error
  87. rm -Rf "dejavusansmono"
  88. rm -Rf "${dirname}"
  89. printf "ERROR: download/dejavusansmono: problem extracting archive.\n"
  90. exit 1
  91. fi
  92. mv "${dirname}" "dejavusansmono"
  93. checkttf "dejavusansmono" || touch osbmk_error
  94. if [ -f osbmk_error ]; then
  95. rm -f osbmk_error
  96. rm -Rf "dejavusansmono"
  97. rm -Rf "${dirname}"
  98. rm -f "${tarfilename}"
  99. printf "ERROR: download/dejavusansmono: TTF file got corrupted. Tar is cursed.\n"
  100. exit 1
  101. fi
  102. rm -Rf "${dirname}"
  103. rm -Rf "${tarfilename}"
  104. printf "REMARK: download/dejavusansmono: Dejavu Sans Mono font successfully downloaded.\n"
  105. exit 0