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

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