Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. #!/bin/bash
  2. ### Author: Insality <insality@gmail.com>, 04.2019
  3. ## (c) Insality Games
  4. ##
  5. ## Unique build && deploy script for mobile projects (Android, iOS)
  6. ## for Defold Engine.
  7. ## Usage:
  8. ## bash deployer.sh [a][i][r][b][d]
  9. ## a - add target platform Android
  10. ## i - add target platform iOS
  11. ## r - set build mode to Release
  12. ## b - build project (game bundle will be in ./dist folder)
  13. ## d - deploy bundle to connected device
  14. ## it will deploy && run bundle on Android
  15. ## it will only deploy bundle on iOS
  16. ##
  17. ## Example:
  18. ## ./deployer.sh abd - build, deploy and run Android bundle
  19. ## ./deployer.sh ird - build and deploy iOS release bundle
  20. ## ./deployer.sh aibr - build Android and iOS release bundles
  21. ##
  22. ## You can pass params in any order you want, for example:
  23. ## ./deployer.sh riba - same behaviour as aibr
  24.  
  25.  
  26. title=$(less game.project | grep "^title = " | cut -d "=" -f2 | sed -e 's/^[[:space:]]*//')
  27. version=$(less game.project | grep "^version = " | cut -d "=" -f2 | sed -e 's/^[[:space:]]*//')
  28. title_no_space=$(echo -e "${title}" | tr -d '[[:space:]]')
  29. bundle_id=$(less game.project | grep "^package = " | cut -d "=" -f2 | sed -e 's/^[[:space:]]*//')
  30. android_platform="armv7-android"
  31. ios_platform="armv7-darwin"
  32.  
  33. ## Setup provisions and certificates for your project
  34. bob_path=../bob.jar
  35. android_key="./provisions/key.pk8"
  36. android_cer="./provisions/certificate.pem"
  37. ios_identity_dev="ABXXABXX"
  38. ios_identity_dist="ABYYABYYY"
  39. ios_prov_dev="./provisions/dev.mobileprovision"
  40. ios_prov_dist="./provisions/dist.mobileprovision"
  41.  
  42. echo "Project: ${title} v${version}"
  43.  
  44. if [ ! -f ${bob_path} ]
  45. then
  46. echo "Unable to find bob.jar. Download it from d.defold.com."
  47. exit 1
  48. fi
  49.  
  50.  
  51. resolve_bob() {
  52. java -jar ${bob_path} --email foo@bar.com --auth 12345 resolve
  53. }
  54.  
  55. bob() {
  56. java -jar ${bob_path} --version
  57. java -jar ${bob_path} --archive -tc true -bo ./dist \
  58. --strip-executable $@ distclean build bundle
  59. }
  60.  
  61. build() {
  62. if [ ! -d ./dist ]
  63. then
  64. mkdir ./dist
  65. fi
  66. platform=$1
  67. release=$2
  68. mode="debug"
  69. ident=${ios_identity_dev}
  70. prov=${ios_prov_dev}
  71. if $2
  72. then
  73. mode="release"
  74. ident=${ios_identity_dist}
  75. prov=${ios_prov_dist}
  76. fi
  77.  
  78. resolve_bob
  79.  
  80. if [ ${platform} == "armv7-android" ]
  81. then
  82. echo "Start build android ${mode}"
  83. bob -brhtml ./dist/${platform}_report.html \
  84. --platform ${platform} -pk ${android_key} -ce ${android_cer} \
  85. --variant ${mode}
  86. fi
  87.  
  88. if [ ${platform} == "armv7-darwin" ]
  89. then
  90. echo "Start build ios ${mode}"
  91. bob -brhtml ./dist/${platform}_report.html \
  92. --platform ${platform} --identity ${ident} -mp ${prov} \
  93. --variant ${mode}
  94. fi
  95. }
  96.  
  97. deploy() {
  98. platform=$1
  99. if [ ${platform} == "armv7-android" ]
  100. then
  101. line="./dist/${title}/${title}.apk"
  102. line= sed 's/ /\\ /g' <<< $line
  103. echo "Deploy to Android from $line"
  104. adb install -r "${line}"
  105. fi
  106.  
  107. if [ ${platform} == "armv7-darwin" ]
  108. then
  109. line="./dist/${title}.ipa"
  110. line= sed 's/ /\\ /g' <<< $line
  111. echo "Deploy to Ios from dist/${line}.ipa"
  112. ios-deploy --bundle "${line}"
  113. fi
  114. }
  115.  
  116. run() {
  117. platform=$1
  118. if [ ${platform} == "armv7-android" ]
  119. then
  120. echo "Start game ${bundle_id}"
  121. adb shell am start -n ${bundle_id}/com.dynamo.android.DefoldActivity
  122. adb logcat -s defold
  123. fi
  124. if [ ${platform} == "armv7-darwin" ]
  125. then
  126. echo "Can't run ipa on iOS"
  127. fi
  128. }
  129.  
  130. all_release() {
  131. echo "Start build all releases"
  132. build armv7-android true
  133. build armv7-darwin true
  134. }
  135.  
  136. arg=$1
  137. is_build=false
  138. is_deploy=false
  139. release=false
  140. is_android=false
  141. is_ios=false
  142.  
  143. for (( i=0; i<${#arg}; i++ )); do
  144. a=${arg:$i:1}
  145. if [ $a == b ]
  146. then
  147. is_build=true
  148. fi
  149. if [ $a == "d" ]
  150. then
  151. is_deploy=true
  152. fi
  153. if [ $a == "r" ]
  154. then
  155. release=true
  156. fi
  157. if [ $a == "a" ]
  158. then
  159. is_android=true
  160. fi
  161. if [ $a == "i" ]
  162. then
  163. is_ios=true
  164. fi
  165. done
  166.  
  167.  
  168. if $is_ios
  169. then
  170. if $is_build
  171. then
  172. echo "Start build on ${ios_platform}"
  173. build ${ios_platform} ${release}
  174. fi
  175.  
  176. if $is_deploy
  177. then
  178. echo "Start deploy project to device"
  179. deploy ${ios_platform}
  180. run ${ios_platform}
  181. fi
  182. fi
  183.  
  184. if $is_android
  185. then
  186. if $is_build
  187. then
  188. echo "Start build on ${android_platform}"
  189. build ${android_platform} ${release}
  190. fi
  191.  
  192. if $is_deploy
  193. then
  194. echo "Start deploy project to device"
  195. deploy ${android_platform}
  196. run ${android_platform}
  197. fi
  198. fi
  199.  
  200. echo "End of builder"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement