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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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="8"
  26. params=""
  27. # Check the which command exists, and if so make sure it behaves how we want
  28. # it to...
  29. WHICH=`which which 2>/dev/null`
  30. if [ "" = "${WHICH}" ]; then
  31. echo "which command not found. Aborting.";
  32. exit 0;
  33. else
  34. # Solaris sucks
  35. BADWHICH=`which /`
  36. if [ "${BADWHICH}" != "" ]; then
  37. echo "Replacing bad which command.";
  38. # "Which" on solaris gives non-empty results for commands that don't exist
  39. which() {
  40. OUT=`${WHICH} ${1}`
  41. if [ $? -eq 0 ]; then
  42. echo ${OUT}
  43. else
  44. echo ""
  45. fi;
  46. }
  47. fi;
  48. fi
  49. # Store params so that we can pass them back to the client
  50. for param in "$@"; do
  51. PSN=`echo "${param}" | grep "^-psn_"`
  52. if [ "" = "${PSN}" ]; then
  53. SPACE=`echo "${param}" | grep " "`
  54. if [ "${SPACE}" != "" ]; then
  55. niceParam=`echo "${param}" | sed 's/"/\\\\"/g'`
  56. params=${params}" \"${niceParam}\""
  57. else
  58. params=${params}" ${param}"
  59. fi;
  60. fi;
  61. done;
  62. # Check for OS X
  63. OSASCRIPT=`which osascript`
  64. KERNEL=`uname -s`
  65. ISOSX="0"
  66. # Kernel is darwin, and osascript exists, probably OS X!
  67. if [ "${KERNEL}" = "Darwin" -a "" != "${OSASCRIPT}" ]; then
  68. ISOSX="1"
  69. fi;
  70. # Check for some CLI params
  71. if [ "${ISOSX}" = "1" ]; then
  72. profiledir="${HOME}/Library/Preferences/DMDirc"
  73. else
  74. profiledir="${HOME}/.DMDirc/"
  75. fi;
  76. while test -n "$1"; do
  77. case "$1" in
  78. --directory|-d)
  79. shift
  80. profiledir=${1}
  81. ;;
  82. esac
  83. shift
  84. done
  85. if [ "${ISOSX}" != "1" ]; then
  86. PIDOF=`which pidof`
  87. if [ "${PIDOF}" = "" ]; then
  88. # For some reason some distros hide pidof...
  89. if [ -e /sbin/pidof ]; then
  90. PIDOF=/sbin/pidof
  91. elif [ -e /usr/sbin/pidof ]; then
  92. PIDOF=/usr/sbin/pidof
  93. fi;
  94. fi;
  95. ## Helper Functions
  96. if [ "${PIDOF}" != "" ]; then
  97. ISKDE=`${PIDOF} -x -s kdeinit`
  98. ISGNOME=`${PIDOF} -x -s gnome-panel`
  99. else
  100. ISKDE=`ps -Af | grep kdeinit | grep -v grep`
  101. ISGNOME=`ps -Af | grep gnome-panel | grep -v grep`
  102. fi;
  103. KDIALOG=`which kdialog`
  104. ZENITY=`which zenity`
  105. KSUDO=`which kdesudo`
  106. GSUDO=`which gksudo`
  107. fi;
  108. errordialog() {
  109. # Send message to console.
  110. echo ""
  111. echo "-----------------------------------------------------------------------"
  112. echo "Error: ${1}"
  113. echo "-----------------------------------------------------------------------"
  114. echo "${2}"
  115. echo "-----------------------------------------------------------------------"
  116. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  117. echo "Displaying dialog.."
  118. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  119. else
  120. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  121. echo "Dialog on Display: ${DISPLAY}"
  122. ${KDIALOG} --title "DMDirc: ${1}" --error "${1}\n\n${2}"
  123. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  124. echo "Dialog on Display: ${DISPLAY}"
  125. ${ZENITY} --error --title "DMDirc: ${1}" --text "${1}\n\n${2}"
  126. fi
  127. fi;
  128. }
  129. messagedialog() {
  130. # Send message to console.
  131. echo ""
  132. echo "-----------------------------------------------------------------------"
  133. echo "Info: ${1}"
  134. echo "-----------------------------------------------------------------------"
  135. echo "${2}"
  136. echo "-----------------------------------------------------------------------"
  137. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  138. echo "Displaying dialog.."
  139. ${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'
  140. else
  141. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  142. echo "Dialog on Display: ${DISPLAY}"
  143. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${1}\n\n${2}"
  144. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  145. echo "Dialog on Display: ${DISPLAY}"
  146. ${ZENITY} --info --title "DMDirc: ${1}" --text "${1}\n\n${2}"
  147. fi
  148. fi;
  149. }
  150. if [ "${ISOSX}" = "1" ]; then
  151. jarDir=`dirname $0`/../Resources/Java/
  152. jar=${jarDir}DMDirc.jar
  153. else
  154. jar=`dirname $0`/DMDirc.jar
  155. fi
  156. launcherUpdater=${profiledir}/updateLauncher.sh
  157. BSDJava1="/usr/local/jdk1.6.0/jre/bin/java"
  158. BSDJava2="/usr/local/diablo-jdk1.6.0/jre/bin/java"
  159. echo "---------------------"
  160. echo "DMDirc - Open Source IRC Client"
  161. echo "Launcher Version: ${LAUNCHERVERSION}"
  162. echo "Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes"
  163. echo "---------------------"
  164. if [ "${ISOSX}" = "1" ]; then
  165. echo "Running on OS X."
  166. elif [ "${KERNEL}" = "Linux" ]; then
  167. echo "Running on Linux."
  168. elif [ "`echo ${KERNEL} | grep -i BSD`" != "" ]; then
  169. echo "Running on BSD."
  170. elif [ "`echo ${KERNEL} | grep -i SunOS`" != "" ]; then
  171. echo "Running on Solaris."
  172. else
  173. echo "Running on unknown unix variation: ${KERNEL}."
  174. fi;
  175. echo -n "Checking for launcher updates in ${profiledir} - ";
  176. if [ -e "${profiledir}/.launcher.sh.ignore" ]; then
  177. rm -Rf "${profiledir}/.launcher.sh.ignore"
  178. echo "Ignoring!";
  179. elif [ -e "${profiledir}/.launcher.sh" ]; then
  180. echo "Found!";
  181. echo "Attempting to update..";
  182. cat <<EOF> ${launcherUpdater}
  183. cd `dirname $0`
  184. errordialog() {
  185. # Send message to console.
  186. echo ""
  187. echo "-----------------------------------------------------------------------"
  188. echo "Error: \${1}"
  189. echo "-----------------------------------------------------------------------"
  190. echo "\${2}"
  191. echo "-----------------------------------------------------------------------"
  192. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  193. echo "Displaying dialog.."
  194. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  195. else
  196. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  197. echo "Dialog on Display: ${DISPLAY}"
  198. ${KDIALOG} --title "DMDirc: \${1}" --error "\${1}\n\n\${2}"
  199. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  200. echo "Dialog on Display: ${DISPLAY}"
  201. ${ZENITY} --error --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  202. fi
  203. fi
  204. }
  205. messagedialog() {
  206. # Send message to console.
  207. echo ""
  208. echo "-----------------------------------------------------------------------"
  209. echo "Info: \${1}"
  210. echo "-----------------------------------------------------------------------"
  211. echo "\${2}"
  212. echo "-----------------------------------------------------------------------"
  213. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  214. echo "Displaying dialog.."
  215. ${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'
  216. else
  217. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  218. echo "Dialog on Display: ${DISPLAY}"
  219. ${KDIALOG} --title "DMDirc: \${1}" --msgbox "\${1}\n\n\${2}"
  220. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  221. echo "Dialog on Display: ${DISPLAY}"
  222. ${ZENITY} --info --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  223. fi
  224. fi;
  225. }
  226. mv -fv ${profiledir}/.launcher.sh ${0}
  227. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  228. echo "Launcher Update successful."
  229. messagedialog "Launcher Update" "Launcher Update successful"
  230. else
  231. if [ "${UID}" = "" ]; then
  232. UID=`id -u`;
  233. fi
  234. if [ "0" != "${UID}" ]; then
  235. if [ "${ISOSX}" = "1" ]; then
  236. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  237. if [ $? -eq 0 ]; then
  238. echo "Password dialog on display"
  239. osascript -e do shell script "mv -fv \"${profiledir}/.launcher.sh\" \"${0}\"" with administrator privileges
  240. fi;
  241. else
  242. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  243. echo "Password dialog on ${DISPLAY}"
  244. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  245. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  246. echo "Password dialog on ${DISPLAY}"
  247. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  248. else
  249. echo "DMDirc Client Updater requires root access to modify the global installation"
  250. sudo mv -fv "${profiledir}/.launcher.sh" "${0}"
  251. fi;
  252. fi;
  253. fi
  254. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  255. echo "Update successful."
  256. messagedialog "Launcher Update" "Launcher Update successful"
  257. else
  258. echo "Launcher failed."
  259. errordialog "Launcher Update" "Launcher Update failed, using old version"
  260. touch ${profiledir}/.launcher.sh.ignore
  261. fi;
  262. fi;
  263. sh ${0} ${params}
  264. EOF
  265. chmod a+x ${launcherUpdater}
  266. ${launcherUpdater}
  267. exit 0;
  268. else
  269. echo "Not found.";
  270. fi;
  271. if [ -e "${launcherUpdater}" ]; then
  272. rm -Rf "${launcherUpdater}"
  273. fi;
  274. echo -n "Checking for client updates in ${profiledir} - ";
  275. if [ -e "${profiledir}/.DMDirc.jar" ]; then
  276. echo "Found!";
  277. echo "Attempting to update..";
  278. mv -fv ${profiledir}/.DMDirc.jar ${jar}
  279. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  280. echo "Update successful."
  281. messagedialog "Client Update" "Client Update successful"
  282. else
  283. if [ "${UID}" = "" ]; then
  284. UID=`id -u`;
  285. fi
  286. if [ "0" != "${UID}" ]; then
  287. if [ "${ISOSX}" = "1" ]; then
  288. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  289. if [ $? -eq 0 ]; then
  290. echo "Password dialog on display"
  291. osascript -e "do shell script \"mv -fv \\\"${profiledir}/.DMDirc.jar\\\" \\\"${jar}\\\"\" with administrator privileges"
  292. fi;
  293. else
  294. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  295. echo "Password dialog on ${DISPLAY}"
  296. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  297. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  298. echo "Password dialog on ${DISPLAY}"
  299. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  300. else
  301. echo "DMDirc Client Updater requires root access to modify the global installation"
  302. sudo mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  303. fi;
  304. fi;
  305. fi
  306. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  307. echo "Update successful."
  308. messagedialog "Client Update" "Client Update successful"
  309. else
  310. echo "Update failed."
  311. errordialog "Client Update" "Client Update failed, using old version"
  312. fi;
  313. fi
  314. else
  315. echo "Not found.";
  316. fi;
  317. echo -n "Looking for java - ";
  318. if [ "${ISOSX}" = "1" ]; then
  319. JAVA=`which java`
  320. if [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java" ]; then
  321. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java"
  322. elif [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java" ]; then
  323. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java"
  324. fi;
  325. else
  326. if [ -e "${HOME}/.profile" ]; then
  327. # Source the profile incase java can't be found otherwise
  328. . ${HOME}/.profile
  329. fi;
  330. JAVA=`which java`
  331. if [ ! -e "${JAVA}" ]; then
  332. # Location where ports on FreeBSD/PCBSD installs java6
  333. # check it first, because it isn't added to the path automatically
  334. JAVA=${BSDJava1}
  335. if [ ! -e "${JAVA}" ]; then
  336. # Try alternative BSD Location
  337. JAVA=${BSDJava2}
  338. fi;
  339. fi;
  340. fi;
  341. if [ "" != "${JAVA}" ]; then
  342. echo "Success! (${JAVA})"
  343. else
  344. echo "Failed!"
  345. ERROR="Sorry, java does not appear to be installed on this machine.";
  346. ERROR=${ERROR}"\n"
  347. if [ "${ISOSX}" = "1" ]; then
  348. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM.";
  349. else
  350. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  351. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  352. fi;
  353. errordialog "Unable to launch dmdirc!" "${ERROR}";
  354. exit 1;
  355. fi
  356. echo -n "Running DMDirc - "
  357. if [ -e "${jar}" ]; then
  358. # Check that DMDirc will run, if java is not 1.6 this will fail.
  359. # We do it this way otherwise segfaults etc would cause an unable to launch
  360. # error message to be printed.
  361. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  362. if [ $? -ne 0 ]; then
  363. FAILED=1
  364. # If we are on BSD, check to see if there is alternative versions of java
  365. # than the one in the path.
  366. if [ "`echo ${KERNEL} | grep -i BSD`" != "" ]; then
  367. if [ "${JAVA}" != "${BSDJava1}" -a "${JAVA}" != "${BSDJava2}" ]; then
  368. JAVA=${BSDJava1}
  369. if [ ! -e "${JAVA}" ]; then
  370. JAVA=${BSDJava2}
  371. fi;
  372. # Now check to see if DMDirc runs again.
  373. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  374. if [ $? -eq 0 ]; then
  375. # It runs!
  376. FAILED=0
  377. fi;
  378. fi;
  379. fi;
  380. if [ ${FAILED} -eq 1 ]; then
  381. echo "Failed."
  382. ERROR="Sorry, the currently installed version of java is not compatible with DMDirc.";
  383. ERROR=${ERROR}"\n";
  384. if [ "${ISOSX}" = "1" ]; then
  385. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM.";
  386. else
  387. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  388. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  389. fi;
  390. errordialog "Unable to launch dmdirc!" "${ERROR}";
  391. exit 1;
  392. fi;
  393. fi
  394. # Now we can run the client for real, this allows stderr/stdout output
  395. # to be seen, and the shell script exits with the correct exit code.
  396. APPLEOPTS=""
  397. if [ "${ISOSX}" = "1" ]; then
  398. APPLEOPTS="${APPLEOPTS} -Djava.library.path=${jarDir}"
  399. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.growbox.intrudes=false"
  400. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.live-resize=true"
  401. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.apple.menu.about.name=DMDirc"
  402. #APPLEOPTS="${APPLEOPTS} -Dapple.awt.showGrowBox=true"
  403. #APPLEOPTS="${APPLEOPTS} -Dapple.laf.useScreenMenuBar=true"
  404. fi;
  405. ${JAVA}${APPLEOPTS} -ea -jar ${jar} -l unix-${LAUNCHERVERSION} ${params}
  406. exit $?;
  407. else
  408. echo "Failed.";
  409. errordialog "Unable to launch dmdirc!" "No jar file found";
  410. fi