command_fastdl.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #!/bin/bash
  2. # LGSM command_fastdl function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: http://gameservermanagers.com
  6. lgsm_version="190216"
  7. # Description: Creates a FastDL folder
  8. local modulename="FastDL Creator"
  9. function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. check.sh
  11. # Directories
  12. fastdldir="${rootdir}/fastdl"
  13. # Server lua autorun dir, used to autorun lua on client connect to the server
  14. luasvautorundir="${systemdir}/lua/audoturn/server"
  15. luafastdlfile="lgsm_cl_force_fastdl.lua"
  16. luafastdlfullpath="${luasvautorundir}/${luafastdlfile}"
  17. fn_fastdl_init(){
  18. # User confirmation for starting process
  19. echo "Generate a FastDL Folder ?"
  20. while true; do
  21. read -p "Continue? [y/N]" yn
  22. case $yn in
  23. [Yy]* ) break;;
  24. [Nn]* ) exit;;
  25. * ) echo "Please answer yes or no.";;
  26. esac
  27. done
  28. # Create FastDL folder if it doesn't exit
  29. if [ ! -d "${fastdldir}" ]; then
  30. echo "Creating FastDL directory"
  31. mkdir -v "${fastdldir}"
  32. sleep 1
  33. else
  34. echo "Updating FastDL..."
  35. fi
  36. # Ask for lua resource add file use
  37. echo "Do you wish to use a lua file to force clients to download FastDL content ?"
  38. echo "It can be necessary for addons devs that forgot about registering their files to be downloaded through FastDL"
  39. while true; do
  40. read -p "Continue? [y/n]" yn
  41. case $yn in
  42. [Yy]* ) luaressource="on"; break;;
  43. [Nn]* ) luaressource="off"; return 1;;
  44. * ) echo "Please answer yes or no.";;
  45. esac
  46. done
  47. }
  48. fn_gmod_fastdl(){
  49. # Copy all needed files for fastDL
  50. echo "Gathering all needed FastDL files..."
  51. sleep 1
  52. cd "${systemdir}"
  53. # Map Files
  54. echo "Copying map files"
  55. sleep 1
  56. find . -name '*.bsp' | cpio -updm "${fastdldir}"
  57. echo "Done"
  58. sleep 1
  59. # Materials
  60. echo "Copying Materials"
  61. sleep 1
  62. find . -name '*.vtf' | cpio -updm "${fastdldir}"
  63. find . -name '*.vmt' | cpio -updm "${fastdldir}"
  64. echo "Done"
  65. sleep 1
  66. # Models
  67. echo "Copying Models"
  68. sleep 1
  69. find . -name '*.vtx' | cpio -updm "${fastdldir}"
  70. find . -name '*.vvd' | cpio -updm "${fastdldir}"
  71. find . -name '*.mdl' | cpio -updm "${fastdldir}"
  72. find . -name '*.phy' | cpio -updm "${fastdldir}"
  73. echo "Done"
  74. sleep 1
  75. # Particles
  76. echo "Copying Particles"
  77. sleep 1
  78. find . -name '*.pcf' | cpio -updm "${fastdldir}"
  79. echo "Done"
  80. sleep 1
  81. # Sounds
  82. echo "Copying Sounds"
  83. sleep 1
  84. find . -name '*.wav' | cpio -updm "${fastdldir}"
  85. find . -name '*.mp3' | cpio -updm "${fastdldir}"
  86. find . -name '*.ogg' | cpio -updm "${fastdldir}"
  87. echo "Done"
  88. sleep 1
  89. # Resources (mostly fonts)
  90. echo "Copying fonts and png"
  91. sleep 1
  92. find . -name '*.otf' | cpio -updm "${fastdldir}"
  93. find . -name '*.ttf' | cpio -updm "${fastdldir}"
  94. find . -name '*.png' | cpio -updm "${fastdldir}"
  95. echo "Done"
  96. sleep 1
  97. # Going back to scriptfolder to avoid mistakes
  98. cd ${rootdir}
  99. # Correct addons folder structure
  100. if [ -d "${fastdldir}/addons" ]; then
  101. echo "Possible FastDL files found into addons"
  102. echo "Moving those files to their correct folder"
  103. sleep 2
  104. cp -Rf ${fastdldir}/addons/*/* "${fastdldir}"
  105. rm -R "${fastdldir}/addons"
  106. echo "Done"
  107. sleep 1
  108. fi
  109. # Correct content that may be into a lua folder by mistake like some darkrpmodification addons
  110. if [ -d "${fastdldir}/lua" ]; then
  111. echo "Some FastDL files (often addons in darkrpmodifications) may be in the wrong folder"
  112. sleep 1
  113. echo "Copying those files to their hopefully correct locations"
  114. sleep 1
  115. cp -Rf "${fastdldir}/lua/"* "${fastdldir}"
  116. echo "Done"
  117. sleep 1
  118. fi
  119. }
  120. # bzip2 compression
  121. fn_check_bzip2(){
  122. # Returns true if not installed
  123. if [ -z "$(command -v bzip2)" ]; then
  124. bzip2installed="0"
  125. echo "WARNING bzip2 packed is not installed !"
  126. sleep 2
  127. echo "You can't compress your FastDL files !"
  128. sleep 2
  129. echo "Loading time won't be as good as possible for your players."
  130. sleep 2
  131. echo "It's advised that your install bzip2 and re-run the fastdl command."
  132. sleep 3
  133. else
  134. bzip2installed="1"
  135. fi
  136. }
  137. fn_fastdl_bzip2(){
  138. echo "Do you want to compress files using bzip2 for even faster client download ?"
  139. echo "It may take a while..."
  140. while true; do
  141. read -p "Continue? [y/N]" yn
  142. case $yn in
  143. [Yy]* ) break;;
  144. [Nn]* ) exit;;
  145. * ) echo "Please answer yes or no.";;
  146. esac
  147. done
  148. echo "Compressing files using bzip2..."
  149. sleep 2
  150. # bzip2 all files that are not already compressed (keeping original files)
  151. find "${fastdldir}" -not -name \*.bz2 -exec bzip2 -k \{\} \;
  152. echo "bzip2 compression done"
  153. sleep 1
  154. }
  155. # Function to implement
  156. fn_lua_fastdl(){
  157. if [ luaressource="off" == "on" ]; then
  158. if [ -f "${luafastdlfullpath}" ]; then
  159. echo "Removing "
  160. }
  161. fn_fastdl_completed(){
  162. echo "----------------------------------"
  163. echo "Congratulations, it's done"
  164. echo "Now you should configure your HTTP server to target the fastdl folder that was created"
  165. echo "Or copy files to an external server"
  166. echo "Don't forget to change your sv_downloadurl accordingly in ${servercfgfullpath}"
  167. if [ "$bzip2installed" == "0" ]; then
  168. echo "By the way, you'd better install bzip2 an re-run this command"
  169. fi
  170. echo "----------------------------------"
  171. exit
  172. }
  173. # Game checking
  174. # Garry's Mod
  175. if [ "${gamename}" == "Garry's Mod" ]; then
  176. fn_fastdl_init
  177. fn_gmod_fastdl
  178. fn_check_bzip2
  179. if [ "${bzip2installed}" == "1" ]; then
  180. fn_fastdl_bzip2
  181. fi
  182. fn_lua_fastdl
  183. fn_fastdl_completed
  184. exit
  185. fi