You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

makeInstallerOSX.sh 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. #!/bin/sh
  2. #
  3. # This script generates a .dmg file that includes dmdirc
  4. #
  5. # DMDirc - Open Source IRC Client
  6. # Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
  7. #
  8. # Permission is hereby granted, free of charge, to any person obtaining a copy
  9. # of this software and associated documentation files (the "Software"), to deal
  10. # in the Software without restriction, including without limitation the rights
  11. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. # copies of the Software, and to permit persons to whom the Software is
  13. # furnished to do so, subject to the following conditions:
  14. #
  15. # The above copyright notice and this permission notice shall be included in
  16. # all copies or substantial portions of the Software.
  17. #
  18. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. # SOFTWARE.
  25. # Final Name of the installer (without file extention)
  26. INSTALLERNAME=DMDirc
  27. # full name of the file to output to
  28. RUNNAME="${PWD}/${INSTALLERNAME}.dmg"
  29. # Linux needs an entry in fstab to allow normal users to mount things (like a
  30. # dmg image).
  31. # These 2 config vars choose what dir and file we mount so that fstab can be
  32. # correct, these should be full paths, and are ignored on OSX.
  33. # This is the name of the image that gets mounted:
  34. LINUXIMAGE=${PWD}/DMDirc.dmg
  35. # This is the dir we mount it in
  36. LINUXIMAGEDIR=${PWD}/dmg
  37. # fstab entry should read:
  38. # ${LINUXIMAGE} ${LINUXIMAGEDIR} auto users,noauto,loop 0 0
  39. MKISOFS=`which mkisofs`
  40. HDIUTIL=`which hdiutil`
  41. JNIName="libDMDirc-Apple.jnilib"
  42. if [ ! -e "${JNIName}" ]; then
  43. if [ -e "/System/Library/Frameworks/JavaVM.framework/Headers" ]; then
  44. GCC=`which gcc`
  45. ${GCC} -dynamiclib -framework JavaVM -framework Carbon -o ${JNIName} DMDirc-Apple.c -arch x86_64
  46. if [ ! -e "${JNIName}" ]; then
  47. echo "JNI Lib not found and failed to compile. Aborting."
  48. exit 1;
  49. fi;
  50. else
  51. echo "JNI Lib not found, unable to compile on this system. Aborting."
  52. exit 1;
  53. fi;
  54. fi;
  55. if [ "" = "${HDIUTIL}" ]; then
  56. if [ "" != "${MKISOFS}" ]; then
  57. MKISOFS_TEST=`${MKISOFS} --help 2>&1 | grep apple`
  58. if [ "" = "${MKISOFS_TEST}" ]; then
  59. echo "This machine is unable to produce dmg images. Aborting."
  60. exit 1;
  61. fi;
  62. fi;
  63. fi;
  64. # Go!
  65. echo "-----------"
  66. if [ -e "${RUNNAME}" ]; then
  67. echo "Removing existing .dmg file"
  68. rm -Rf ./*.dmg
  69. fi
  70. showHelp() {
  71. echo "This will generate a DMDirc installer for a unix based system."
  72. echo "The following command line arguments are known:"
  73. echo "---------------------"
  74. echo "-h, --help Help information"
  75. echo "-r, --release <version> Generate a file based on an svn tag (or branch with -b aswell)"
  76. echo "-b, --branch Release in -r is a branch "
  77. echo "-p, --plugins <plugins> What plugins to add to the jar file"
  78. echo "-c, --compile Recompile the .jar file"
  79. echo " --jar <file> use <file> as DMDirc.jar"
  80. echo " --current Use the current folder as the base for the build"
  81. echo "-t, --tag <tag> Tag to add to final exe name to distinguish this build from a standard build"
  82. echo "-k, --keep Keep the existing source tree when compiling"
  83. echo " (don't svn update beforehand)"
  84. echo "---------------------"
  85. exit 0;
  86. }
  87. # Check for some CLI params
  88. compileJar="false"
  89. updateSVN="true"
  90. isRelease=""
  91. finalTag=""
  92. BRANCH="0"
  93. plugins=""
  94. location="../../../"
  95. jarfile=""
  96. current=""
  97. while test -n "$1"; do
  98. case "$1" in
  99. --plugins|-p)
  100. shift
  101. plugins=${1}
  102. ;;
  103. --jar)
  104. shift
  105. jarfile=${1}
  106. ;;
  107. --current)
  108. location="../../"
  109. current="1"
  110. ;;
  111. --compile|-c)
  112. compileJar="true"
  113. ;;
  114. --release|-r)
  115. shift
  116. isRelease=${1}
  117. ;;
  118. --tag|-t)
  119. shift
  120. finalTag=${1}
  121. RUNNAME="${PWD}/${INSTALLERNAME}-${1}.dmg"
  122. ;;
  123. --keep|-k)
  124. updateSVN="false"
  125. ;;
  126. --help|-h)
  127. showHelp;
  128. ;;
  129. --branch|-b)
  130. BRANCH="1"
  131. ;;
  132. esac
  133. shift
  134. done
  135. if [ "" = "${current}" ]; then
  136. jarPath="${location}trunk"
  137. else
  138. jarPath="${location}"
  139. fi
  140. if [ "${isRelease}" != "" ]; then
  141. if [ "${BRANCH}" != "0" ]; then
  142. if [ -e "${location}/${isRelease}" ]; then
  143. jarPath="${location}/${isRelease}"
  144. else
  145. echo "Branch "${isRelease}" not found."
  146. exit 1;
  147. fi
  148. else
  149. if [ -e "${location}/${isRelease}" ]; then
  150. jarPath="${location}/${isRelease}"
  151. else
  152. echo "Tag "${isRelease}" not found."
  153. exit 1;
  154. fi
  155. fi
  156. fi
  157. if [ "" = "${jarfile}" ]; then
  158. jarfile=${jarPath}"/dist/DMDirc.jar"
  159. if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
  160. echo "Creating jar.."
  161. OLDPWD=${PWD}
  162. cd ${jarPath}
  163. if [ "${updateSVN}" = "true" ]; then
  164. svn update
  165. fi
  166. rm -Rf build dist
  167. ant jar
  168. if [ ! -e "dist/DMDirc.jar" ]; then
  169. echo "There was an error creating the .jar file. Aborting."
  170. exit 1;
  171. fi;
  172. cd ${OLDPWD}
  173. fi;
  174. elif [ ! -e "${jarfile}" ]; then
  175. echo "Requested Jar file (${jarfile}) does not exist."
  176. exit 1;
  177. fi;
  178. echo "Copying jar (${jarfile}).."
  179. cp ${jarfile} "./DMDirc.jar"
  180. if [ "" != "${plugins}" ]; then
  181. echo "Adding plugins to jar"
  182. ln -sf ${jarPath}"/plugins"
  183. pluginList=""
  184. for plugin in ${plugins}; do
  185. pluginList=${pluginList}" plugins/${plugin}"
  186. done
  187. jar -uvf "DMDirc.jar" ${pluginList}
  188. rm -Rf plugins;
  189. fi
  190. APPDIR="DMDirc.app"
  191. CONTENTSDIR=${APPDIR}/Contents
  192. RESDIR=${CONTENTSDIR}/Resources
  193. MACOSDIR=${CONTENTSDIR}/MacOS
  194. if [ -e "${APPDIR}" ]; then
  195. echo "Removing existing .app directory";
  196. rm -Rf ${APPDIR}
  197. fi;
  198. echo "Creating .app directory"
  199. mkdir -pv ${APPDIR}
  200. mkdir -pv ${CONTENTSDIR}
  201. mkdir -pv ${RESDIR}
  202. mkdir -pv ${RESDIR}/Java
  203. mkdir -pv ${MACOSDIR}
  204. echo "Creating meta files"
  205. echo "APPLDMDI" > ${CONTENTSDIR}/PkgInfo
  206. if [ "${isRelease}" != "" ]; then
  207. if [ "${BRANCH}" = "1" ]; then
  208. bundleVersion=branch-${isRelease}
  209. else
  210. bundleVersion=${isRelease}
  211. fi
  212. else
  213. bundleVersion="trunk-"`date +%Y%m%d_%H%M%S`
  214. fi;
  215. cat <<EOF> ${CONTENTSDIR}/Info.plist
  216. <?xml version="1.0" encoding="UTF-8"?>
  217. <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
  218. <plist version="0.9">
  219. <dict>
  220. <key>CFBundleName</key>
  221. <string>DMDirc</string>
  222. <key>CFBundleIdentifier</key>
  223. <string>com.dmdirc.osx</string>
  224. <key>CFBundleAllowMixedLocalizations</key>
  225. <string>true</string>
  226. <key>CFBundleExecutable</key>
  227. <string>DMDirc.sh</string>
  228. <key>CFBundleDevelopmentRegion</key>
  229. <string>English</string>
  230. <key>CFBundlePackageType</key>
  231. <string>APPL</string>
  232. <key>CFBundleSignature</key>
  233. <string>DMDI</string>
  234. <key>CFBundleInfoDictionaryVersion</key>
  235. <string>6.0</string>
  236. <key>CFBundleIconFile</key>
  237. <string>dmdirc.icns</string>
  238. <key>CFBundleVersion</key>
  239. <string>${bundleVersion}</string>
  240. <key>CFBundleShortVersionString</key>
  241. <string>${bundleVersion}</string>
  242. <key>Java</key>
  243. <dict>
  244. <key>WorkingDirectory</key>
  245. <string>\$APP_PACKAGE/Contents/Resources/Java</string>
  246. <key>MainClass</key>
  247. <string>com.dmdirc.Main</string>
  248. <key>JVMVersion</key>
  249. <string>1.6+</string>
  250. <key>ClassPath</key>
  251. <string>\$JAVAROOT/DMDirc.jar</string>
  252. </dict>
  253. <key>CFBundleURLTypes</key>
  254. <array>
  255. <dict>
  256. <key>CFBundleURLName</key>
  257. <string>IRC URL</string>
  258. <key>CFBundleURLSchemes</key>
  259. <array>
  260. <string>irc</string>
  261. </array>
  262. </dict>
  263. </array>
  264. </dict>
  265. </plist>
  266. EOF
  267. # <key>Properties</key>
  268. # <dict>
  269. # <key>com.apple.mrj.application.growbox.intrudes</key>
  270. # <string>false</string>
  271. # <key>com.apple.mrj.application.live-resize</key>
  272. # <string>true</string>
  273. # <key>com.apple.mrj.application.apple.menu.about.name</key>
  274. # <string>DMDirc</string>
  275. # <key>apple.laf.useScreenMenuBar</key>
  276. # <string>true</string>
  277. # </dict>
  278. cp DMDirc.jar ${RESDIR}/Java/DMDirc.jar
  279. cp ${JNIName} ${RESDIR}/Java/${JNIName}
  280. #if [ -e "../common/installer.jar" ]; then
  281. # ln -sf ../common/installer.jar ./installer.jar
  282. # FILES="${FILES} installer.jar"
  283. #else
  284. # echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  285. #fi
  286. if [ -e ${jarPath}"/installer/osx/res/dmdirc.icns" ]; then
  287. cp ${jarPath}"/installer/osx/res/dmdirc.icns" ${RESDIR}/dmdirc.icns
  288. fi
  289. if [ "${isRelease}" != "" ]; then
  290. DOCSDIR=${jarPath}
  291. else
  292. DOCSDIR="../common"
  293. fi
  294. if [ -e "${DOCSDIR}/README.TXT" ]; then
  295. cp "${DOCSDIR}/README.TXT" ${RESDIR}/README.TXT
  296. fi
  297. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  298. cp "${DOCSDIR}/CHANGES.TXT" ${RESDIR}/CHANGES.TXT
  299. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  300. cp "${DOCSDIR}/CHANGELOG.TXT" ${RESDIR}/CHANGELOG.TXT
  301. fi
  302. if [ -e "${jarPath}/launcher/osx" ]; then
  303. cp ${jarPath}/launcher/osx/DMDirc.sh ${MACOSDIR}/DMDirc.sh
  304. chmod a+x ${MACOSDIR}/DMDirc.sh
  305. fi
  306. echo "Packaging.."
  307. # Create RUNNAME
  308. # Create temp dir
  309. DMG=package
  310. if [ -e ${DMG} ]; then
  311. rm -Rf ${DMG}
  312. fi;
  313. mkdir ${DMG}
  314. # Copy the application
  315. mv ${APPDIR} ${DMG}/
  316. # link to /Applications to allow easy drag and drop
  317. ln -sf /Applications ${DMG}/
  318. if [ -e ${jarPath}"/installer/osx/res/VolumeIcon.icns" ]; then
  319. cp -v ${jarPath}"/installer/osx/res/VolumeIcon.icns" ${DMG}/.VolumeIcon.icns
  320. fi
  321. if [ -e ${jarPath}"/installer/osx/res/Background.png" ]; then
  322. mkdir ${DMG}/.background
  323. cp -v ${jarPath}"/installer/osx/res/Background.png" ${DMG}/.background/background.png
  324. fi
  325. if [ -e ${PWD}/.DS_Store ]; then
  326. cp -v ${PWD}/.DS_Store ${DMG}/.DS_Store
  327. fi
  328. # Now, make a dmg
  329. if [ "" = "${HDIUTIL}" ]; then
  330. # Make sure the variables are set
  331. if [ "" = "${LINUXIMAGEDIR}" ]; then
  332. LINUXIMAGEDIR=${PWD}/dmg
  333. fi;
  334. if [ "" = "${LINUXIMAGED}" ]; then
  335. LINUXIMAGE=${PWD}/DMDirc.dmg
  336. fi;
  337. # Non-OSX
  338. # Create Read-Only blessed image
  339. ${MKISOFS} -V 'DMDirc' -no-pad -r -apple -o "${LINUXIMAGE}" -hfs-creator "DMDI" -hfs-bless "/Volumes/DMDirc" "${DMG}"
  340. # Compres it \o
  341. if [ ! -e "${PWD}/compress-dmg" ]; then
  342. wget http://binary.dmdirc.com/dmg -O compress-dmg
  343. chmod a+x compress-dmg
  344. fi;
  345. if [ ! -e "${PWD}/compress-dmg" ]; then
  346. echo "DMG will not be compressed."
  347. else
  348. echo "Compressing DMG"
  349. mv ${LINUXIMAGE} ${LINUXIMAGE}.pre
  350. ${PWD}/compress-dmg dmg ${LINUXIMAGE}.pre ${LINUXIMAGE}
  351. if [ -e ${LINUXIMAGE} ]; then
  352. rm -Rf ${LINUXIMAGE}.pre
  353. else
  354. echo "Compression failed."
  355. mv ${LINUXIMAGE}.pre ${LINUXIMAGE}
  356. fi;
  357. fi;
  358. if [ "${LINUXIMAGE}" != "${RUNNAME}" ]; then
  359. # Rename the image
  360. mv ${LINUXIMAGE} ${RUNNAME}
  361. fi;
  362. else
  363. # OSX
  364. # Create Read/Write image
  365. ${HDIUTIL} create -volname "DMDirc" -fs HFS+ -srcfolder ${DMG} -format UDRW ${RUNNAME}.RW.dmg
  366. # Make it auto-open
  367. BLESS=`which bless`
  368. if [ "" != "${BLESS}" ]; then
  369. if [ -e /Volumes/DMDirc ]; then
  370. ${HDIUTIL} detach /Volumes/DMDirc
  371. fi;
  372. if [ ! -e /Volumes/DMDirc ]; then
  373. ${HDIUTIL} attach ${RUNNAME}.RW.dmg
  374. ${BLESS} -openfolder /Volumes/DMDirc
  375. ${HDIUTIL} detach /Volumes/DMDirc
  376. fi;
  377. fi;
  378. # Convert to compressed read-only image
  379. ${HDIUTIL} convert ${RUNNAME}.RW.dmg -format UDZO -imagekey zlib-level=9 -o ${RUNNAME}
  380. rm ${RUNNAME}.RW.dmg
  381. fi;
  382. echo "DMG Creation complete!"
  383. if [ "${isRelease}" != "" ]; then
  384. if [ "${BRANCH}" = "1" ]; then
  385. isRelease=branch-${isRelease}
  386. fi;
  387. if [ "" != "${finalTag}" ]; then
  388. finalTag="-${finalTag}"
  389. fi;
  390. finalname=DMDirc-${isRelease}${finalTag}.dmg
  391. else
  392. finalname=${RUNNAME##*/}
  393. fi;
  394. mv ${RUNNAME} ../output/${finalname}
  395. rm -Rfv ${DMG} ${APPDIR} ${DMGMOUNTDIR} DMDirc.jar
  396. echo "-----------"
  397. echo "Done."
  398. echo "-----------"
  399. # and Done \o
  400. exit 0;