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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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-2010 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 as well)"
  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. if [ ${isSVN} -eq 1 ]; then
  164. REGEX="^[0-9]+(\.[0-9]+(\.[0-9]+)?)?$"
  165. CHECKTAG=`echo ${1} | egrep "${REGEX}"`
  166. if [ "" = "${CHECKTAG}" ]; then
  167. echo "Specified tag ("${1}") is invalid."
  168. exit 1;
  169. fi;
  170. TAGGED="${1}"
  171. else
  172. TAGGED=`git describe --tags`
  173. TAGGED=${TAGGED%%-*}
  174. fi;
  175. ;;
  176. esac
  177. shift
  178. done
  179. if [ "" = "${current}" ]; then
  180. jarPath="${location}trunk"
  181. else
  182. jarPath="${location}"
  183. fi
  184. if [ "${isRelease}" != "" ]; then
  185. if [ $isSVN -eq 1 ]; then
  186. if [ "${BRANCH}" != "0" ]; then
  187. if [ -e "${location}/${isRelease}" ]; then
  188. jarPath="${location}/${isRelease}"
  189. else
  190. echo "Branch "${isRelease}" not found."
  191. exit 1;
  192. fi
  193. else
  194. if [ -e "${location}/${isRelease}" ]; then
  195. jarPath="${location}/${isRelease}"
  196. else
  197. echo "Tag "${isRelease}" not found."
  198. exit 1;
  199. fi
  200. fi
  201. fi
  202. fi
  203. if [ "" = "${jarfile}" ]; then
  204. jarfile=${jarPath}"/dist/DMDirc.jar"
  205. if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
  206. echo "Creating jar.."
  207. OLDPWD=${PWD}
  208. cd ${jarPath}
  209. if [ "${updateSVN}" = "true" ]; then
  210. svn update
  211. fi
  212. rm -Rf build dist
  213. ant jar
  214. if [ ! -e "dist/DMDirc.jar" ]; then
  215. echo "There was an error creating the .jar file. Aborting."
  216. exit 1;
  217. fi;
  218. cd ${OLDPWD}
  219. fi;
  220. elif [ ! -e "${jarfile}" ]; then
  221. echo "Requested Jar file (${jarfile}) does not exist."
  222. exit 1;
  223. fi;
  224. echo "Copying jar (${jarfile}).."
  225. cp ${jarfile} "./DMDirc.jar"
  226. if [ "" != "${plugins}" ]; then
  227. echo "Adding plugins to jar"
  228. ln -sf ${jarPath}"/plugins"
  229. pluginList=""
  230. for plugin in ${plugins}; do
  231. pluginList=${pluginList}" plugins/${plugin}"
  232. done
  233. jar -uvf "DMDirc.jar" ${pluginList}
  234. rm -Rf plugins;
  235. fi
  236. APPDIR="DMDirc.app"
  237. CONTENTSDIR=${APPDIR}/Contents
  238. RESDIR=${CONTENTSDIR}/Resources
  239. MACOSDIR=${CONTENTSDIR}/MacOS
  240. if [ -e "${APPDIR}" ]; then
  241. echo "Removing existing .app directory";
  242. rm -Rf ${APPDIR}
  243. fi;
  244. echo "Creating .app directory"
  245. mkdir -pv ${APPDIR}
  246. mkdir -pv ${CONTENTSDIR}
  247. mkdir -pv ${RESDIR}
  248. mkdir -pv ${RESDIR}/Java
  249. mkdir -pv ${MACOSDIR}
  250. echo "Creating meta files"
  251. echo "APPLDMDI" > ${CONTENTSDIR}/PkgInfo
  252. doRename=0
  253. if [ "${isRelease}" != "" ]; then
  254. doRename=1
  255. elif [ $isSVN -eq 0 -a "${TAGGED}" != "" ]; then
  256. doRename=1
  257. fi;
  258. if [ ${doRename} -eq 1 ]; then
  259. if [ $isSVN -eq 1 ]; then
  260. if [ "${BRANCH}" = "1" ]; then
  261. bundleVersion=branch-${isRelease}
  262. else
  263. bundleVersion=${isRelease}
  264. fi;
  265. else
  266. if [ "${TAGGED}" = "" ]; then
  267. bundleVersion=branch-${isRelease}
  268. else
  269. bundleVersion=${TAGGED}
  270. fi;
  271. fi
  272. else
  273. bundleVersion="trunk-"`date +%Y%m%d_%H%M%S`
  274. fi;
  275. cat <<EOF> ${CONTENTSDIR}/Info.plist
  276. <?xml version="1.0" encoding="UTF-8"?>
  277. <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
  278. <plist version="0.9">
  279. <dict>
  280. <key>CFBundleName</key>
  281. <string>DMDirc</string>
  282. <key>CFBundleIdentifier</key>
  283. <string>com.dmdirc.osx</string>
  284. <key>CFBundleAllowMixedLocalizations</key>
  285. <string>true</string>
  286. <key>CFBundleExecutable</key>
  287. <string>DMDirc.sh</string>
  288. <key>CFBundleDevelopmentRegion</key>
  289. <string>English</string>
  290. <key>CFBundlePackageType</key>
  291. <string>APPL</string>
  292. <key>CFBundleSignature</key>
  293. <string>DMDI</string>
  294. <key>CFBundleInfoDictionaryVersion</key>
  295. <string>6.0</string>
  296. <key>CFBundleIconFile</key>
  297. <string>dmdirc.icns</string>
  298. <key>CFBundleVersion</key>
  299. <string>${bundleVersion}</string>
  300. <key>CFBundleShortVersionString</key>
  301. <string>${bundleVersion}</string>
  302. <key>Java</key>
  303. <dict>
  304. <key>WorkingDirectory</key>
  305. <string>\$APP_PACKAGE/Contents/Resources/Java</string>
  306. <key>MainClass</key>
  307. <string>com.dmdirc.Main</string>
  308. <key>JVMVersion</key>
  309. <string>1.6+</string>
  310. <key>ClassPath</key>
  311. <string>\$JAVAROOT/DMDirc.jar</string>
  312. </dict>
  313. <key>CFBundleURLTypes</key>
  314. <array>
  315. <dict>
  316. <key>CFBundleURLName</key>
  317. <string>IRC URL</string>
  318. <key>CFBundleURLSchemes</key>
  319. <array>
  320. <string>irc</string>
  321. </array>
  322. </dict>
  323. </array>
  324. </dict>
  325. </plist>
  326. EOF
  327. # <key>Properties</key>
  328. # <dict>
  329. # <key>com.apple.mrj.application.growbox.intrudes</key>
  330. # <string>false</string>
  331. # <key>com.apple.mrj.application.live-resize</key>
  332. # <string>true</string>
  333. # <key>com.apple.mrj.application.apple.menu.about.name</key>
  334. # <string>DMDirc</string>
  335. # <key>apple.laf.useScreenMenuBar</key>
  336. # <string>true</string>
  337. # </dict>
  338. cp DMDirc.jar ${RESDIR}/Java/DMDirc.jar
  339. cp ${JNIName} ${RESDIR}/Java/${JNIName}
  340. #if [ -e "../common/installer.jar" ]; then
  341. # ln -sf ../common/installer.jar ./installer.jar
  342. # FILES="${FILES} installer.jar"
  343. #else
  344. # echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  345. #fi
  346. if [ -e ${jarPath}"/installer/osx/res/dmdirc.icns" ]; then
  347. cp ${jarPath}"/installer/osx/res/dmdirc.icns" ${RESDIR}/dmdirc.icns
  348. fi
  349. if [ "${isRelease}" != "" ]; then
  350. DOCSDIR=${jarPath}
  351. else
  352. DOCSDIR="../common"
  353. fi
  354. if [ -e "${DOCSDIR}/README.TXT" ]; then
  355. cp "${DOCSDIR}/README.TXT" ${RESDIR}/README.TXT
  356. fi
  357. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  358. cp "${DOCSDIR}/CHANGES.TXT" ${RESDIR}/CHANGES.TXT
  359. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  360. cp "${DOCSDIR}/CHANGELOG.TXT" ${RESDIR}/CHANGELOG.TXT
  361. fi
  362. if [ -e "${jarPath}/launcher/unix" ]; then
  363. cp ${jarPath}/launcher/unix/DMDirc.sh ${MACOSDIR}/DMDirc.sh
  364. chmod a+x ${MACOSDIR}/DMDirc.sh
  365. fi
  366. if [ -e "${jarPath}/installer/linux" ]; then
  367. cp ${jarPath}/installer/linux/functions.sh ${MACOSDIR}/functions.sh
  368. else
  369. echo "Unable to find launcher functions, exiting."
  370. exit 1;
  371. fi
  372. echo "Packaging.."
  373. # Create RUNNAME
  374. # Create temp dir
  375. DMG=package
  376. if [ -e ${DMG} ]; then
  377. rm -Rf ${DMG}
  378. fi;
  379. mkdir ${DMG}
  380. # Copy the application
  381. mv ${APPDIR} ${DMG}/
  382. # link to /Applications to allow easy drag and drop
  383. ln -sf /Applications ${DMG}/
  384. if [ -e ${jarPath}"/installer/osx/res/VolumeIcon.icns" ]; then
  385. cp -v ${jarPath}"/installer/osx/res/VolumeIcon.icns" ${DMG}/.VolumeIcon.icns
  386. fi
  387. if [ -e ${jarPath}"/installer/osx/res/Background.png" ]; then
  388. mkdir ${DMG}/.background
  389. cp -v ${jarPath}"/installer/osx/res/Background.png" ${DMG}/.background/background.png
  390. fi
  391. if [ -e ${PWD}/.DS_Store ]; then
  392. cp -v ${PWD}/.DS_Store ${DMG}/.DS_Store
  393. fi
  394. # Now, make a dmg
  395. if [ "" = "${HDIUTIL}" ]; then
  396. # Make sure the variables are set
  397. if [ "" = "${LINUXIMAGEDIR}" ]; then
  398. LINUXIMAGEDIR=${PWD}/dmg
  399. fi;
  400. if [ "" = "${LINUXIMAGED}" ]; then
  401. LINUXIMAGE=${PWD}/DMDirc.dmg
  402. fi;
  403. # Non-OSX
  404. # Create Read-Only blessed image
  405. ${MKISOFS} -V 'DMDirc' -no-pad -r -apple -o "${LINUXIMAGE}" -hfs-creator "DMDI" -hfs-bless "/Volumes/DMDirc" "${DMG}"
  406. # Compres it \o
  407. if [ ! -e "${PWD}/compress-dmg" ]; then
  408. getFile "http://binary.dmdirc.com/dmg" "compress-dmg"
  409. chmod a+x compress-dmg
  410. fi;
  411. if [ ! -e "${PWD}/compress-dmg" ]; then
  412. echo "DMG will not be compressed."
  413. else
  414. echo "Compressing DMG"
  415. mv ${LINUXIMAGE} ${LINUXIMAGE}.pre
  416. ${PWD}/compress-dmg dmg ${LINUXIMAGE}.pre ${LINUXIMAGE}
  417. if [ -e ${LINUXIMAGE} ]; then
  418. rm -Rf ${LINUXIMAGE}.pre
  419. else
  420. echo "Compression failed."
  421. mv ${LINUXIMAGE}.pre ${LINUXIMAGE}
  422. fi;
  423. fi;
  424. if [ "${LINUXIMAGE}" != "${RUNNAME}" ]; then
  425. # Rename the image
  426. mv ${LINUXIMAGE} ${RUNNAME}
  427. fi;
  428. else
  429. # OSX
  430. # Create Read/Write image
  431. ${HDIUTIL} create -volname "DMDirc" -fs HFS+ -srcfolder ${DMG} -format UDRW ${RUNNAME}.RW.dmg
  432. # Make it auto-open
  433. BLESS=`which bless`
  434. if [ "" != "${BLESS}" ]; then
  435. if [ -e /Volumes/DMDirc ]; then
  436. ${HDIUTIL} detach /Volumes/DMDirc
  437. fi;
  438. if [ ! -e /Volumes/DMDirc ]; then
  439. ${HDIUTIL} attach ${RUNNAME}.RW.dmg
  440. ${BLESS} -openfolder /Volumes/DMDirc
  441. ${HDIUTIL} detach /Volumes/DMDirc
  442. fi;
  443. fi;
  444. # Convert to compressed read-only image
  445. ${HDIUTIL} convert ${RUNNAME}.RW.dmg -format UDZO -imagekey zlib-level=9 -o ${RUNNAME}
  446. rm ${RUNNAME}.RW.dmg
  447. fi;
  448. echo "DMG Creation complete!"
  449. if [ ${doRename} -eq 1 ]; then
  450. if [ $isSVN -eq 1 ]; then
  451. if [ "${BRANCH}" = "1" ]; then
  452. isRelease=branch-${isRelease}
  453. fi;
  454. else
  455. if [ "${TAGGED}" = "" ]; then
  456. isRelease=branch-${isRelease}
  457. else
  458. isRelease=${TAGGED}
  459. fi;
  460. fi
  461. if [ "" != "${finalTag}" ]; then
  462. finalTag="-${finalTag}"
  463. fi;
  464. finalname=DMDirc-${isRelease}${finalTag}.dmg
  465. else
  466. finalname=${RUNNAME##*/}
  467. fi;
  468. mv ${RUNNAME} ../output/${finalname}
  469. rm -Rfv ${DMG} ${APPDIR} ${DMGMOUNTDIR} DMDirc.jar
  470. echo "-----------"
  471. echo "Done."
  472. echo "-----------"
  473. # and Done \o
  474. exit 0;