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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. # 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. rm -Rf plugins;
  184. fi
  185. APPDIR="DMDirc.app"
  186. CONTENTSDIR=${APPDIR}/Contents
  187. RESDIR=${CONTENTSDIR}/Resources
  188. MACOSDIR=${CONTENTSDIR}/MacOS
  189. if [ -e "${APPDIR}" ]; then
  190. echo "Removing existing .app directory";
  191. rm -Rf ${APPDIR}
  192. fi;
  193. echo "Creating .app directory"
  194. mkdir -pv ${APPDIR}
  195. mkdir -pv ${CONTENTSDIR}
  196. mkdir -pv ${RESDIR}
  197. mkdir -pv ${RESDIR}/Java
  198. mkdir -pv ${MACOSDIR}
  199. echo "Creating meta files"
  200. echo "APPLDMDI" > ${CONTENTSDIR}/PkgInfo
  201. doRename=0
  202. if [ "${TAGGED}" != "" ]; then
  203. doRename=1
  204. fi;
  205. if [ ${doRename} -eq 1 ]; then
  206. if [ "${TAGGED}" = "" ]; then
  207. bundleVersion=branch-${isRelease}
  208. else
  209. bundleVersion=${TAGGED}
  210. fi
  211. else
  212. bundleVersion="trunk-"`date +%Y%m%d_%H%M%S`
  213. fi;
  214. cat <<EOF> ${CONTENTSDIR}/Info.plist
  215. <?xml version="1.0" encoding="UTF-8"?>
  216. <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
  217. <plist version="0.9">
  218. <dict>
  219. <key>CFBundleName</key>
  220. <string>DMDirc</string>
  221. <key>CFBundleIdentifier</key>
  222. <string>com.dmdirc.osx</string>
  223. <key>CFBundleAllowMixedLocalizations</key>
  224. <string>true</string>
  225. <key>CFBundleExecutable</key>
  226. <string>DMDirc.sh</string>
  227. <key>CFBundleDevelopmentRegion</key>
  228. <string>English</string>
  229. <key>CFBundlePackageType</key>
  230. <string>APPL</string>
  231. <key>CFBundleSignature</key>
  232. <string>DMDI</string>
  233. <key>CFBundleInfoDictionaryVersion</key>
  234. <string>6.0</string>
  235. <key>CFBundleIconFile</key>
  236. <string>dmdirc.icns</string>
  237. <key>CFBundleVersion</key>
  238. <string>${bundleVersion}</string>
  239. <key>CFBundleShortVersionString</key>
  240. <string>${bundleVersion}</string>
  241. <key>Java</key>
  242. <dict>
  243. <key>WorkingDirectory</key>
  244. <string>\$APP_PACKAGE/Contents/Resources/Java</string>
  245. <key>MainClass</key>
  246. <string>com.dmdirc.Main</string>
  247. <key>JVMVersion</key>
  248. <string>1.6+</string>
  249. <key>ClassPath</key>
  250. <string>\$JAVAROOT/DMDirc.jar</string>
  251. </dict>
  252. <key>CFBundleURLTypes</key>
  253. <array>
  254. <dict>
  255. <key>CFBundleURLName</key>
  256. <string>IRC URL</string>
  257. <key>CFBundleURLSchemes</key>
  258. <array>
  259. <string>irc</string>
  260. </array>
  261. </dict>
  262. </array>
  263. </dict>
  264. </plist>
  265. EOF
  266. # <key>Properties</key>
  267. # <dict>
  268. # <key>com.apple.mrj.application.growbox.intrudes</key>
  269. # <string>false</string>
  270. # <key>com.apple.mrj.application.live-resize</key>
  271. # <string>true</string>
  272. # <key>com.apple.mrj.application.apple.menu.about.name</key>
  273. # <string>DMDirc</string>
  274. # <key>apple.laf.useScreenMenuBar</key>
  275. # <string>true</string>
  276. # </dict>
  277. cp DMDirc.jar ${RESDIR}/Java/DMDirc.jar
  278. cp ${JNIName} ${RESDIR}/Java/${JNIName}
  279. #if [ -e "../common/installer.jar" ]; then
  280. # ln -sf ../common/installer.jar ./installer.jar
  281. # FILES="${FILES} installer.jar"
  282. #else
  283. # echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  284. #fi
  285. if [ -e ${jarPath}"/installer/osx/res/dmdirc.icns" ]; then
  286. cp ${jarPath}"/installer/osx/res/dmdirc.icns" ${RESDIR}/dmdirc.icns
  287. fi
  288. if [ "${isRelease}" != "" ]; then
  289. DOCSDIR=${jarPath}
  290. else
  291. DOCSDIR="../common"
  292. fi
  293. if [ -e "${DOCSDIR}/README.TXT" ]; then
  294. cp "${DOCSDIR}/README.TXT" ${RESDIR}/README.TXT
  295. fi
  296. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  297. cp "${DOCSDIR}/CHANGES.TXT" ${RESDIR}/CHANGES.TXT
  298. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  299. cp "${DOCSDIR}/CHANGELOG.TXT" ${RESDIR}/CHANGELOG.TXT
  300. fi
  301. if [ -e "${jarPath}/launcher/unix" ]; then
  302. cp ${jarPath}/launcher/unix/DMDirc.sh ${MACOSDIR}/DMDirc.sh
  303. chmod a+x ${MACOSDIR}/DMDirc.sh
  304. fi
  305. if [ -e "${jarPath}/installer/linux" ]; then
  306. cp ${jarPath}/installer/linux/functions.sh ${MACOSDIR}/functions.sh
  307. else
  308. echo "Unable to find launcher functions, exiting."
  309. exit 1;
  310. fi
  311. echo "Packaging.."
  312. # Create RUNNAME
  313. # Create temp dir
  314. DMG=package
  315. if [ -e ${DMG} ]; then
  316. rm -Rf ${DMG}
  317. fi;
  318. mkdir ${DMG}
  319. # Copy the application
  320. mv ${APPDIR} ${DMG}/
  321. # link to /Applications to allow easy drag and drop
  322. ln -sf /Applications ${DMG}/
  323. if [ -e ${jarPath}"/installer/osx/res/VolumeIcon.icns" ]; then
  324. cp -v ${jarPath}"/installer/osx/res/VolumeIcon.icns" ${DMG}/.VolumeIcon.icns
  325. fi
  326. if [ -e ${jarPath}"/installer/osx/res/Background.png" ]; then
  327. mkdir ${DMG}/.background
  328. cp -v ${jarPath}"/installer/osx/res/Background.png" ${DMG}/.background/background.png
  329. fi
  330. if [ -e ${PWD}/.DS_Store ]; then
  331. cp -v ${PWD}/.DS_Store ${DMG}/.DS_Store
  332. fi
  333. # Now, make a dmg
  334. if [ "" = "${HDIUTIL}" ]; then
  335. # Make sure the variables are set
  336. if [ "" = "${LINUXIMAGEDIR}" ]; then
  337. LINUXIMAGEDIR=${PWD}/dmg
  338. fi;
  339. if [ "" = "${LINUXIMAGED}" ]; then
  340. LINUXIMAGE=${PWD}/DMDirc.dmg
  341. fi;
  342. # Non-OSX
  343. # Create Read-Only blessed image
  344. ${MKISOFS} -V 'DMDirc' -no-pad -r -apple -o "${LINUXIMAGE}" -hfs-creator "DMDI" -hfs-bless "/Volumes/DMDirc" "${DMG}"
  345. # Compres it \o
  346. if [ ! -e "${PWD}/compress-dmg" ]; then
  347. getFile "http://binary.dmdirc.com/dmg" "compress-dmg"
  348. chmod a+x compress-dmg
  349. fi;
  350. if [ ! -e "${PWD}/compress-dmg" ]; then
  351. echo "DMG will not be compressed."
  352. else
  353. echo "Compressing DMG"
  354. mv ${LINUXIMAGE} ${LINUXIMAGE}.pre
  355. ${PWD}/compress-dmg dmg ${LINUXIMAGE}.pre ${LINUXIMAGE}
  356. if [ -e ${LINUXIMAGE} ]; then
  357. rm -Rf ${LINUXIMAGE}.pre
  358. else
  359. echo "Compression failed."
  360. mv ${LINUXIMAGE}.pre ${LINUXIMAGE}
  361. fi;
  362. fi;
  363. if [ "${LINUXIMAGE}" != "${RUNNAME}" ]; then
  364. # Rename the image
  365. mv ${LINUXIMAGE} ${RUNNAME}
  366. fi;
  367. else
  368. # OSX
  369. # Create Read/Write image
  370. ${HDIUTIL} create -volname "DMDirc" -fs HFS+ -srcfolder ${DMG} -format UDRW ${RUNNAME}.RW.dmg
  371. # Make it auto-open
  372. BLESS=`which bless`
  373. if [ "" != "${BLESS}" ]; then
  374. if [ -e /Volumes/DMDirc ]; then
  375. ${HDIUTIL} detach /Volumes/DMDirc
  376. fi;
  377. if [ ! -e /Volumes/DMDirc ]; then
  378. ${HDIUTIL} attach ${RUNNAME}.RW.dmg
  379. ${BLESS} -openfolder /Volumes/DMDirc
  380. ${HDIUTIL} detach /Volumes/DMDirc
  381. fi;
  382. fi;
  383. # Convert to compressed read-only image
  384. ${HDIUTIL} convert ${RUNNAME}.RW.dmg -format UDZO -imagekey zlib-level=9 -o ${RUNNAME}
  385. rm ${RUNNAME}.RW.dmg
  386. fi;
  387. echo "DMG Creation complete!"
  388. if [ ${doRename} -eq 1 ]; then
  389. if [ "${TAGGED}" = "" ]; then
  390. isRelease=branch-${isRelease}
  391. else
  392. isRelease=${TAGGED}
  393. fi;
  394. if [ "" != "${finalTag}" ]; then
  395. finalTag="-${finalTag}"
  396. fi;
  397. finalname=DMDirc-${isRelease}${finalTag}.dmg
  398. else
  399. finalname=${RUNNAME##*/}
  400. fi;
  401. mv ${RUNNAME} ../output/${finalname}
  402. rm -Rfv ${DMG} ${APPDIR} ${DMGMOUNTDIR} DMDirc.jar
  403. echo "-----------"
  404. echo "Done."
  405. echo "-----------"
  406. # and Done \o
  407. exit 0;