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.

DMDirc.sh 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. #!/bin/sh
  2. #
  3. # This script launches dmdirc and attempts to update the jar file if needed.
  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. LAUNCHERVERSION="13"
  26. LAUNCHERINFO="unix-${LAUNCHERVERSION}"
  27. params=""
  28. # Check the which command exists, and if so make sure it behaves how we want
  29. # it to...
  30. WHICH=`which which 2>/dev/null`
  31. if [ "" = "${WHICH}" ]; then
  32. echo "which command not found. Aborting.";
  33. exit 0;
  34. else
  35. # Solaris sucks
  36. BADWHICH=`which /`
  37. if [ "${BADWHICH}" != "" ]; then
  38. echo "Replacing bad which command.";
  39. # "Which" on solaris gives non-empty results for commands that don't exist
  40. which() {
  41. OUT=`${WHICH} ${1}`
  42. if [ $? -eq 0 ]; then
  43. echo ${OUT}
  44. else
  45. echo ""
  46. fi;
  47. }
  48. fi;
  49. fi
  50. # Store params so that we can pass them back to the client
  51. for param in "$@"; do
  52. if [ "${param}" = "--noprofile" -o "${param}" = "--updateonly" ]; then
  53. continue;
  54. fi;
  55. PSN=`echo "${param}" | grep "^-psn_"`
  56. if [ "" = "${PSN}" ]; then
  57. SPACE=`echo "${param}" | grep " "`
  58. if [ "${SPACE}" != "" ]; then
  59. niceParam=`echo "${param}" | sed 's/"/\\\\"/g'`
  60. params=${params}" \"${niceParam}\""
  61. else
  62. params=${params}" ${param}"
  63. fi;
  64. fi;
  65. done;
  66. if [ -e "functions.sh" ]; then
  67. . functions.sh
  68. else
  69. # TODO: Remove this and depend on functions.sh...
  70. echo "Unable to find functions.sh, using old functions"
  71. # Check for OS X
  72. OSASCRIPT=`which osascript`
  73. KERNEL=`uname -s`
  74. ISOSX="0"
  75. # Kernel is darwin, and osascript exists, probably OS X!
  76. if [ "${KERNEL}" = "Darwin" -a "" != "${OSASCRIPT}" ]; then
  77. ISOSX="1"
  78. fi;
  79. if [ "${ISOSX}" != "1" ]; then
  80. PIDOF=`which pidof`
  81. if [ "${PIDOF}" = "" ]; then
  82. # For some reason some distros hide pidof...
  83. if [ -e /sbin/pidof ]; then
  84. PIDOF=/sbin/pidof
  85. elif [ -e /usr/sbin/pidof ]; then
  86. PIDOF=/usr/sbin/pidof
  87. fi;
  88. fi;
  89. ## Helper Functions
  90. if [ "${PIDOF}" != "" ]; then
  91. ISKDE=`${PIDOF} -x -s kdeinit`
  92. ISGNOME=`${PIDOF} -x -s gnome-panel`
  93. else
  94. ISKDE=`ps -Af | grep kdeinit | grep -v grep`
  95. ISGNOME=`ps -Af | grep gnome-panel | grep -v grep`
  96. fi;
  97. KDIALOG=`which kdialog`
  98. ZENITY=`which zenity`
  99. KSUDO=`which kdesudo`
  100. GSUDO=`which gksudo`
  101. fi;
  102. errordialog() {
  103. # Send message to console.
  104. echo ""
  105. echo "-----------------------------------------------------------------------"
  106. echo "Error: ${1}"
  107. echo "-----------------------------------------------------------------------"
  108. echo "${2}"
  109. echo "-----------------------------------------------------------------------"
  110. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  111. echo "Displaying dialog.."
  112. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  113. else
  114. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  115. echo "Dialog on Display: ${DISPLAY}"
  116. ${KDIALOG} --title "DMDirc: ${1}" --error "${1}\n\n${2}"
  117. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  118. echo "Dialog on Display: ${DISPLAY}"
  119. ${ZENITY} --error --title "DMDirc: ${1}" --text "${1}\n\n${2}"
  120. fi
  121. fi;
  122. }
  123. messagedialog() {
  124. # Send message to console.
  125. echo ""
  126. echo "-----------------------------------------------------------------------"
  127. echo "Info: ${1}"
  128. echo "-----------------------------------------------------------------------"
  129. echo "${2}"
  130. echo "-----------------------------------------------------------------------"
  131. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  132. echo "Displaying dialog.."
  133. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} giving up after 120 with icon note" -e 'end tell'
  134. else
  135. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  136. echo "Dialog on Display: ${DISPLAY}"
  137. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${1}\n\n${2}"
  138. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  139. echo "Dialog on Display: ${DISPLAY}"
  140. ${ZENITY} --info --title "DMDirc: ${1}" --text "${1}\n\n${2}"
  141. fi
  142. fi;
  143. }
  144. fi;
  145. # Check to see if we can bspatch things
  146. BSPATCH="./bspatch"
  147. if [ ! -e "${BSPATCH}" ]; then
  148. BSPATCH=`which bspatch`
  149. fi;
  150. # This launcher supports zip files.
  151. LAUNCHERINFO=${LAUNCHERINFO}",zip"
  152. if [ "${BSPATCH}" != "" ]; then
  153. # TODO: Website should (if available) send bsdiff patches
  154. # to clients with bsdiff compatible launchers
  155. LAUNCHERINFO=${LAUNCHERINFO}",bsdiff";
  156. fi;
  157. # Check for some CLI params
  158. if [ "${ISOSX}" = "1" ]; then
  159. profiledir="${HOME}/Library/Preferences/DMDirc"
  160. else
  161. profiledir="${HOME}/.DMDirc/"
  162. fi;
  163. USEPROFILE=1;
  164. UPDATEONLY=0;
  165. while test -n "$1"; do
  166. case "$1" in
  167. --directory|-d)
  168. shift
  169. profiledir=${1}
  170. ;;
  171. --noprofile)
  172. USEPROFILE=0;
  173. ;;
  174. --updateonly)
  175. UPDATEONLY=1;
  176. ;;
  177. -p|--portable)
  178. profiledir=${PWD};
  179. ;;
  180. esac
  181. shift
  182. done
  183. getConfigOption() {
  184. FILE="${profiledir}/dmdirc.config"
  185. WANTED_DOMAIN="${1}"
  186. WANTED_KEY="${2}"
  187. CURRENT_SECTION=""
  188. if [ "${WANTED_KEY}" != "" -a "${WANTED_DOMAIN}" = "" ]; then
  189. if [ -e "${FILE}" ]; then
  190. cat ${FILE} | sed 's/\\/\\\\/g' | while IFS='' read -r LINE; do
  191. IS_SECTION=`echo ${LINE} | egrep "^.*:$"`
  192. IS_KEYVALUE=`echo ${LINE} | egrep "^[[:space:]]+.*=.*$"`
  193. if [ "" != "${IS_SECTION}" ]; then
  194. CURRENT_SECTION=${LINE%%:*}
  195. elif [ "" != "${IS_KEYVALUE}" ]; then
  196. KEY=`echo ${LINE%%=*} | sed 's/^\s*//g'`
  197. VALUE=${LINE##*=}
  198. if [ "${WANTED_DOMAIN}" = "${CURRENT_SECTION}" -a "${WANTED_KEY}" = "${KEY}" ]; then
  199. echo ${VALUE};
  200. fi;
  201. fi;
  202. done;
  203. fi;
  204. fi;
  205. }
  206. if [ "${ISOSX}" = "1" ]; then
  207. jarDir=`dirname $0`/../Resources/Java/
  208. jar=${jarDir}DMDirc.jar
  209. else
  210. jar=`dirname $0`/DMDirc.jar
  211. fi
  212. launcherUpdater=${profiledir}/updateLauncher.sh
  213. BSDJava1="/usr/local/jdk1.6.0/jre/bin/java"
  214. BSDJava2="/usr/local/diablo-jdk1.6.0/jre/bin/java"
  215. echo "---------------------"
  216. echo "DMDirc - Open Source IRC Client"
  217. echo "Launcher Version: ${LAUNCHERVERSION}"
  218. echo "Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes"
  219. echo "---------------------"
  220. if [ "${ISOSX}" = "1" ]; then
  221. echo "Running on OS X."
  222. elif [ "${KERNEL}" = "Linux" ]; then
  223. echo "Running on Linux."
  224. elif [ "`echo ${KERNEL} | grep -i BSD`" != "" ]; then
  225. echo "Running on BSD."
  226. elif [ "`echo ${KERNEL} | grep -i SunOS`" != "" ]; then
  227. echo "Running on Solaris."
  228. else
  229. echo "Running on unknown unix variation: ${KERNEL}."
  230. fi;
  231. if [ -e "${profiledir}/.launcher.zip" ]; then
  232. # Unzip!
  233. unzip ${profiledir}/.launcher.zip -d ${profiledir}/
  234. fi;
  235. echo -n "Checking for launcher updates in ${profiledir} - ";
  236. if [ -e "${profiledir}/.launcher.sh.ignore" ]; then
  237. rm -Rf "${profiledir}/.launcher.sh.ignore"
  238. echo "Ignoring!";
  239. elif [ -e "${profiledir}/.launcher.sh" ]; then
  240. echo "Found!";
  241. echo "Attempting to update..";
  242. cat <<EOF> ${launcherUpdater}
  243. cd `dirname $0`
  244. if [ -e "functions.sh" ]; then
  245. . functions.sh
  246. else
  247. # TODO: Remove this and depend on functions.sh...
  248. echo "Unable to find functions.sh, using old functions"
  249. errordialog() {
  250. # Send message to console.
  251. echo ""
  252. echo "-----------------------------------------------------------------------"
  253. echo "Error: \${1}"
  254. echo "-----------------------------------------------------------------------"
  255. echo "\${2}"
  256. echo "-----------------------------------------------------------------------"
  257. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  258. echo "Displaying dialog.."
  259. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  260. else
  261. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  262. echo "Dialog on Display: ${DISPLAY}"
  263. ${KDIALOG} --title "DMDirc: \${1}" --error "\${1}\n\n\${2}"
  264. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  265. echo "Dialog on Display: ${DISPLAY}"
  266. ${ZENITY} --error --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  267. fi
  268. fi
  269. }
  270. messagedialog() {
  271. # Send message to console.
  272. echo ""
  273. echo "-----------------------------------------------------------------------"
  274. echo "Info: \${1}"
  275. echo "-----------------------------------------------------------------------"
  276. echo "\${2}"
  277. echo "-----------------------------------------------------------------------"
  278. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  279. echo "Displaying dialog.."
  280. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} giving up after 120 with icon note" -e 'end tell'
  281. else
  282. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  283. echo "Dialog on Display: ${DISPLAY}"
  284. ${KDIALOG} --title "DMDirc: \${1}" --msgbox "\${1}\n\n\${2}"
  285. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  286. echo "Dialog on Display: ${DISPLAY}"
  287. ${ZENITY} --info --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  288. fi
  289. fi;
  290. }
  291. fi;
  292. mv -fv ${profiledir}/.launcher.sh ${0}
  293. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  294. echo "Launcher Update successful."
  295. messagedialog "Launcher Update" "Launcher Update successful"
  296. else
  297. if [ "${UID}" = "" ]; then
  298. UID=`id -u`;
  299. fi
  300. if [ "0" != "${UID}" ]; then
  301. if [ "${ISOSX}" = "1" ]; then
  302. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  303. if [ $? -eq 0 ]; then
  304. echo "Password dialog on display"
  305. osascript -e do shell script "mv -fv \"${profiledir}/.launcher.sh\" \"${0}\"" with administrator privileges
  306. fi;
  307. else
  308. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  309. echo "Password dialog on ${DISPLAY}"
  310. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  311. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  312. echo "Password dialog on ${DISPLAY}"
  313. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  314. elif [ "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  315. sudo -k
  316. ${ZENITY} --entry --title="DMDirc" --text="DMDirc Client Updater requires root access to modify the global installation, please enter your password to continue." --entry-text="" --hide-text | sudo -S -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  317. else
  318. echo "DMDirc Client Updater requires root access to modify the global installation"
  319. sudo mv -fv "${profiledir}/.launcher.sh" "${0}"
  320. fi;
  321. fi;
  322. fi
  323. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  324. echo "Update successful."
  325. messagedialog "Launcher Update" "Launcher Update successful"
  326. else
  327. echo "Launcher failed."
  328. errordialog "Launcher Update" "Launcher Update failed, using old version"
  329. touch ${profiledir}/.launcher.sh.ignore
  330. fi;
  331. fi;
  332. sh ${0} ${params}
  333. EOF
  334. chmod a+x ${launcherUpdater}
  335. ${launcherUpdater}
  336. exit 0;
  337. else
  338. echo "Not found.";
  339. fi;
  340. if [ -e "${launcherUpdater}" ]; then
  341. rm -Rf "${launcherUpdater}"
  342. fi;
  343. echo -n "Checking for client updates in ${profiledir} - ";
  344. UPDATESOURCE="${profiledir}/.DMDirc.jar"
  345. BSDIFF="0"
  346. if [ -e "${profiledir}/.DMDirc.jar.bsdiff" -a "${BSPATCH}" != "" ]; then
  347. UPDATESOURCE="${profiledir}/.DMDirc.jar.bsdiff"
  348. BSDIFF="1"
  349. fi;
  350. if [ -e "${UPDATESOURCE}" ]; then
  351. UPDATEOK="0"
  352. TRYROOT="1"
  353. echo "Found!";
  354. echo "Attempting to update..";
  355. if [ "${BSDIFF}" = "1" ]; then
  356. cp ${jar} ${jar}.bak
  357. ${BSPATCH} ${jar}.bak ${jar} ${UPDATESOURCE}
  358. if [ "${?}" = "0" ]; then
  359. FILEINFO=`which ${jar} | egrep "data$`
  360. if [ "${FILEINFO}" = "" ]; then
  361. UPDATEOK="1"
  362. else
  363. # Let the user know the update failed.
  364. echo "1" >> "${profiledir}/.updatefailed";
  365. chmod 777 "${profiledir}/.updatefailed";
  366. # Replace the attempted update with the old jar
  367. cp ${jar}.bak ${jar}
  368. # Don't bother trying as root.
  369. TRYROOT="0"
  370. fi;
  371. fi;
  372. else
  373. mv -fv ${UPDATESOURCE} ${jar}
  374. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  375. UPDATEOK="1"
  376. fi;
  377. fi;
  378. if [ "${UPDATEOK}" = "1" ]; then
  379. echo "Update successful."
  380. messagedialog "Client Update" "Client Update successful"
  381. if [ "${UPDATEONLY}" = "1" ]; then
  382. exit 0;
  383. fi;
  384. else
  385. if [ "${UID}" = "" ]; then
  386. UID=`id -u`;
  387. fi
  388. if [ "0" != "${UID}" -a "1" = "${TRYROOT}" ]; then
  389. if [ "${ISOSX}" = "1" ]; then
  390. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  391. if [ $? -eq 0 ]; then
  392. echo "Password dialog on display"
  393. # osascript -e "do shell script \"mv -fv \\\"${profiledir}/.DMDirc.jar\\\" \\\"${jar}\\\"\" with administrator privileges"
  394. osascript -e "do shell script \"sh ${0} ${params} --updateonly\" with administrator privileges"
  395. fi;
  396. else
  397. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  398. echo "Password dialog on ${DISPLAY}"
  399. # ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  400. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- sh ${0} ${params} --updateonly
  401. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  402. echo "Password dialog on ${DISPLAY}"
  403. # ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  404. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- sh ${0} ${params} --updateonly
  405. elif [ "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  406. sudo -k
  407. ${ZENITY} --entry --title="DMDirc" --text="DMDirc Client Updater requires root access to modify the global installation, please enter your password to continue." --entry-text="" --hide-text | sudo -S -- sh ${0} ${params} --updateonly
  408. else
  409. echo "DMDirc Client Updater requires root access to modify the global installation"
  410. # sudo mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  411. sudo sh ${0} ${params} --updateonly
  412. fi;
  413. fi;
  414. elif [ "${UPDATEONLY}" = "1" ]; then
  415. # Update failed as root, so give up.
  416. echo "1" >> "${profiledir}/.updatefailed";
  417. chmod 777 "${profiledir}/.updatefailed";
  418. exit 1;
  419. fi;
  420. if [ ! -e "${profiledir}/.updatefailed" ]; then
  421. echo "Update successful."
  422. messagedialog "Client Update" "Client Update successful"
  423. else
  424. rm -Rf ${profiledir}/.updatefailed;
  425. echo "Update failed."
  426. errordialog "Client Update" "Client Update failed, using old version"
  427. if [ "${BSDIFF}" = "1" ]; then
  428. # Run the client without bspatch support
  429. LAUNCHERINFO=`echo ${LAUNCHERINFO} | sed 's/|bsdiff//'`
  430. fi;
  431. fi;
  432. fi
  433. else
  434. echo "Not found.";
  435. fi;
  436. if [ "${UPDATEONLY}" = "1" ]; then
  437. exit 0;
  438. fi;
  439. relaunch() {
  440. trap - INT TERM EXIT
  441. echo ""
  442. echo "============================================================="
  443. echo "ERROR"
  444. echo "============================================================="
  445. echo "${HOME}/.profile has errors in it (or an 'exit' command)."
  446. echo "Setup will now restart with the --noprofile option."
  447. echo "============================================================="
  448. sh ${0} ${params} --noprofile
  449. }
  450. echo -n "Looking for java - ";
  451. if [ "${ISOSX}" = "1" ]; then
  452. JAVA=`which java`
  453. if [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java" ]; then
  454. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java"
  455. elif [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java" ]; then
  456. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java"
  457. fi;
  458. else
  459. if [ -e "${HOME}/.profile" -a "${USEPROFILE}" = "1" ]; then
  460. # Source the profile incase java can't be found otherwise
  461. trap relaunch INT TERM EXIT
  462. . ${HOME}/.profile
  463. trap - INT TERM EXIT
  464. fi;
  465. JAVA=`which java`
  466. if [ ! -e "${JAVA}" ]; then
  467. # Location where ports on FreeBSD/PCBSD installs java6
  468. # check it first, because it isn't added to the path automatically
  469. JAVA=${BSDJava1}
  470. if [ ! -e "${JAVA}" ]; then
  471. # Try alternative BSD Location
  472. JAVA=${BSDJava2}
  473. fi;
  474. fi;
  475. fi;
  476. if [ "" != "${JAVA}" ]; then
  477. echo "Success! (${JAVA})"
  478. else
  479. echo "Failed!"
  480. ERROR="Sorry, java does not appear to be installed on this machine.";
  481. ERROR=${ERROR}"\n"
  482. if [ "${ISOSX}" = "1" ]; then
  483. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM.";
  484. else
  485. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  486. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  487. fi;
  488. errordialog "Unable to launch dmdirc!" "${ERROR}";
  489. exit 1;
  490. fi
  491. echo -n "Running DMDirc - "
  492. if [ -e "${jar}" ]; then
  493. # Check that DMDirc will run, if java is not 1.6 this will fail.
  494. # We do it this way otherwise segfaults etc would cause an unable to launch
  495. # error message to be printed.
  496. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  497. if [ $? -ne 0 ]; then
  498. FAILED=1
  499. # If we are on BSD, check to see if there is alternative versions of java
  500. # than the one in the path.
  501. if [ "`echo ${KERNEL} | grep -i BSD`" != "" ]; then
  502. if [ "${JAVA}" != "${BSDJava1}" -a "${JAVA}" != "${BSDJava2}" ]; then
  503. JAVA=${BSDJava1}
  504. if [ ! -e "${JAVA}" ]; then
  505. JAVA=${BSDJava2}
  506. fi;
  507. # Now check to see if DMDirc runs again.
  508. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  509. if [ $? -eq 0 ]; then
  510. # It runs!
  511. FAILED=0
  512. fi;
  513. fi;
  514. fi;
  515. if [ ${FAILED} -eq 1 ]; then
  516. echo "Failed."
  517. ERROR="Sorry, the currently installed version of java is not compatible with DMDirc.";
  518. ERROR=${ERROR}"\n";
  519. if [ "${ISOSX}" = "1" ]; then
  520. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM.";
  521. else
  522. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  523. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  524. fi;
  525. errordialog "Unable to launch dmdirc!" "${ERROR}";
  526. exit 1;
  527. fi;
  528. fi
  529. # Now we can run the client for real, this allows stderr/stdout output
  530. # to be seen, and the shell script exits with the correct exit code.
  531. APPLEOPTS=""
  532. if [ "${ISOSX}" = "1" ]; then
  533. APPLEOPTS="${APPLEOPTS} -Djava.library.path=${jarDir}"
  534. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.growbox.intrudes=false"
  535. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.live-resize=true"
  536. APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.apple.menu.about.name=DMDirc"
  537. #APPLEOPTS="${APPLEOPTS} -Dapple.awt.showGrowBox=true"
  538. #APPLEOPTS="${APPLEOPTS} -Dapple.laf.useScreenMenuBar=true"
  539. fi;
  540. ${JAVA}${APPLEOPTS} -ea -jar ${jar} -l ${LAUNCHERINFO} ${params}
  541. EXITCODE=${?}
  542. if [ ${EXITCODE} -eq 42 ]; then
  543. # The client says we need to up update, rerun ourself before exiting.
  544. ${0} ${params}
  545. fi;
  546. exit ${EXITCODE};
  547. else
  548. echo "Failed.";
  549. errordialog "Unable to launch dmdirc!" "No jar file found";
  550. fi