release-all.sh 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #!/bin/sh
  2. VERSION=$1
  3. OS=`uname -s`
  4. SVN_REVISION=`export LANG=C && [ -f /usr/bin/git ] && git --git-dir=../.git describe --long $VERSION`
  5. if [ '!' -z "$VERSION" ]; then
  6. VERSION_STR=$VERSION
  7. else
  8. VERSION_STR=$SVN_REVISION
  9. fi
  10. if [ -z "$VERSION" ]; then
  11. VERSION=`echo "$SVN_REVISION" | cut -d'-' -f1`
  12. fi
  13. VERSION=`echo "$VERSION" | cut -d'v' -f2`
  14. BASE_NAME=qwbfsmanager-$VERSION_STR
  15. FOLDER_NAME=$BASE_NAME-src
  16. TAR_GZ_FILE=$FOLDER_NAME.tar.gz
  17. ZIP_FILE=$FOLDER_NAME.zip
  18. WIN_SETUP=$BASE_NAME-win32.exe
  19. WIN_FOLDER=$BASE_NAME-win32
  20. WIN_PACKAGE=$WIN_FOLDER.zip
  21. MAC_PACKAGE=$BASE_NAME.dmg
  22. CUR_PATH=$PWD
  23. LOG_FOLDER=$CUR_PATH/log
  24. if [ $OS = "Linux" ]; then
  25. WINE="wine"
  26. WINE_DRIVE="$HOME/.wine/drive_c"
  27. WINE_PROGRAM_FILES="$WINE_DRIVE/Program Files"
  28. fi
  29. if [ $OS = "Darwin" ]; then
  30. WINE="/Applications/Wine.app/Contents/Resources/bin/wine"
  31. WINE_DRIVE="$HOME/Wine Files/drive_c"
  32. WINE_PROGRAM_FILES="$WINE_DRIVE/Program Files"
  33. fi
  34. export OS
  35. export VERSION
  36. export VERSION_STR
  37. export SVN_REVISION
  38. # execute command and stop if fails
  39. startCommand()
  40. {
  41. echo " -Starting command: $1"
  42. error=0
  43. eval "$1" || error=1
  44. if [ $error = 1 -a -z "$2" ]; then
  45. echo "***************************************************"
  46. echo "*** Error when evaluing command: $1"
  47. echo "***************************************************"
  48. finish 1
  49. fi
  50. }
  51. # delete existing file/folder $1
  52. deleteIfExists()
  53. {
  54. if [ -d "$1" ]; then
  55. echo "*** Deleting folder: $1"
  56. startCommand "rm -fr \"$1\""
  57. elif [ -f "$1" ]; then
  58. echo "*** Deleting file: $1"
  59. startCommand "rm -f \"$1\""
  60. fi
  61. }
  62. # export a svn path from source $1 to target $2
  63. exportRepository()
  64. {
  65. echo "*** Exporting repository: $1 to $2"
  66. startCommand "cd \"..\""
  67. startCommand "git submodule update --init --recursive > /dev/null 2>&1"
  68. startCommand "cd \"$CUR_PATH\""
  69. startCommand "rsync -a .. \"$2\" --exclude \"$2\" > /dev/null 2>&1"
  70. startCommand "cd \"$2\""
  71. if [ '!' -z "$1" ]; then
  72. startCommand "git clean -f -q -x -d && git reset -q --hard && git checkout -q \"$1\" > /dev/null 2>&1"
  73. else
  74. startCommand "git clean -f -X -q -d > /dev/null 2>&1"
  75. fi
  76. startCommand "cd \"$CUR_PATH\""
  77. startCommand "rm -fr \"$2/.git\""
  78. }
  79. # create a tar.gz file $1 from path $2
  80. createTarGz()
  81. {
  82. echo "*** Creating tar.gz package: $1"
  83. startCommand "tar czf \"$1\" \"$2\""
  84. }
  85. # create a zip file $1 from path $2 and extra parameters $3 and ending parameters $4
  86. createZip()
  87. {
  88. echo "*** Creating zip package: $1"
  89. params=
  90. if [ '!' -z "$3" ]; then
  91. params="$params \"$3\""
  92. fi
  93. if [ '!' -z "$1" ]; then
  94. params="$params \"$1\""
  95. fi
  96. if [ '!' -z "$2" ]; then
  97. params="$params \"$2\""
  98. fi
  99. if [ '!' -z "$4" ]; then
  100. params="$params $4"
  101. fi
  102. startCommand "zip -q -r -9 $params"
  103. }
  104. # crossbuild for windows
  105. crossBuild()
  106. {
  107. QMAKE="qmake"
  108. if [ $OS = "Linux" ]; then
  109. QMAKE="qmake-qt4"
  110. QT_VERSION="4.8.6"
  111. QT_WIN32_VERSION="4.8.3"
  112. QT_PATH="/usr"
  113. MKSPEC="$HOME/.qt/mkspecs/win32-x11-g++"
  114. QT_WIN32_PATH="$WINE_DRIVE/Development/Qt/$QT_WIN32_VERSION"
  115. ISCC="$WINE_PROGRAM_FILES/Inno Setup 5/ISCC.exe"
  116. DLLS_PATH="$WINE_DRIVE/Development/OpenSSL"
  117. fi
  118. if [ $OS = "Darwin" ]; then
  119. QT_VERSION="4.7.0-lgpl"
  120. QT_WIN32_VERSION="4.7.1"
  121. QT_PATH="/usr/local/Trolltech/$QT_VERSION"
  122. MKSPEC="$HOME/mkspecs/4.6.x/win32-osx-g++"
  123. QT_WIN32_PATH="/usr/local/Trolltech/win32/$QT_WIN32_VERSION"
  124. ISCC="$WINE_PROGRAM_FILES/Inno_Setup_5/ISCC.exe"
  125. DLLS_PATH="$HOME/Win32Libraries/bin"
  126. fi
  127. if [ -d "$QT_PATH" ] && [ -d "$MKSPEC" ] && [ -d "$QT_WIN32_PATH" ] && [ -f "$ISCC" ] && [ -d "$DLLS_PATH" ]; then
  128. echo "*** Crossbuilding for windows"
  129. export QT_WIN32_PATH
  130. export QT_WIN32_VERSION
  131. export DLLS_PATH
  132. export CROSS_WIN32_QT_PATH="$QT_WIN32_PATH"
  133. export QT_WINDOWS_PATH="$QT_WIN32_PATH"
  134. startCommand "cd \"$FOLDER_NAME\""
  135. startCommand "make distclean > /dev/null 2>&1" 0
  136. startCommand "\"$QT_PATH/bin/$QMAKE\" -spec \"$MKSPEC\" -win32 -r > /dev/null 2>&1"
  137. startCommand "make distclean > /dev/null 2>&1" 0
  138. startCommand "\"$QT_PATH/bin/$QMAKE\" -spec \"$MKSPEC\" -win32 -r > /dev/null 2>&1"
  139. startCommand "make -j4 > \"$CUR_PATH/log/winbuild.log\" 2>&1"
  140. startCommand "\"$WINE\" \"$ISCC\" \"packages/windows.iss\" > \"$CUR_PATH/log/winpackage.log\" 2>&1"
  141. startCommand "make distclean > /dev/null 2>&1" 0
  142. startCommand "cd \"$CUR_PATH\""
  143. if [ -f "$FOLDER_NAME/packages/$WIN_SETUP" ]; then
  144. startCommand "mv \"$FOLDER_NAME/packages/$WIN_SETUP\" \".\""
  145. fi
  146. fi
  147. }
  148. # create windows zip package
  149. windowsZipPackage()
  150. {
  151. if [ -f "$WIN_SETUP" ]; then
  152. echo "*** Creating windows zip package"
  153. # uninstall previous package
  154. startCommand "find \"$WINE_PROGRAM_FILES/QWBFS Manager\" -name \"unins*.exe\" -print0 | xargs -0 -I {} \"$WINE\" {} /silent > /dev/null 2>&1"
  155. # install the current one
  156. startCommand "\"$WINE\" \"$WIN_SETUP\" /silent > /dev/null 2>&1"
  157. # create zip
  158. startCommand "cp -fr \"$WINE_PROGRAM_FILES/QWBFS Manager\" \"$WIN_FOLDER\""
  159. startCommand "createZip \"$WIN_PACKAGE\" \"$WIN_FOLDER\" \"\" \"-x *unins*.exe -x *unins*.dat\""
  160. startCommand "deleteIfExists \"$WIN_FOLDER\""
  161. # uninstall installed package
  162. startCommand "find \"$WINE_PROGRAM_FILES/QWBFS Manager\" -name \"unins*.exe\" -print0 | xargs -0 -I {} \"$WINE\" {} /silent > /dev/null 2>&1"
  163. fi
  164. }
  165. # create mac os x package
  166. macPackage()
  167. {
  168. echo "*** Create Mac OS X package"
  169. QT_VERSION="4.7.0-lgpl"
  170. BUNDLE_NAME="QWBFSManager"
  171. BUNDLE_PATH="bin"
  172. BUNDLE_APP_PATH="$BUNDLE_PATH/$BUNDLE_NAME.app"
  173. QT_PATH="/usr/local/Trolltech/$QT_VERSION"
  174. QMAKE_FLAGS="\"CONFIG *= universal no_fresh_install\""
  175. # qt4-mac package mac port qt4 support
  176. if [ ! -d "$QT_PATH" ]; then
  177. QT_VERSION=""
  178. QT_PATH="/opt/local"
  179. QMAKE_FLAGS="\"CONFIG *= no_fresh_install\""
  180. fi
  181. startCommand "cd \"$FOLDER_NAME\""
  182. startCommand "make distclean > /dev/null 2>&1" 0
  183. startCommand "\"$QT_PATH/bin/qmake\" $QMAKE_FLAGS -r > /dev/null 2>&1"
  184. startCommand "make distclean > /dev/null 2>&1" 0
  185. startCommand "\"$QT_PATH/bin/qmake\" $QMAKE_FLAGS -r > /dev/null 2>&1"
  186. startCommand "make -j4 > \"$CUR_PATH/log/macbuild.log\" 2>&1"
  187. startCommand "make install > /dev/null 2>&1"
  188. startCommand "\"$QT_PATH/bin/macdeployqt\" \"$BUNDLE_APP_PATH\" -dmg > /dev/null 2>&1"
  189. startCommand "make distclean > /dev/null 2>&1" 0
  190. startCommand "cd \"$CUR_PATH\""
  191. if [ -f "$FOLDER_NAME/$BUNDLE_PATH/$BUNDLE_NAME.dmg" ]; then
  192. startCommand "mv \"$FOLDER_NAME/$BUNDLE_PATH/$BUNDLE_NAME.dmg\" \"$MAC_PACKAGE\""
  193. fi
  194. }
  195. # startup function
  196. startup()
  197. {
  198. if [ '!' -d "$LOG_FOLDER" ]; then
  199. echo "*** Create log folder"
  200. startCommand "mkdir -p \"$LOG_FOLDER\""
  201. fi
  202. }
  203. # finish function, must not use startCommand or function calling it to avoid possible unfinite loop on errors.
  204. finish()
  205. {
  206. # close wine, WineBottler & X11
  207. if [ $OS = "Darwin" ]; then
  208. startCommand "killall wine > /dev/null 2>&1" 0
  209. startCommand "killall WineBottler > /dev/null 2>&1" 0
  210. startCommand "killall X11.bin > /dev/null 2>&1" 0
  211. fi
  212. # come back to start folder
  213. startCommand "cd \"$CUR_PATH\"" 0
  214. # delete exported repository
  215. startCommand "rm -fr \"$FOLDER_NAME\"" 0
  216. echo "********** Processing release finished - Exit code: $1 **********"
  217. exit $1
  218. }
  219. # startup call
  220. startup
  221. # delete source folder
  222. deleteIfExists "$FOLDER_NAME"
  223. # delete tar.gz source
  224. deleteIfExists "$TAR_GZ_FILE"
  225. # delete zip source
  226. deleteIfExists "$ZIP_FILE"
  227. # delete win setup
  228. deleteIfExists "$WIN_SETUP"
  229. # delete win package
  230. deleteIfExists "$WIN_PACKAGE"
  231. # delete mac package
  232. deleteIfExists "$MAC_PACKAGE"
  233. # export the taggued version to release
  234. exportRepository "$1" "$FOLDER_NAME"
  235. # create tar.gz source
  236. createTarGz "$TAR_GZ_FILE" "$FOLDER_NAME"
  237. # create zip source
  238. createZip "$ZIP_FILE" "$FOLDER_NAME"
  239. # create win setup
  240. crossBuild
  241. # create windows zip package
  242. windowsZipPackage
  243. # darwin specific
  244. if [ $OS = "Darwin" ]; then
  245. echo "*** Mac"
  246. macPackage
  247. fi
  248. # linux specific
  249. if [ $OS = "Linux" ]; then
  250. echo "*** Linux"
  251. fi
  252. # finish call
  253. finish 0