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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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 (no support from mkisofs). Aborting."
  60. exit 1;
  61. fi;
  62. else
  63. echo "This machine is unable to produce dmg images (missing mkisofs or hdiutil). Aborting."
  64. exit 1;
  65. fi;
  66. fi;
  67. # Go!
  68. echo "-----------"
  69. if [ -e "${RUNNAME}" ]; then
  70. echo "Removing existing .dmg file"
  71. rm -Rf ./*.dmg
  72. fi
  73. WGET=`which wget`
  74. FETCH=`which fetch`
  75. CURL=`which curl`
  76. getFile() {
  77. URL=${1}
  78. OUTPUT=${2}
  79. if [ "${WGET}" != "" ]; then
  80. ${WGET} -O ${OUTPUT} ${URL}
  81. elif [ "${FETCH}" != "" ]; then
  82. ${FETCH} -o ${OUTPUT} ${URL}
  83. elif [ "${CURL}" != "" ]; then
  84. ${CURL} -o ${OUTPUT} ${URL}
  85. fi;
  86. }
  87. showHelp() {
  88. echo "This will generate a DMDirc installer for a unix based system."
  89. echo "The following command line arguments are known:"
  90. echo "---------------------"
  91. echo "-h, --help Help information"
  92. echo "-r, --release <version> Generate a file based on an svn tag (or branch with -b aswell)"
  93. echo "-b, --branch Release in -r is a branch "
  94. echo "-p, --plugins <plugins> What plugins to add to the jar file"
  95. echo "-c, --compile Recompile the .jar file"
  96. echo " --jar <file> use <file> as DMDirc.jar"
  97. echo " --current Use the current folder as the base for the build"
  98. echo "-t, --tag <tag> Tag to add to final exe name to distinguish this build from a standard build"
  99. echo "-k, --keep Keep the existing source tree when compiling"
  100. echo " (don't svn update beforehand)"
  101. echo "---------------------"
  102. exit 0;
  103. }
  104. # Check for some CLI params
  105. compileJar="false"
  106. updateSVN="true"
  107. isRelease=""
  108. finalTag=""
  109. BRANCH="0"
  110. plugins=""
  111. location="../../../"
  112. jarfile=""
  113. current=""
  114. while test -n "$1"; do
  115. case "$1" in
  116. --plugins|-p)
  117. shift
  118. plugins=${1}
  119. ;;
  120. --jar)
  121. shift
  122. jarfile=${1}
  123. ;;
  124. --current)
  125. location="../../"
  126. current="1"
  127. ;;
  128. --compile|-c)
  129. compileJar="true"
  130. ;;
  131. --release|-r)
  132. shift
  133. isRelease=${1}
  134. ;;
  135. --tag|-t)
  136. shift
  137. finalTag=${1}
  138. RUNNAME="${PWD}/${INSTALLERNAME}-${1}.dmg"
  139. ;;
  140. --keep|-k)
  141. updateSVN="false"
  142. ;;
  143. --help|-h)
  144. showHelp;
  145. ;;
  146. --branch|-b)
  147. BRANCH="1"
  148. ;;
  149. esac
  150. shift
  151. done
  152. if [ "" = "${current}" ]; then
  153. jarPath="${location}trunk"
  154. else
  155. jarPath="${location}"
  156. fi
  157. if [ "${isRelease}" != "" ]; then
  158. if [ "${BRANCH}" != "0" ]; then
  159. if [ -e "${location}/${isRelease}" ]; then
  160. jarPath="${location}/${isRelease}"
  161. else
  162. echo "Branch "${isRelease}" not found."
  163. exit 1;
  164. fi
  165. else
  166. if [ -e "${location}/${isRelease}" ]; then
  167. jarPath="${location}/${isRelease}"
  168. else
  169. echo "Tag "${isRelease}" not found."
  170. exit 1;
  171. fi
  172. fi
  173. fi
  174. if [ "" = "${jarfile}" ]; then
  175. jarfile=${jarPath}"/dist/DMDirc.jar"
  176. if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
  177. echo "Creating jar.."
  178. OLDPWD=${PWD}
  179. cd ${jarPath}
  180. if [ "${updateSVN}" = "true" ]; then
  181. svn update
  182. fi
  183. rm -Rf build dist
  184. ant jar
  185. if [ ! -e "dist/DMDirc.jar" ]; then
  186. echo "There was an error creating the .jar file. Aborting."
  187. exit 1;
  188. fi;
  189. cd ${OLDPWD}
  190. fi;
  191. elif [ ! -e "${jarfile}" ]; then
  192. echo "Requested Jar file (${jarfile}) does not exist."
  193. exit 1;
  194. fi;
  195. echo "Copying jar (${jarfile}).."
  196. cp ${jarfile} "./DMDirc.jar"
  197. if [ "" != "${plugins}" ]; then
  198. echo "Adding plugins to jar"
  199. ln -sf ${jarPath}"/plugins"
  200. pluginList=""
  201. for plugin in ${plugins}; do
  202. pluginList=${pluginList}" plugins/${plugin}"
  203. done
  204. jar -uvf "DMDirc.jar" ${pluginList}
  205. rm -Rf plugins;
  206. fi
  207. APPDIR="DMDirc.app"
  208. CONTENTSDIR=${APPDIR}/Contents
  209. RESDIR=${CONTENTSDIR}/Resources
  210. MACOSDIR=${CONTENTSDIR}/MacOS
  211. if [ -e "${APPDIR}" ]; then
  212. echo "Removing existing .app directory";
  213. rm -Rf ${APPDIR}
  214. fi;
  215. echo "Creating .app directory"
  216. mkdir -pv ${APPDIR}
  217. mkdir -pv ${CONTENTSDIR}
  218. mkdir -pv ${RESDIR}
  219. mkdir -pv ${RESDIR}/Java
  220. mkdir -pv ${MACOSDIR}
  221. echo "Creating meta files"
  222. echo "APPLDMDI" > ${CONTENTSDIR}/PkgInfo
  223. if [ "${isRelease}" != "" ]; then
  224. if [ "${BRANCH}" = "1" ]; then
  225. bundleVersion=branch-${isRelease}
  226. else
  227. bundleVersion=${isRelease}
  228. fi
  229. else
  230. bundleVersion="trunk-"`date +%Y%m%d_%H%M%S`
  231. fi;
  232. cat <<EOF> ${CONTENTSDIR}/Info.plist
  233. <?xml version="1.0" encoding="UTF-8"?>
  234. <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
  235. <plist version="0.9">
  236. <dict>
  237. <key>CFBundleName</key>
  238. <string>DMDirc</string>
  239. <key>CFBundleIdentifier</key>
  240. <string>com.dmdirc.osx</string>
  241. <key>CFBundleAllowMixedLocalizations</key>
  242. <string>true</string>
  243. <key>CFBundleExecutable</key>
  244. <string>DMDirc.sh</string>
  245. <key>CFBundleDevelopmentRegion</key>
  246. <string>English</string>
  247. <key>CFBundlePackageType</key>
  248. <string>APPL</string>
  249. <key>CFBundleSignature</key>
  250. <string>DMDI</string>
  251. <key>CFBundleInfoDictionaryVersion</key>
  252. <string>6.0</string>
  253. <key>CFBundleIconFile</key>
  254. <string>dmdirc.icns</string>
  255. <key>CFBundleVersion</key>
  256. <string>${bundleVersion}</string>
  257. <key>CFBundleShortVersionString</key>
  258. <string>${bundleVersion}</string>
  259. <key>Java</key>
  260. <dict>
  261. <key>WorkingDirectory</key>
  262. <string>\$APP_PACKAGE/Contents/Resources/Java</string>
  263. <key>MainClass</key>
  264. <string>com.dmdirc.Main</string>
  265. <key>JVMVersion</key>
  266. <string>1.6+</string>
  267. <key>ClassPath</key>
  268. <string>\$JAVAROOT/DMDirc.jar</string>
  269. </dict>
  270. <key>CFBundleURLTypes</key>
  271. <array>
  272. <dict>
  273. <key>CFBundleURLName</key>
  274. <string>IRC URL</string>
  275. <key>CFBundleURLSchemes</key>
  276. <array>
  277. <string>irc</string>
  278. </array>
  279. </dict>
  280. </array>
  281. </dict>
  282. </plist>
  283. EOF
  284. # <key>Properties</key>
  285. # <dict>
  286. # <key>com.apple.mrj.application.growbox.intrudes</key>
  287. # <string>false</string>
  288. # <key>com.apple.mrj.application.live-resize</key>
  289. # <string>true</string>
  290. # <key>com.apple.mrj.application.apple.menu.about.name</key>
  291. # <string>DMDirc</string>
  292. # <key>apple.laf.useScreenMenuBar</key>
  293. # <string>true</string>
  294. # </dict>
  295. cp DMDirc.jar ${RESDIR}/Java/DMDirc.jar
  296. cp ${JNIName} ${RESDIR}/Java/${JNIName}
  297. #if [ -e "../common/installer.jar" ]; then
  298. # ln -sf ../common/installer.jar ./installer.jar
  299. # FILES="${FILES} installer.jar"
  300. #else
  301. # echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  302. #fi
  303. if [ -e ${jarPath}"/installer/osx/res/dmdirc.icns" ]; then
  304. cp ${jarPath}"/installer/osx/res/dmdirc.icns" ${RESDIR}/dmdirc.icns
  305. fi
  306. if [ "${isRelease}" != "" ]; then
  307. DOCSDIR=${jarPath}
  308. else
  309. DOCSDIR="../common"
  310. fi
  311. if [ -e "${DOCSDIR}/README.TXT" ]; then
  312. cp "${DOCSDIR}/README.TXT" ${RESDIR}/README.TXT
  313. fi
  314. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  315. cp "${DOCSDIR}/CHANGES.TXT" ${RESDIR}/CHANGES.TXT
  316. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  317. cp "${DOCSDIR}/CHANGELOG.TXT" ${RESDIR}/CHANGELOG.TXT
  318. fi
  319. if [ -e "${jarPath}/launcher/unix" ]; then
  320. cp ${jarPath}/launcher/unix/DMDirc.sh ${MACOSDIR}/DMDirc.sh
  321. chmod a+x ${MACOSDIR}/DMDirc.sh
  322. fi
  323. echo "Packaging.."
  324. # Create RUNNAME
  325. # Create temp dir
  326. DMG=package
  327. if [ -e ${DMG} ]; then
  328. rm -Rf ${DMG}
  329. fi;
  330. mkdir ${DMG}
  331. # Copy the application
  332. mv ${APPDIR} ${DMG}/
  333. # link to /Applications to allow easy drag and drop
  334. ln -sf /Applications ${DMG}/
  335. if [ -e ${jarPath}"/installer/osx/res/VolumeIcon.icns" ]; then
  336. cp -v ${jarPath}"/installer/osx/res/VolumeIcon.icns" ${DMG}/.VolumeIcon.icns
  337. fi
  338. if [ -e ${jarPath}"/installer/osx/res/Background.png" ]; then
  339. mkdir ${DMG}/.background
  340. cp -v ${jarPath}"/installer/osx/res/Background.png" ${DMG}/.background/background.png
  341. fi
  342. if [ -e ${PWD}/.DS_Store ]; then
  343. cp -v ${PWD}/.DS_Store ${DMG}/.DS_Store
  344. fi
  345. # Now, make a dmg
  346. if [ "" = "${HDIUTIL}" ]; then
  347. # Make sure the variables are set
  348. if [ "" = "${LINUXIMAGEDIR}" ]; then
  349. LINUXIMAGEDIR=${PWD}/dmg
  350. fi;
  351. if [ "" = "${LINUXIMAGED}" ]; then
  352. LINUXIMAGE=${PWD}/DMDirc.dmg
  353. fi;
  354. # Non-OSX
  355. # Create Read-Only blessed image
  356. ${MKISOFS} -V 'DMDirc' -no-pad -r -apple -o "${LINUXIMAGE}" -hfs-creator "DMDI" -hfs-bless "/Volumes/DMDirc" "${DMG}"
  357. # Compres it \o
  358. if [ ! -e "${PWD}/compress-dmg" ]; then
  359. getFile "http://binary.dmdirc.com/dmg" "compress-dmg"
  360. chmod a+x compress-dmg
  361. fi;
  362. if [ ! -e "${PWD}/compress-dmg" ]; then
  363. echo "DMG will not be compressed."
  364. else
  365. echo "Compressing DMG"
  366. mv ${LINUXIMAGE} ${LINUXIMAGE}.pre
  367. ${PWD}/compress-dmg dmg ${LINUXIMAGE}.pre ${LINUXIMAGE}
  368. if [ -e ${LINUXIMAGE} ]; then
  369. rm -Rf ${LINUXIMAGE}.pre
  370. else
  371. echo "Compression failed."
  372. mv ${LINUXIMAGE}.pre ${LINUXIMAGE}
  373. fi;
  374. fi;
  375. if [ "${LINUXIMAGE}" != "${RUNNAME}" ]; then
  376. # Rename the image
  377. mv ${LINUXIMAGE} ${RUNNAME}
  378. fi;
  379. else
  380. # OSX
  381. # Create Read/Write image
  382. ${HDIUTIL} create -volname "DMDirc" -fs HFS+ -srcfolder ${DMG} -format UDRW ${RUNNAME}.RW.dmg
  383. # Make it auto-open
  384. BLESS=`which bless`
  385. if [ "" != "${BLESS}" ]; then
  386. if [ -e /Volumes/DMDirc ]; then
  387. ${HDIUTIL} detach /Volumes/DMDirc
  388. fi;
  389. if [ ! -e /Volumes/DMDirc ]; then
  390. ${HDIUTIL} attach ${RUNNAME}.RW.dmg
  391. ${BLESS} -openfolder /Volumes/DMDirc
  392. ${HDIUTIL} detach /Volumes/DMDirc
  393. fi;
  394. fi;
  395. # Convert to compressed read-only image
  396. ${HDIUTIL} convert ${RUNNAME}.RW.dmg -format UDZO -imagekey zlib-level=9 -o ${RUNNAME}
  397. rm ${RUNNAME}.RW.dmg
  398. fi;
  399. echo "DMG Creation complete!"
  400. if [ "${isRelease}" != "" ]; then
  401. if [ "${BRANCH}" = "1" ]; then
  402. isRelease=branch-${isRelease}
  403. fi;
  404. if [ "" != "${finalTag}" ]; then
  405. finalTag="-${finalTag}"
  406. fi;
  407. finalname=DMDirc-${isRelease}${finalTag}.dmg
  408. else
  409. finalname=${RUNNAME##*/}
  410. fi;
  411. mv ${RUNNAME} ../output/${finalname}
  412. rm -Rfv ${DMG} ${APPDIR} ${DMGMOUNTDIR} DMDirc.jar
  413. echo "-----------"
  414. echo "Done."
  415. echo "-----------"
  416. # and Done \o
  417. exit 0;