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

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