regenerate_htdocs.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/bash
  2. function maxquality { # maxquality val filename
  3. if [ -r $2 ] ; then
  4. curq=$(identify -format "%Q" $2)
  5. if [ $curq -gt $1 ] ; then
  6. mogrify -quality $1 $2
  7. fi
  8. fi
  9. }
  10. targets="htdocs htdocs/q60 htdocs/q80"
  11. # set working directory to the location of the script
  12. cd $(dirname "$(readlink -f "${0}")")
  13. # cleanup
  14. rm -Rf temp htdocs
  15. # create map zip files
  16. mkdir -p temp/packages/maps
  17. for t in $targets ; do mkdir -p $t/packages/maps ; done
  18. cd unpacked/packages/maps
  19. for file in *.cgz ; do
  20. echo creating packages/maps/$file.zip
  21. t=${file%.cgz}.cfg
  22. if [ -r $t ] ; then
  23. zip -9 ../../../temp/packages/maps/$file.zip $file $t
  24. else
  25. zip -9 ../../../temp/packages/maps/$file.zip $file
  26. fi
  27. done
  28. cd ../../..
  29. for t in $targets ; do cp temp/packages/maps/* $t/packages/maps ; done
  30. # copy map sounds
  31. for t in $targets ; do mkdir -p $t/packages/audio/ambience ; done
  32. for t in $targets ; do cp -r unpacked/packages/audio/ambience/* $t/packages/audio/ambience ; done
  33. # create skymap zips
  34. for t in $targets ; do mkdir -p $t/packages/textures/skymaps ; done
  35. mkdir -p temp/packages/textures
  36. mkdir -p temp/tmp
  37. cp -r unpacked/packages/textures/* temp/packages/textures
  38. cd temp
  39. skymapparts="lf rt ft bk dn up"
  40. for file in $(find packages/textures/skymaps -name "*_ft.jpg" -type f) ; do
  41. echo creating ${file%_ft.jpg}.zip
  42. for t in $targets ; do mkdir -p ../$t/$(dirname $file) ; done
  43. # full quality (if it fits in one megabyte, otherwise reduce to 95%)
  44. touch tmp/dummy
  45. rm tmp/*
  46. for t in $skymapparts ; do cp ${file%ft.jpg}$t.jpg tmp ; done
  47. if [ -r ${file%ft.jpg}_license.txt ] ; then
  48. cp ${file%ft.jpg}_license.txt tmp
  49. fi
  50. zip -9 -j tz.zip tmp/*
  51. if [ $(cat tz.zip | wc -c) -ge 1024000 ] ; then
  52. for t in tmp/*.jpg ; do maxquality 95 $t ; done
  53. fi
  54. rm tz.zip
  55. zip -9 -j ../htdocs/${file%_ft.jpg}.zip tmp/*
  56. # q80
  57. for t in $skymapparts ; do cp ${file%ft.jpg}$t.jpg tmp ; done
  58. for t in tmp/*.jpg ; do maxquality 80 $t ; done
  59. zip -9 -j ../htdocs/q80/${file%_ft.jpg}.zip tmp/*
  60. # q60
  61. for t in $skymapparts ; do cp ${file%ft.jpg}$t.jpg tmp ; done
  62. for t in tmp/*.jpg ; do maxquality 60 $t ; done
  63. zip -9 -j ../htdocs/q60/${file%_ft.jpg}.zip tmp/*
  64. done
  65. cd ..
  66. rm -Rf temp/packages/textures/skymaps
  67. # copy full quality textures
  68. echo copy full quality textures
  69. mkdir -p htdocs/packages/textures
  70. cp -r temp/packages/textures/* htdocs/packages/textures
  71. # create q60 textures
  72. echo create q60 textures
  73. mkdir -p htdocs/q60/packages/textures
  74. cp -r temp/packages/textures/* htdocs/q60/packages/textures
  75. for file in $(find htdocs/q60/packages/textures -name "*.jpg" -type f) ; do
  76. maxquality 60 $file
  77. done
  78. # create q80 textures
  79. echo create q80 textures
  80. mkdir -p htdocs/q60/packages/textures
  81. cp -r temp/packages/textures/* htdocs/q80/packages/textures
  82. for file in $(find htdocs/q80/packages/textures -name "*.jpg" -type f) ; do
  83. maxquality 80 $file
  84. done
  85. # create mapmodel zips
  86. for t in temp $targets ; do mkdir -p $t/packages/models/mapmodels ; done
  87. cp -r unpacked/packages/models/* temp/packages/models
  88. cd temp
  89. for file in $(find packages/models/mapmodels -name "*.cfg" -type f) ; do
  90. p=$(dirname $(dirname $file))
  91. fn=$(basename $(dirname $file))
  92. echo creating $p/$fn.zip
  93. for t in $targets ; do mkdir -p ../$t/$p ; done
  94. # get all appropriate files
  95. touch tmp/dummy
  96. rm tmp/*
  97. for t in $(dirname $file)/* ; do
  98. case $t in
  99. *.md2|*.md3|*.cfg|*.txt|*.jpg|*.png)
  100. cp $t tmp
  101. ;;
  102. *)
  103. echo ignore $t
  104. ;;
  105. esac
  106. done
  107. # full quality (if it fits in one megabyte, otherwise reduce jpegs to 95%)
  108. zip -9 -j tz.zip tmp/*
  109. if [ $(cat tz.zip | wc -c) -ge 1024000 ] ; then
  110. for t in tmp/*.jpg ; do maxquality 95 $t ; done
  111. fi
  112. zip -9 -j ../htdocs/$p/$fn.zip tmp/*
  113. # q80
  114. rm tmp/*
  115. unzip tz.zip -d tmp
  116. for t in tmp/*.jpg ; do maxquality 80 $t ; done
  117. zip -9 -j ../htdocs/q80/$p/$fn.zip tmp/*
  118. # q60
  119. rm tmp/*
  120. unzip tz.zip -d tmp
  121. for t in tmp/*.jpg ; do maxquality 60 $t ; done
  122. zip -9 -j ../htdocs/q60/$p/$fn.zip tmp/*
  123. rm tz.zip
  124. done
  125. cd ..