/install-templates-xcode.sh

https://bitbucket.org/Tsiannian/cocos2d-x · Shell · 246 lines · 239 code · 6 blank · 1 comment · 2 complexity · f9445448f302cc9f279384003792f8e3 MD5 · raw file

  1. #!/bin/bash
  2. echo 'cocos2d-x template installer'
  3. COCOS2D_VER='cocos2d-2.0-rc2-x-2.0.1'
  4. BASE_TEMPLATE_DIR="/Library/Application Support/Developer/Shared/Xcode"
  5. BASE_TEMPLATE_USER_DIR="$HOME/Library/Application Support/Developer/Shared/Xcode"
  6. force=
  7. user_dir=
  8. usage(){
  9. cat << EOF
  10. usage: $0 [options]
  11. Install / update templates for ${COCOS2D_VER}
  12. OPTIONS:
  13. -f force overwrite if directories exist
  14. -h this help
  15. -u install in user's Library directory instead of global directory
  16. EOF
  17. }
  18. while getopts "fhu" OPTION; do
  19. case "$OPTION" in
  20. f)
  21. force=1
  22. ;;
  23. h)
  24. usage
  25. exit 0
  26. ;;
  27. u)
  28. user_dir=1
  29. ;;
  30. esac
  31. done
  32. # Make sure only root can run our script
  33. if [[ ! $user_dir && "$(id -u)" != "0" ]]; then
  34. echo ""
  35. echo "Error: This script must be run as root in order to copy templates to ${BASE_TEMPLATE_DIR}" 1>&2
  36. echo ""
  37. echo "Try running it with 'sudo', or with '-u' to install it only you:" 1>&2
  38. echo " sudo $0" 1>&2
  39. echo "or:" 1>&2
  40. echo " $0 -u" 1>&2
  41. exit 1
  42. fi
  43. # Make sure root and user_dir is not executed at the same time
  44. if [[ $user_dir && "$(id -u)" == "0" ]]; then
  45. echo ""
  46. echo "Error: Do not run this script as root with the '-u' option." 1>&2
  47. echo ""
  48. echo "Either use the '-u' option or run it as root, but not both options at the same time." 1>&2
  49. echo ""
  50. echo "RECOMMENDED WAY:" 1>&2
  51. echo " $0 -u -f" 1>&2
  52. echo ""
  53. exit 1
  54. fi
  55. copy_files(){
  56. # SRC_DIR="${SCRIPT_DIR}/${1}"
  57. rsync -r --exclude=.svn "$1" "$2"
  58. }
  59. check_dst_dir(){
  60. if [[ -d $DST_DIR ]]; then
  61. if [[ $force ]]; then
  62. echo "removing old libraries: ${DST_DIR}"
  63. rm -rf "${DST_DIR}"
  64. else
  65. echo "templates already installed. To force a re-install use the '-f' parameter"
  66. exit 1
  67. fi
  68. fi
  69. echo ...creating destination directory: $DST_DIR
  70. mkdir -p "$DST_DIR"
  71. }
  72. # copy_base_mac_files(){
  73. # echo ...copying cocos2dx files
  74. # copy_files cocos2dx "$LIBS_DIR"
  75. # echo ...copying CocosDenshion files
  76. # copy_files CocosDenshion "$LIBS_DIR"
  77. # }
  78. copy_base_files(){
  79. echo ...copying cocos2dx files
  80. copy_files cocos2dx "$LIBS_DIR"
  81. echo ...copying CocosDenshion files
  82. copy_files CocosDenshion "$LIBS_DIR"
  83. }
  84. copy_cocos2d_files(){
  85. echo ...copying cocos2d files
  86. copy_files cocos2dx "$LIBS_DIR"
  87. copy_files licenses/LICENSE_cocos2d-x.txt "$LIBS_DIR"
  88. }
  89. copy_cocosdenshion_files(){
  90. echo ...copying CocosDenshion files
  91. copy_files CocosDenshion "$LIBS_DIR"
  92. # copy_files licenses/LICENSE_CocosDenshion.txt "$LIBS_DIR"
  93. }
  94. copy_extensions_files(){
  95. echo ...copying extension files
  96. copy_files extensions "$LIBS_DIR"
  97. }
  98. # copy_cocosdenshionextras_files(){
  99. # echo ...copying CocosDenshionExtras files
  100. # copy_files CocosDenshion/CocosDenshionExtras "$LIBS_DIR"
  101. # }
  102. # copy_fontlabel_files(){
  103. # echo ...copying FontLabel files
  104. # copy_files external/FontLabel "$LIBS_DIR"
  105. # copy_files licenses/LICENSE_FontLabel.txt "$LIBS_DIR"
  106. # }
  107. # copy_cocoslive_files(){
  108. # echo ...copying cocoslive files
  109. # copy_files cocoslive "$LIBS_DIR"
  110. # echo ...copying TouchJSON files
  111. # copy_files external/TouchJSON "$LIBS_DIR"
  112. # copy_files licenses/LICENSE_TouchJSON.txt "$LIBS_DIR"
  113. # }
  114. print_template_banner(){
  115. echo ''
  116. echo ''
  117. echo ''
  118. echo "$1"
  119. echo '----------------------------------------------------'
  120. echo ''
  121. }
  122. # Xcode4 templates
  123. copy_xcode4_project_templates(){
  124. TEMPLATE_DIR="$HOME/Library/Developer/Xcode/Templates/cocos2d-x/"
  125. print_template_banner "Installing Xcode 4 cocos2d-x iOS template"
  126. DST_DIR="$TEMPLATE_DIR"
  127. check_dst_dir
  128. LIBS_DIR="$DST_DIR""lib_cocos2dx.xctemplate/libs/"
  129. mkdir -p "$LIBS_DIR"
  130. copy_cocos2d_files
  131. LIBS_DIR="$DST_DIR""lib_cocosdenshion.xctemplate/libs/"
  132. mkdir -p "$LIBS_DIR"
  133. copy_cocosdenshion_files
  134. LIBS_DIR="$DST_DIR""lib_extensions.xctemplate/libs/"
  135. mkdir -p "$LIBS_DIR"
  136. copy_extensions_files
  137. echo ...copying template files
  138. copy_files template/xcode4/ "$DST_DIR"
  139. echo done!
  140. print_template_banner "Installing Xcode 4 Chipmunk iOS template"
  141. LIBS_DIR="$DST_DIR""lib_chipmunk.xctemplate/libs/"
  142. mkdir -p "$LIBS_DIR"
  143. echo ...copying Chipmunk files
  144. copy_files external/chipmunk "$LIBS_DIR"
  145. copy_files licenses/LICENSE_chipmunk.txt "$LIBS_DIR"
  146. echo done!
  147. print_template_banner "Installing Xcode 4 Box2d iOS template"
  148. LIBS_DIR="$DST_DIR""lib_box2d.xctemplate/libs/"
  149. mkdir -p "$LIBS_DIR"
  150. echo ...copying Box2D files
  151. copy_files external/Box2D "$LIBS_DIR"
  152. copy_files licenses/LICENSE_box2d.txt "$LIBS_DIR"
  153. echo done!
  154. print_template_banner "Installing Xcode 4 lua iOS template"
  155. LIBS_DIR="$DST_DIR""lib_lua.xctemplate/libs/"
  156. mkdir -p "$LIBS_DIR"
  157. echo ...copying lua files
  158. copy_files scripting/lua "$LIBS_DIR"
  159. copy_files licenses/LICENSE_lua.txt "$LIBS_DIR"
  160. copy_files licenses/LICENSE_tolua++.txt "$LIBS_DIR"
  161. echo done!
  162. print_template_banner "Installing Xcode 4 JS iOS template"
  163. LIBS_DIR="$DST_DIR""lib_js.xctemplate/libs/javascript"
  164. mkdir -p "$LIBS_DIR"
  165. echo ...copying js files
  166. copy_files scripting/javascript/bindings "$LIBS_DIR"
  167. copy_files licenses/LICENSE_js.txt "$LIBS_DIR"
  168. echo done!
  169. echo ...copying spidermonkey files
  170. LIBS_DIR="$DST_DIR""lib_spidermonkey.xctemplate/libs/javascript"
  171. mkdir -p "$LIBS_DIR"
  172. copy_files scripting/javascript/spidermonkey-ios "$LIBS_DIR"
  173. echo done!
  174. # Move File Templates to correct position
  175. # DST_DIR="$HOME/Library/Developer/Xcode/Templates/File Templates/cocos2d/"
  176. # OLD_DIR="$HOME/Library/Developer/Xcode/Templates/cocos2d/"
  177. # print_template_banner "Installing Xcode 4 CCNode file templates..."
  178. # check_dst_dir
  179. # mv -f "$OLD_DIR""/CCNode class.xctemplate" "$DST_DIR"
  180. echo done!
  181. }
  182. copy_xcode4_project_templates