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

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