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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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-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. 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. . `dirname $0`/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. if [ ! -d "${profiledir}" ]; then
  163. profiledir="${XDG_CONFIG_HOME}"
  164. if [ "${profiledir}" = "" ]; then
  165. profiledir="${HOME}/.config"
  166. fi;
  167. profiledir="${profiledir}/DMDirc/"
  168. fi;
  169. fi;
  170. USEPROFILE=1;
  171. UPDATEONLY=0;
  172. while test -n "$1"; do
  173. case "$1" in
  174. --directory|-d)
  175. shift
  176. profiledir=${1}
  177. ;;
  178. --noprofile)
  179. USEPROFILE=0;
  180. ;;
  181. --updateonly)
  182. UPDATEONLY=1;
  183. ;;
  184. -p|--portable)
  185. profiledir=${PWD};
  186. ;;
  187. esac
  188. shift
  189. done
  190. getConfigOption() {
  191. FILE="${profiledir}/dmdirc.config"
  192. WANTED_DOMAIN="${1}"
  193. WANTED_KEY="${2}"
  194. CURRENT_SECTION=""
  195. if [ "${WANTED_KEY}" != "" -a "${WANTED_DOMAIN}" = "" ]; then
  196. if [ -e "${FILE}" ]; then
  197. cat ${FILE} | sed 's/\\/\\\\/g' | while IFS='' read -r LINE; do
  198. IS_SECTION=`echo ${LINE} | egrep "^.*:$"`
  199. IS_KEYVALUE=`echo ${LINE} | egrep "^[[:space:]]+.*=.*$"`
  200. if [ "" != "${IS_SECTION}" ]; then
  201. CURRENT_SECTION=${LINE%%:*}
  202. elif [ "" != "${IS_KEYVALUE}" ]; then
  203. KEY=`echo ${LINE%%=*} | sed 's/^\s*//g'`
  204. VALUE=${LINE##*=}
  205. if [ "${WANTED_DOMAIN}" = "${CURRENT_SECTION}" -a "${WANTED_KEY}" = "${KEY}" ]; then
  206. echo ${VALUE};
  207. fi;
  208. fi;
  209. done;
  210. fi;
  211. fi;
  212. }
  213. if [ "${ISOSX}" = "1" ]; then
  214. jarDir=`dirname $0`/../Resources/Java/
  215. jar=${jarDir}DMDirc.jar
  216. else
  217. jar=`dirname $0`/DMDirc.jar
  218. fi
  219. launcherUpdater=${profiledir}/updateLauncher.sh
  220. BSDJava1="/usr/local/jdk1.6.0/jre/bin/java"
  221. BSDJava2="/usr/local/diablo-jdk1.6.0/jre/bin/java"
  222. echo "---------------------"
  223. echo "DMDirc - Open Source IRC Client"
  224. echo "Launcher Version: ${LAUNCHERVERSION}"
  225. echo "Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes"
  226. echo "---------------------"
  227. if [ "${ISOSX}" = "1" ]; then
  228. echo "Running on OS X."
  229. elif [ "${KERNEL}" = "Linux" ]; then
  230. echo "Running on Linux."
  231. elif [ "`echo ${KERNEL} | grep -i BSD`" != "" ]; then
  232. echo "Running on BSD."
  233. elif [ "`echo ${KERNEL} | grep -i SunOS`" != "" ]; then
  234. echo "Running on Solaris."
  235. else
  236. echo "Running on unknown unix variation: ${KERNEL}."
  237. fi;
  238. if [ -e "${profiledir}/.launcher.zip" ]; then
  239. # Unzip!
  240. unzip ${profiledir}/.launcher.zip -d ${profiledir}/
  241. fi;
  242. echo -n "Checking for launcher updates in ${profiledir} - ";
  243. if [ -e "${profiledir}/.launcher.sh.ignore" ]; then
  244. rm -Rf "${profiledir}/.launcher.sh.ignore"
  245. echo "Ignoring!";
  246. elif [ -e "${profiledir}/.launcher.sh" ]; then
  247. echo "Found!";
  248. echo "Attempting to update..";
  249. cat <<EOF> ${launcherUpdater}
  250. cd `dirname $0`
  251. if [ -e "functions.sh" ]; then
  252. . `dirname $0`/functions.sh
  253. else
  254. # TODO: Remove this and depend on functions.sh...
  255. echo "Unable to find functions.sh, using old functions"
  256. errordialog() {
  257. # Send message to console.
  258. echo ""
  259. echo "-----------------------------------------------------------------------"
  260. echo "Error: \${1}"
  261. echo "-----------------------------------------------------------------------"
  262. echo "\${2}"
  263. echo "-----------------------------------------------------------------------"
  264. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  265. echo "Displaying dialog.."
  266. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  267. else
  268. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  269. echo "Dialog on Display: ${DISPLAY}"
  270. ${KDIALOG} --title "DMDirc: \${1}" --error "\${1}\n\n\${2}"
  271. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  272. echo "Dialog on Display: ${DISPLAY}"
  273. ${ZENITY} --error --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  274. fi
  275. fi
  276. }
  277. messagedialog() {
  278. # Send message to console.
  279. echo ""
  280. echo "-----------------------------------------------------------------------"
  281. echo "Info: \${1}"
  282. echo "-----------------------------------------------------------------------"
  283. echo "\${2}"
  284. echo "-----------------------------------------------------------------------"
  285. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  286. echo "Displaying dialog.."
  287. ${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'
  288. else
  289. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  290. echo "Dialog on Display: ${DISPLAY}"
  291. ${KDIALOG} --title "DMDirc: \${1}" --msgbox "\${1}\n\n\${2}"
  292. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  293. echo "Dialog on Display: ${DISPLAY}"
  294. ${ZENITY} --info --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  295. fi
  296. fi;
  297. }
  298. fi;
  299. mv -fv ${profiledir}/.launcher.sh ${0}
  300. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  301. echo "Launcher Update successful."
  302. messagedialog "Launcher Update" "Launcher Update successful"
  303. else
  304. if [ "${UID}" = "" ]; then
  305. UID=`id -u`;
  306. fi
  307. if [ "0" != "${UID}" ]; then
  308. if [ "${ISOSX}" = "1" ]; then
  309. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  310. if [ $? -eq 0 ]; then
  311. echo "Password dialog on display"
  312. osascript -e do shell script "mv -fv \"${profiledir}/.launcher.sh\" \"${0}\"" with administrator privileges
  313. fi;
  314. else
  315. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  316. echo "Password dialog on ${DISPLAY}"
  317. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  318. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  319. echo "Password dialog on ${DISPLAY}"
  320. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  321. elif [ "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  322. sudo -k
  323. ${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}"
  324. else
  325. echo "DMDirc Client Updater requires root access to modify the global installation"
  326. sudo mv -fv "${profiledir}/.launcher.sh" "${0}"
  327. fi;
  328. fi;
  329. fi
  330. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  331. echo "Update successful."
  332. messagedialog "Launcher Update" "Launcher Update successful"
  333. else
  334. echo "Launcher failed."
  335. errordialog "Launcher Update" "Launcher Update failed, using old version"
  336. touch ${profiledir}/.launcher.sh.ignore
  337. fi;
  338. fi;
  339. sh ${0} ${params}
  340. EOF
  341. chmod a+x ${launcherUpdater}
  342. ${launcherUpdater}
  343. exit 0;
  344. else
  345. echo "Not found.";
  346. fi;
  347. if [ -e "${launcherUpdater}" ]; then
  348. rm -Rf "${launcherUpdater}"
  349. fi;
  350. echo -n "Checking for client updates in ${profiledir} - ";
  351. UPDATESOURCE="${profiledir}/.DMDirc.jar"
  352. BSDIFF="0"
  353. if [ -e "${profiledir}/.DMDirc.jar.bsdiff" -a "${BSPATCH}" != "" ]; then
  354. UPDATESOURCE="${profiledir}/.DMDirc.jar.bsdiff"
  355. BSDIFF="1"
  356. fi;
  357. if [ -e "${UPDATESOURCE}" ]; then
  358. UPDATEOK="0"
  359. TRYROOT="1"
  360. echo "Found!";
  361. echo "Attempting to update..";
  362. if [ "${BSDIFF}" = "1" ]; then
  363. cp ${jar} ${jar}.bak
  364. ${BSPATCH} ${jar}.bak ${jar} ${UPDATESOURCE}
  365. if [ "${?}" = "0" ]; then
  366. FILEINFO=`which ${jar} | egrep "data$`
  367. if [ "${FILEINFO}" = "" ]; then
  368. UPDATEOK="1"
  369. else
  370. # Let the user know the update failed.
  371. echo "1" >> "${profiledir}/.updatefailed";
  372. chmod 777 "${profiledir}/.updatefailed";
  373. # Replace the attempted update with the old jar
  374. cp ${jar}.bak ${jar}
  375. # Don't bother trying as root.
  376. TRYROOT="0"
  377. fi;
  378. fi;
  379. else
  380. mv -fv ${UPDATESOURCE} ${jar}
  381. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  382. UPDATEOK="1"
  383. fi;
  384. fi;
  385. if [ "${UPDATEOK}" = "1" ]; then
  386. echo "Update successful."
  387. messagedialog "Client Update" "Client Update successful"
  388. if [ "${UPDATEONLY}" = "1" ]; then
  389. exit 0;
  390. fi;
  391. else
  392. if [ "${UID}" = "" ]; then
  393. UID=`id -u`;
  394. fi
  395. if [ "0" != "${UID}" -a "1" = "${TRYROOT}" ]; then
  396. if [ "${ISOSX}" = "1" ]; then
  397. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  398. if [ $? -eq 0 ]; then
  399. echo "Password dialog on display"
  400. # osascript -e "do shell script \"mv -fv \\\"${profiledir}/.DMDirc.jar\\\" \\\"${jar}\\\"\" with administrator privileges"
  401. osascript -e "do shell script \"sh ${0} ${params} --updateonly\" with administrator privileges"
  402. fi;
  403. else
  404. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  405. echo "Password dialog on ${DISPLAY}"
  406. # ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  407. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- sh ${0} ${params} --updateonly
  408. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  409. echo "Password dialog on ${DISPLAY}"
  410. # ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  411. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- sh ${0} ${params} --updateonly
  412. elif [ "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  413. sudo -k
  414. ${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
  415. else
  416. echo "DMDirc Client Updater requires root access to modify the global installation"
  417. # sudo mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  418. sudo sh ${0} ${params} --updateonly
  419. fi;
  420. fi;
  421. elif [ "${UPDATEONLY}" = "1" ]; then
  422. # Update failed as root, so give up.
  423. echo "1" >> "${profiledir}/.updatefailed";
  424. chmod 777 "${profiledir}/.updatefailed";
  425. exit 1;
  426. fi;
  427. if [ ! -e "${profiledir}/.updatefailed" ]; then
  428. echo "Update successful."
  429. messagedialog "Client Update" "Client Update successful"
  430. else
  431. rm -Rf ${profiledir}/.updatefailed;
  432. echo "Update failed."
  433. errordialog "Client Update" "Client Update failed, using old version"
  434. if [ "${BSDIFF}" = "1" ]; then
  435. # Run the client without bspatch support
  436. LAUNCHERINFO=`echo ${LAUNCHERINFO} | sed 's/|bsdiff//'`
  437. fi;
  438. fi;
  439. fi
  440. else
  441. echo "Not found.";
  442. fi;
  443. if [ "${UPDATEONLY}" = "1" ]; then
  444. exit 0;
  445. fi;
  446. relaunch() {
  447. trap - INT TERM EXIT
  448. echo ""
  449. echo "============================================================="
  450. echo "ERROR"
  451. echo "============================================================="
  452. echo "${HOME}/.profile has errors in it (or an 'exit' command)."
  453. echo "Setup will now restart with the --noprofile option."
  454. echo "============================================================="
  455. sh ${0} ${params} --noprofile
  456. }
  457. echo -n "Looking for java - ";
  458. if [ "${ISOSX}" = "1" ]; then
  459. JAVA=`which java`
  460. if [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java" ]; then
  461. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java"
  462. elif [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java" ]; then
  463. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java"
  464. fi;
  465. else
  466. if [ -e "${HOME}/.profile" -a "${USEPROFILE}" = "1" ]; then
  467. # Source the profile incase java can't be found otherwise
  468. trap relaunch INT TERM EXIT
  469. . ${HOME}/.profile
  470. trap - INT TERM EXIT
  471. fi;
  472. JAVA=`which java`
  473. if [ ! -e "${JAVA}" ]; then
  474. # Location where ports on FreeBSD/PCBSD installs java6
  475. # check it first, because it isn't added to the path automatically
  476. JAVA=${BSDJava1}
  477. if [ ! -e "${JAVA}" ]; then
  478. # Try alternative BSD Location
  479. JAVA=${BSDJava2}
  480. fi;
  481. fi;
  482. fi;
  483. if [ "" != "${JAVA}" ]; then
  484. echo "Success! (${JAVA})"
  485. else
  486. echo "Failed!"
  487. ERROR="Sorry, java does not appear to be installed on this machine.";
  488. ERROR=${ERROR}"\n"
  489. if [ "${ISOSX}" = "1" ]; then
  490. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM.";
  491. else
  492. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  493. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  494. fi;
  495. errordialog "Unable to launch dmdirc!" "${ERROR}";
  496. exit 1;
  497. fi
  498. echo -n "Running DMDirc - "
  499. if [ -e "${jar}" ]; then
  500. # Check that DMDirc will run, if java is not 1.6 this will fail.
  501. # We do it this way otherwise segfaults etc would cause an unable to launch
  502. # error message to be printed.
  503. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  504. if [ $? -ne 0 ]; then
  505. FAILED=1
  506. # If we are on BSD, check to see if there is alternative versions of java
  507. # than the one in the path.
  508. if [ "`echo ${KERNEL} | grep -i BSD`" != "" ]; then
  509. if [ "${JAVA}" != "${BSDJava1}" -a "${JAVA}" != "${BSDJava2}" ]; then
  510. JAVA=${BSDJava1}
  511. if [ ! -e "${JAVA}" ]; then
  512. JAVA=${BSDJava2}
  513. fi;
  514. # Now check to see if DMDirc runs again.
  515. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  516. if [ $? -eq 0 ]; then
  517. # It runs!
  518. FAILED=0
  519. fi;
  520. fi;
  521. fi;
  522. if [ ${FAILED} -eq 1 ]; then
  523. echo "Failed."
  524. ERROR="Sorry, the currently installed version of java is not compatible with DMDirc.";
  525. ERROR=${ERROR}"\n";
  526. if [ "${ISOSX}" = "1" ]; then
  527. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM.";
  528. else
  529. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  530. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  531. fi;
  532. errordialog "Unable to launch dmdirc!" "${ERROR}";
  533. exit 1;
  534. fi;
  535. fi
  536. # Now we can run the client for real, this allows stderr/stdout output
  537. # to be seen, and the shell script exits with the correct exit code.
  538. APPLEOPTS=""
  539. if [ "${ISOSX}" = "1" ]; then
  540. APPLEOPTS="${APPLEOPTS} -Djava.library.path=${jarDir}"
  541. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.growbox.intrudes=false"
  542. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.live-resize=true"
  543. APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.apple.menu.about.name=DMDirc"
  544. #APPLEOPTS="${APPLEOPTS} -Dapple.awt.showGrowBox=true"
  545. #APPLEOPTS="${APPLEOPTS} -Dapple.laf.useScreenMenuBar=true"
  546. fi;
  547. ${JAVA}${APPLEOPTS} -ea -jar ${jar} -l ${LAUNCHERINFO} ${params}
  548. EXITCODE=${?}
  549. if [ ${EXITCODE} -eq 42 ]; then
  550. # The client says we need to up update, rerun ourself before exiting.
  551. ${0} ${params}
  552. fi;
  553. exit ${EXITCODE};
  554. else
  555. echo "Failed.";
  556. errordialog "Unable to launch dmdirc!" "No jar file found";
  557. fi