您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DMDirc.sh 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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-2008 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. echo "---------------------"
  158. echo "DMDirc - Open Source IRC Client"
  159. echo "Launcher Version: ${LAUNCHERVERSION}"
  160. echo "Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes"
  161. echo "---------------------"
  162. if [ "${ISOSX}" = "1" ]; then
  163. echo "Running on OS X."
  164. elif [ "${KERNEL}" = "Linux" ]; then
  165. echo "Running on Linux."
  166. elif [ "`echo ${KERNEL} | grep -i BSD`" != "" ]; then
  167. echo "Running on BSD."
  168. elif [ "`echo ${KERNEL} | grep -i SunOS`" != "" ]; then
  169. echo "Running on Solaris."
  170. else
  171. echo "Running on unknown unix variation: ${KERNEL}."
  172. fi;
  173. echo -n "Checking for launcher updates in ${profiledir} - ";
  174. if [ -e "${profiledir}/.launcher.sh.ignore" ]; then
  175. rm -Rf "${profiledir}/.launcher.sh.ignore"
  176. echo "Ignoring!";
  177. elif [ -e "${profiledir}/.launcher.sh" ]; then
  178. echo "Found!";
  179. echo "Attempting to update..";
  180. cat <<EOF> ${launcherUpdater}
  181. cd `dirname $0`
  182. errordialog() {
  183. # Send message to console.
  184. echo ""
  185. echo "-----------------------------------------------------------------------"
  186. echo "Error: \${1}"
  187. echo "-----------------------------------------------------------------------"
  188. echo "\${2}"
  189. echo "-----------------------------------------------------------------------"
  190. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  191. echo "Displaying dialog.."
  192. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  193. else
  194. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  195. echo "Dialog on Display: ${DISPLAY}"
  196. ${KDIALOG} --title "DMDirc: \${1}" --error "\${1}\n\n\${2}"
  197. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  198. echo "Dialog on Display: ${DISPLAY}"
  199. ${ZENITY} --error --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  200. fi
  201. fi
  202. }
  203. messagedialog() {
  204. # Send message to console.
  205. echo ""
  206. echo "-----------------------------------------------------------------------"
  207. echo "Info: \${1}"
  208. echo "-----------------------------------------------------------------------"
  209. echo "\${2}"
  210. echo "-----------------------------------------------------------------------"
  211. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  212. echo "Displaying dialog.."
  213. ${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'
  214. else
  215. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  216. echo "Dialog on Display: ${DISPLAY}"
  217. ${KDIALOG} --title "DMDirc: \${1}" --msgbox "\${1}\n\n\${2}"
  218. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  219. echo "Dialog on Display: ${DISPLAY}"
  220. ${ZENITY} --info --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  221. fi
  222. fi;
  223. }
  224. mv -fv ${profiledir}/.launcher.sh ${0}
  225. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  226. echo "Launcher Update successful."
  227. messagedialog "Launcher Update" "Launcher Update successful"
  228. else
  229. if [ "${UID}" = "" ]; then
  230. UID=`id -u`;
  231. fi
  232. if [ "0" != "${UID}" ]; then
  233. if [ "${ISOSX}" = "1" ]; then
  234. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  235. if [ $? -eq 0 ]; then
  236. echo "Password dialog on display"
  237. osascript -e do shell script "mv -fv \"${profiledir}/.launcher.sh\" \"${0}\"" with administrator privileges
  238. fi;
  239. else
  240. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  241. echo "Password dialog on ${DISPLAY}"
  242. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  243. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  244. echo "Password dialog on ${DISPLAY}"
  245. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  246. else
  247. echo "DMDirc Client Updater requires root access to modify the global installation"
  248. sudo mv -fv "${profiledir}/.launcher.sh" "${0}"
  249. fi;
  250. fi;
  251. fi
  252. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  253. echo "Update successful."
  254. messagedialog "Launcher Update" "Launcher Update successful"
  255. else
  256. echo "Launcher failed."
  257. errordialog "Launcher Update" "Launcher Update failed, using old version"
  258. touch ${profiledir}/.launcher.sh.ignore
  259. fi;
  260. fi;
  261. sh ${0} ${params}
  262. EOF
  263. chmod a+x ${launcherUpdater}
  264. ${launcherUpdater}
  265. exit 0;
  266. else
  267. echo "Not found.";
  268. fi;
  269. if [ -e "${launcherUpdater}" ]; then
  270. rm -Rf "${launcherUpdater}"
  271. fi;
  272. echo -n "Checking for client updates in ${profiledir} - ";
  273. if [ -e "${profiledir}/.DMDirc.jar" ]; then
  274. echo "Found!";
  275. echo "Attempting to update..";
  276. mv -fv ${profiledir}/.DMDirc.jar ${jar}
  277. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  278. echo "Update successful."
  279. messagedialog "Client Update" "Client Update successful"
  280. else
  281. if [ "${UID}" = "" ]; then
  282. UID=`id -u`;
  283. fi
  284. if [ "0" != "${UID}" ]; then
  285. if [ "${ISOSX}" = "1" ]; then
  286. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  287. if [ $? -eq 0 ]; then
  288. echo "Password dialog on display"
  289. osascript -e "do shell script \"mv -fv \\\"${profiledir}/.DMDirc.jar\\\" \\\"${jar}\\\"\" with administrator privileges"
  290. fi;
  291. else
  292. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  293. echo "Password dialog on ${DISPLAY}"
  294. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  295. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  296. echo "Password dialog on ${DISPLAY}"
  297. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  298. else
  299. echo "DMDirc Client Updater requires root access to modify the global installation"
  300. sudo mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  301. fi;
  302. fi;
  303. fi
  304. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  305. echo "Update successful."
  306. messagedialog "Client Update" "Client Update successful"
  307. else
  308. echo "Update failed."
  309. errordialog "Client Update" "Client Update failed, using old version"
  310. fi;
  311. fi
  312. else
  313. echo "Not found.";
  314. fi;
  315. echo -n "Looking for java - ";
  316. if [ "${ISOSX}" = "1" ]; then
  317. JAVA=`which java`
  318. if [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java" ]; then
  319. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java"
  320. elif [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java" ]; then
  321. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java"
  322. fi;
  323. else
  324. # Location where ports on FreeBSD/PCBSD installs java6
  325. # check it first, because it isn't added to the path automatically
  326. JAVA="/usr/local/jdk1.6.0/jre/bin/java"
  327. if [ ! -e "${JAVA}" ]; then
  328. # Try alternative BSD Location
  329. JAVA="/usr/local/diablo-jdk1.6.0/jre/bin/java"
  330. if [ ! -e "${JAVA}" ]; then
  331. # Look in path
  332. if [ -e "${HOME}/.profile" ]; then
  333. # Source the profile incase java can't be found otherwise
  334. . ${HOME}/.profile
  335. fi;
  336. JAVA=`which java`
  337. fi
  338. fi
  339. fi;
  340. if [ "" != "${JAVA}" ]; then
  341. echo "Success! (${JAVA})"
  342. else
  343. echo "Failed!"
  344. ERROR="Sorry, java does not appear to be installed on this machine.";
  345. ERROR=${ERROR}"\n"
  346. if [ "${ISOSX}" = "1" ]; then
  347. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM.";
  348. else
  349. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  350. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  351. fi;
  352. errordialog "Unable to launch dmdirc!" "${ERROR}";
  353. exit 1;
  354. fi
  355. echo -n "Running DMDirc - "
  356. if [ -e "${jar}" ]; then
  357. # Check that DMDirc will run, if java is not 1.6 this will fail.
  358. # We do it this way otherwise segfaults etc would cause an unable to launch
  359. # error message to be printed.
  360. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  361. if [ $? -ne 0 ]; then
  362. echo "Failed."
  363. ERROR="Sorry, the currently installed version of java is not compatible with DMDirc.";
  364. ERROR=${ERROR}"\n";
  365. if [ "${ISOSX}" = "1" ]; then
  366. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM.";
  367. else
  368. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  369. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  370. fi;
  371. errordialog "Unable to launch dmdirc!" "${ERROR}";
  372. exit 1;
  373. fi
  374. # Now we can run the client for real, this allows stderr/stdout output
  375. # to be seen, and the shell script exits with the correct exit code.
  376. APPLEOPTS=""
  377. if [ "${ISOSX}" = "1" ]; then
  378. APPLEOPTS="${APPLEOPTS} -Djava.library.path=${jarDir}"
  379. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.growbox.intrudes=false"
  380. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.live-resize=true"
  381. #APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.apple.menu.about.name=DMDirc"
  382. #APPLEOPTS="${APPLEOPTS} -Dapple.awt.showGrowBox=true"
  383. #APPLEOPTS="${APPLEOPTS} -Dapple.laf.useScreenMenuBar=true"
  384. fi;
  385. ${JAVA}${APPLEOPTS} -ea -jar ${jar} -l unix-${LAUNCHERVERSION} ${params}
  386. exit $?;
  387. else
  388. echo "Failed.";
  389. errordialog "Unable to launch dmdirc!" "No jar file found";
  390. fi