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

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