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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. MKHFS=`which mkfs.hfs`
  40. MKHFSPLUS=`which mkfs.hfsplus`
  41. HDIUTIL=`which hdiutil`
  42. JNIName="libDMDirc-Apple.jnilib"
  43. if [ ! -e "${JNIName}" ]; then
  44. if [ -e "/System/Library/Frameworks/JavaVM.framework/Headers" ]; then
  45. GCC=`which gcc`
  46. ${GCC} -dynamiclib -framework JavaVM -framework Carbon -o ${JNIName} DMDirc-Apple.c -arch x86_64
  47. if [ ! -e "${JNIName}" ]; then
  48. echo "JNI Lib not found and failed to compile. Aborting."
  49. exit 1;
  50. fi;
  51. else
  52. echo "JNI Lib not found, unable to compile on this system. Aborting."
  53. exit 1;
  54. fi;
  55. fi;
  56. if [ "" = "${HDIUTIL}" ]; then
  57. if [ "" = "${MKHFS}" -a "" = "${MKHFSPLUS}" ]; then
  58. echo "This machine is unable to produce dmg images. Aborting."
  59. exit 1;
  60. fi;
  61. fi;
  62. # Go!
  63. echo "-----------"
  64. if [ -e "${RUNNAME}" ]; then
  65. echo "Removing existing .dmg file"
  66. rm -Rf ./*.dmg
  67. fi
  68. showHelp() {
  69. echo "This will generate a DMDirc installer for a unix based system."
  70. echo "The following command line arguments are known:"
  71. echo "---------------------"
  72. echo "-h, --help Help information"
  73. echo "-r, --release <version> Generate a file based on an svn tag (or branch with -b aswell)"
  74. echo "-b, --branch Release in -r is a branch "
  75. echo "-p, --plugins <plugins> What plugins to add to the jar file"
  76. echo "-c, --compile Recompile the .jar file"
  77. echo " --jar <file> use <file> as DMDirc.jar"
  78. echo " --current Use the current folder as the base for the build"
  79. echo "-t, --tag <tag> Tag to add to final exe name to distinguish this build from a standard build"
  80. echo "-k, --keep Keep the existing source tree when compiling"
  81. echo " (don't svn update beforehand)"
  82. echo "---------------------"
  83. exit 0;
  84. }
  85. # Check for some CLI params
  86. compileJar="false"
  87. updateSVN="true"
  88. isRelease=""
  89. finalTag=""
  90. BRANCH="0"
  91. plugins=""
  92. location="../../../"
  93. jarfile=""
  94. current=""
  95. while test -n "$1"; do
  96. case "$1" in
  97. --plugins|-p)
  98. shift
  99. plugins=${1}
  100. ;;
  101. --jar)
  102. shift
  103. jarfile=${1}
  104. ;;
  105. --current)
  106. location="../../"
  107. current="1"
  108. ;;
  109. --compile|-c)
  110. compileJar="true"
  111. ;;
  112. --release|-r)
  113. shift
  114. isRelease=${1}
  115. ;;
  116. --tag|-t)
  117. shift
  118. finalTag=${1}
  119. RUNNAME="${PWD}/${INSTALLERNAME}-${1}.dmg"
  120. ;;
  121. --keep|-k)
  122. updateSVN="false"
  123. ;;
  124. --help|-h)
  125. showHelp;
  126. ;;
  127. --branch|-b)
  128. BRANCH="1"
  129. ;;
  130. esac
  131. shift
  132. done
  133. if [ "" = "${current}" ]; then
  134. jarPath="${location}trunk"
  135. else
  136. jarPath="${location}"
  137. fi
  138. if [ "${isRelease}" != "" ]; then
  139. if [ "${BRANCH}" != "0" ]; then
  140. if [ -e "${location}/${isRelease}" ]; then
  141. jarPath="${location}/${isRelease}"
  142. else
  143. echo "Branch "${isRelease}" not found."
  144. exit 1;
  145. fi
  146. else
  147. if [ -e "${location}/${isRelease}" ]; then
  148. jarPath="${location}/${isRelease}"
  149. else
  150. echo "Tag "${isRelease}" not found."
  151. exit 1;
  152. fi
  153. fi
  154. fi
  155. if [ "" = "${jarfile}" ]; then
  156. jarfile=${jarPath}"/dist/DMDirc.jar"
  157. if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
  158. echo "Creating jar.."
  159. OLDPWD=${PWD}
  160. cd ${jarPath}
  161. if [ "${updateSVN}" = "true" ]; then
  162. svn update
  163. fi
  164. rm -Rf build dist
  165. ant jar
  166. if [ ! -e "dist/DMDirc.jar" ]; then
  167. echo "There was an error creating the .jar file. Aborting."
  168. exit 1;
  169. fi;
  170. cd ${OLDPWD}
  171. fi;
  172. elif [ ! -e "${jarfile}" ]; then
  173. echo "Requested Jar file (${jarfile}) does not exist."
  174. exit 1;
  175. fi;
  176. echo "Copying jar (${jarfile}).."
  177. cp ${jarfile} "./DMDirc.jar"
  178. if [ "" != "${plugins}" ]; then
  179. echo "Adding plugins to jar"
  180. ln -sf ${jarPath}"/plugins"
  181. pluginList=""
  182. for plugin in ${plugins}; do
  183. pluginList=${pluginList}" plugins/${plugin}"
  184. done
  185. jar -uvf "DMDirc.jar" ${pluginList}
  186. rm -Rf plugins;
  187. fi
  188. APPDIR="DMDirc.app"
  189. CONTENTSDIR=${APPDIR}/Contents
  190. RESDIR=${CONTENTSDIR}/Resources
  191. MACOSDIR=${CONTENTSDIR}/MacOS
  192. if [ -e "${APPDIR}" ]; then
  193. echo "Removing existing .app directory";
  194. rm -Rf ${APPDIR}
  195. fi;
  196. echo "Creating .app directory"
  197. mkdir -pv ${APPDIR}
  198. mkdir -pv ${CONTENTSDIR}
  199. mkdir -pv ${RESDIR}
  200. mkdir -pv ${RESDIR}/Java
  201. mkdir -pv ${MACOSDIR}
  202. echo "Creating meta files"
  203. echo "APPLDMDI" > ${CONTENTSDIR}/PkgInfo
  204. if [ "${isRelease}" != "" ]; then
  205. if [ "${BRANCH}" = "1" ]; then
  206. bundleVersion=branch-${isRelease}
  207. else
  208. bundleVersion=${isRelease}
  209. fi
  210. else
  211. bundleVersion="trunk-"`date +%Y%m%d_%H%M%S`
  212. fi;
  213. cat <<EOF> ${CONTENTSDIR}/Info.plist
  214. <?xml version="1.0" encoding="UTF-8"?>
  215. <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
  216. <plist version="0.9">
  217. <dict>
  218. <key>CFBundleName</key>
  219. <string>DMDirc</string>
  220. <key>CFBundleIdentifier</key>
  221. <string>com.dmdirc.osx</string>
  222. <key>CFBundleAllowMixedLocalizations</key>
  223. <string>true</string>
  224. <key>CFBundleExecutable</key>
  225. <string>DMDirc.sh</string>
  226. <key>CFBundleDevelopmentRegion</key>
  227. <string>English</string>
  228. <key>CFBundlePackageType</key>
  229. <string>APPL</string>
  230. <key>CFBundleSignature</key>
  231. <string>DMDI</string>
  232. <key>CFBundleInfoDictionaryVersion</key>
  233. <string>6.0</string>
  234. <key>CFBundleIconFile</key>
  235. <string>dmdirc.icns</string>
  236. <key>CFBundleVersion</key>
  237. <string>${bundleVersion}</string>
  238. <key>CFBundleShortVersionString</key>
  239. <string>${bundleVersion}</string>
  240. <key>Java</key>
  241. <dict>
  242. <key>WorkingDirectory</key>
  243. <string>\$APP_PACKAGE/Contents/Resources/Java</string>
  244. <key>MainClass</key>
  245. <string>com.dmdirc.Main</string>
  246. <key>JVMVersion</key>
  247. <string>1.6+</string>
  248. <key>ClassPath</key>
  249. <string>\$JAVAROOT/DMDirc.jar</string>
  250. </dict>
  251. <key>CFBundleURLTypes</key>
  252. <array>
  253. <dict>
  254. <key>CFBundleURLName</key>
  255. <string>IRC URL</string>
  256. <key>CFBundleURLSchemes</key>
  257. <array>
  258. <string>irc</string>
  259. </array>
  260. </dict>
  261. </array>
  262. </dict>
  263. </plist>
  264. EOF
  265. # <key>Properties</key>
  266. # <dict>
  267. # <key>com.apple.mrj.application.growbox.intrudes</key>
  268. # <string>false</string>
  269. # <key>com.apple.mrj.application.live-resize</key>
  270. # <string>true</string>
  271. # <key>com.apple.mrj.application.apple.menu.about.name</key>
  272. # <string>DMDirc</string>
  273. # <key>apple.laf.useScreenMenuBar</key>
  274. # <string>true</string>
  275. # </dict>
  276. cp DMDirc.jar ${RESDIR}/Java/DMDirc.jar
  277. cp ${JNIName} ${RESDIR}/Java/${JNIName}
  278. #if [ -e "../common/installer.jar" ]; then
  279. # ln -sf ../common/installer.jar ./installer.jar
  280. # FILES="${FILES} installer.jar"
  281. #else
  282. # echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  283. #fi
  284. if [ -e ${jarPath}"/installer/osx/res/dmdirc.icns" ]; then
  285. cp ${jarPath}"/installer/osx/res/dmdirc.icns" ${RESDIR}/dmdirc.icns
  286. fi
  287. if [ "${isRelease}" != "" ]; then
  288. DOCSDIR=${jarPath}
  289. else
  290. DOCSDIR="../common"
  291. fi
  292. if [ -e "${DOCSDIR}/README.TXT" ]; then
  293. cp "${DOCSDIR}/README.TXT" ${RESDIR}/README.TXT
  294. fi
  295. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  296. cp "${DOCSDIR}/CHANGES.TXT" ${RESDIR}/CHANGES.TXT
  297. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  298. cp "${DOCSDIR}/CHANGELOG.TXT" ${RESDIR}/CHANGELOG.TXT
  299. fi
  300. if [ -e "${jarPath}/launcher/osx" ]; then
  301. cp ${jarPath}/launcher/osx/DMDirc.sh ${MACOSDIR}/DMDirc.sh
  302. chmod a+x ${MACOSDIR}/DMDirc.sh
  303. fi
  304. echo "Packaging.."
  305. # Create RUNNAME
  306. # Create temp dir
  307. DMG=package
  308. if [ -e ${DMG} ]; then
  309. rm -Rf ${DMG}
  310. fi;
  311. mkdir ${DMG}
  312. # Copy the application
  313. mv ${APPDIR} ${DMG}/
  314. # link to /Applications to allow easy drag and drop
  315. ln -sf /Applications ${DMG}/
  316. if [ -e ${jarPath}"/installer/osx/res/VolumeIcon.icns" ]; then
  317. cp -v ${jarPath}"/installer/osx/res/VolumeIcon.icns" ${DMG}/.VolumeIcon.icns
  318. fi
  319. if [ -e ${jarPath}"/installer/osx/res/Background.png" ]; then
  320. mkdir ${DMG}/.background
  321. cp -v ${jarPath}"/installer/osx/res/Background.png" ${DMG}/.background/background.png
  322. fi
  323. if [ -e ${PWD}/.DS_Store ]; then
  324. cp -v ${PWD}/.DS_Store ${DMG}/.DS_Store
  325. fi
  326. # Now, make a dmg
  327. if [ "" = "${HDIUTIL}" ]; then
  328. # Make sure the variables are set
  329. if [ "" = "${LINUXIMAGEDIR}" ]; then
  330. LINUXIMAGEDIR=${PWD}/dmg
  331. fi;
  332. if [ "" = "${LINUXIMAGED}" ]; then
  333. LINUXIMAGE=${PWD}/DMDirc.dmg
  334. fi;
  335. # Non-OSX
  336. # This doesn't work quite aswell as on OSX, but it works.
  337. IMGBLOCKSIZE=4096 # OSX Default = 4096
  338. MVRES=0
  339. createImage() {
  340. MVRES=0
  341. SIZE=${1}
  342. if [ "" = "${MKHFS}" -a "" != "${MKHFSPLUS}" ]; then
  343. MKHFS=${MKHFSPLUS}
  344. fi;
  345. # mkfs.hfs will only create 512kb+ sized images
  346. if [ ${SIZE} -lt 524288 ]; then
  347. echo "Size is less than 512kb"
  348. SIZE=524288;
  349. fi;
  350. dd if=/dev/zero of=${LINUXIMAGE} bs=${SIZE} count=1
  351. ${MKHFS} -b ${IMGBLOCKSIZE} -v 'DMDirc' ${LINUXIMAGE}
  352. if [ ${?} -ne 0 ]; then
  353. echo "mkfs.hfs failed to create the image, aborting."
  354. exit 1;
  355. fi;
  356. # Now try and mount
  357. # This could be a problem, as linux requires either root to mount, or an fstab
  358. # entry.
  359. # Try to mount, if this fails, let the user know what to add to fstab.
  360. if [ -e ${LINUXIMAGEDIR} ]; then
  361. rm -Rf ${LINUXIMAGEDIR}
  362. fi;
  363. mkdir ${LINUXIMAGEDIR}
  364. mount ${LINUXIMAGEDIR}
  365. MOUNTRES=${?}
  366. if [ ${MOUNTRES} -ne 0 ]; then
  367. # Try using full parameters - could be running as root.
  368. mount -t hfsplus -o loop ${RUNNAME} ${LINUXIMAGEDIR}
  369. MOUNTRES=${?}
  370. fi;
  371. if [ ${MOUNTRES} -ne 0 ]; then
  372. echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
  373. echo "@ ERROR @"
  374. echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
  375. echo "You do not have permission to mount the image."
  376. echo "Please add the following lines to /etc/fstab and re run this script again"
  377. echo "# DMDirc OSX dmg image"
  378. echo "${LINUXIMAGE} ${LINUXIMAGEDIR} auto users,noauto,loop 0 0"
  379. echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
  380. echo "@ ERROR @"
  381. echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
  382. exit 1;
  383. fi;
  384. mv -fv ${DMG}/* ${LINUXIMAGEDIR}
  385. MVRES=${?}
  386. if [ ${MVRES} -ne 0 ]; then
  387. echo "Image incorrect size."
  388. else
  389. mv -fv ${DMG}/.[A-Za-z]* ${LINUXIMAGEDIR}
  390. MVRES=${?}
  391. if [ ${MVRES} -ne 0 ]; then
  392. echo "Image incorrect size."
  393. fi;
  394. fi;
  395. umount ${LINUXIMAGEDIR}
  396. # If anyone finds out how to compress these nicely, add it here.
  397. }
  398. INCREASE=10
  399. IMAGESIZE=$(((`du -s --block-size ${IMGBLOCKSIZE} ${DMG} | awk '{print $1}'` + ${INCREASE}) * ${IMGBLOCKSIZE} ))
  400. createImage ${IMAGESIZE}
  401. # This sucks, but it makes sure the image gets created at a size that contains
  402. # everything.
  403. # I can't manage to get du to return the size that the files actually end up
  404. # using on the image.
  405. TRIES=0
  406. while [ ${MVRES} -ne 0 -a ${TRIES} -ne 5 ]; do
  407. TRIES=$((${TRIES} + 1))
  408. echo "Previous ImageSize of ${IMAGESIZE} failed"
  409. INCREASE=$((${INCREASE} + 5))
  410. IMAGESIZE=$(((`du -s --block-size ${IMGBLOCKSIZE} ${DMG} | awk '{print $1}'` + ${INCREASE}) * ${IMGBLOCKSIZE} ))
  411. echo "Trying to build with ImageSize ${IMAGESIZE}"
  412. createImage ${IMAGESIZE}
  413. done;
  414. if [ ${MVRES} -ne 0 ]; then
  415. echo "OSX Build Failed - Imagesize: ${IMAGESIZE}"
  416. exit 1;
  417. fi;
  418. if [ "${LINUXIMAGE}" != "${RUNNAME}" ]; then
  419. # Rename the image
  420. mv ${LINUXIMAGE} ${RUNNAME}
  421. fi;
  422. else
  423. # OSX
  424. # This creates better versions than non-OSX
  425. # Create Read/Write image
  426. ${HDIUTIL} create -volname "DMDirc" -fs HFS+ -srcfolder ${DMG} -format UDRW ${RUNNAME}.RW.dmg
  427. # Make it auto-open
  428. BLESS=`which bless`
  429. if [ "" != "${BLESS}" ]; then
  430. if [ -e /Volumes/DMDirc ]; then
  431. ${HDIUTIL} detach /Volumes/DMDirc
  432. fi;
  433. if [ ! -e /Volumes/DMDirc ]; then
  434. ${HDIUTIL} attach ${RUNNAME}.RW.dmg
  435. ${BLESS} -openfolder /Volumes/DMDirc
  436. ${HDIUTIL} detach /Volumes/DMDirc
  437. fi;
  438. fi;
  439. # Convert to compressed read-only image
  440. ${HDIUTIL} convert ${RUNNAME}.RW.dmg -format UDZO -imagekey zlib-level=9 -o ${RUNNAME}
  441. rm ${RUNNAME}.RW.dmg
  442. fi;
  443. echo "DMG Creation complete!"
  444. if [ "${isRelease}" != "" ]; then
  445. if [ "${BRANCH}" = "1" ]; then
  446. isRelease=branch-${isRelease}
  447. fi;
  448. if [ "" != "${finalTag}" ]; then
  449. finalTag="-${finalTag}"
  450. fi;
  451. finalname=DMDirc-${isRelease}${finalTag}.dmg
  452. else
  453. finalname=${RUNNAME##*/}
  454. fi;
  455. mv ${RUNNAME} ../output/${finalname}
  456. rm -Rfv ${DMG} ${APPDIR} ${DMGMOUNTDIR} DMDirc.jar
  457. echo "-----------"
  458. echo "Done."
  459. echo "-----------"
  460. # and Done \o
  461. exit 0;