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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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="1"
  26. params=""
  27. # Store params so that we can pass them back to the client
  28. for param in "$@"; do
  29. PSN=`echo "${param}" | grep "^-psn_"`
  30. if [ "" = "${PSN}" ]; then
  31. SPACE=`echo "${param}" | grep " "`
  32. if [ "${SPACE}" != "" ]; then
  33. niceParam=`echo "${param}" | sed 's/"/\\\\"/g'`
  34. params=${params}" \"${niceParam}\""
  35. else
  36. params=${params}" ${param}"
  37. fi;
  38. fi;
  39. done;
  40. # Check for some CLI params
  41. profiledir="${HOME}/Library/Preferences/DMDirc"
  42. while test -n "$1"; do
  43. case "$1" in
  44. --directory|-d)
  45. shift
  46. profiledir=${1}
  47. ;;
  48. esac
  49. shift
  50. done
  51. OSASCRIPT=`which osascript`
  52. errordialog() {
  53. # Send message to console.
  54. echo ""
  55. echo "-----------------------------------------------------------------------"
  56. echo "Error: ${1}"
  57. echo "-----------------------------------------------------------------------"
  58. echo "${2}"
  59. echo "-----------------------------------------------------------------------"
  60. if [ "" != "${OSASCRIPT}" ]; then
  61. echo "Displaying dialog.."
  62. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  63. fi;
  64. }
  65. messagedialog() {
  66. # Send message to console.
  67. echo ""
  68. echo "-----------------------------------------------------------------------"
  69. echo "Info: ${1}"
  70. echo "-----------------------------------------------------------------------"
  71. echo "${2}"
  72. echo "-----------------------------------------------------------------------"
  73. if [ "" != "${OSASCRIPT}" ]; then
  74. echo "Displaying dialog.."
  75. ${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'
  76. fi;
  77. }
  78. jar=`dirname $0`/../Resources/Java/DMDirc.jar
  79. launcherUpdater=${profiledir}/updateLauncher.sh
  80. echo "---------------------"
  81. echo "DMDirc - Open Source IRC Client"
  82. echo "Launcher Version: ${LAUNCHERVERSION}"
  83. echo "Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes"
  84. echo "---------------------"
  85. echo -n "Checking for launcher updates in ${profiledir} - ";
  86. if [ -e "${profiledir}/.launcher.sh.ignore" ]; then
  87. rm -Rf "${profiledir}/.launcher.sh.ignore"
  88. echo "Ignoring!";
  89. elif [ -e "${profiledir}/.launcher.sh" ]; then
  90. echo "Found!";
  91. echo "Attempting to update..";
  92. cat <<EOF> ${launcherUpdater}
  93. cd `dirname $0`
  94. OSASCRIPT=`which osascript`
  95. errordialog() {
  96. # Send message to console.
  97. echo ""
  98. echo "-----------------------------------------------------------------------"
  99. echo "Error: \${1}"
  100. echo "-----------------------------------------------------------------------"
  101. echo "\${2}"
  102. echo "-----------------------------------------------------------------------"
  103. if [ "" != "${OSASCRIPT}" ]; then
  104. echo "Displaying dialog.."
  105. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  106. fi;
  107. }
  108. messagedialog() {
  109. # Send message to console.
  110. echo ""
  111. echo "-----------------------------------------------------------------------"
  112. echo "Info: \${1}"
  113. echo "-----------------------------------------------------------------------"
  114. echo "\${2}"
  115. echo "-----------------------------------------------------------------------"
  116. if [ "" != "${OSASCRIPT}" ]; then
  117. echo "Displaying dialog.."
  118. ${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'
  119. fi;
  120. }
  121. mv -fv ${profiledir}/.launcher.sh ${0}
  122. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  123. echo "Launcher Update successful."
  124. messagedialog "Launcher Update" "Launcher Update successful"
  125. else
  126. if [ "${UID}" = "" ]; then
  127. UID=`id -u`;
  128. fi
  129. if [ "0" != "${UID}" ]; then
  130. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  131. if [ $? -eq 0 ]; then
  132. echo "Password dialog on display"
  133. osascript -e do shell script "mv -fv \"${profiledir}/.launcher.sh\" \"${0}\"" with administrator privileges
  134. fi;
  135. fi
  136. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  137. echo "Update successful."
  138. messagedialog "Launcher Update" "Launcher Update successful"
  139. else
  140. echo "Launcher failed."
  141. errordialog "Launcher Update" "Launcher Update failed, using old version"
  142. touch ${profiledir}/.launcher.sh.ignore
  143. fi;
  144. fi;
  145. sh ${0} ${params}
  146. EOF
  147. chmod a+x ${launcherUpdater}
  148. ${launcherUpdater}
  149. exit 0;
  150. else
  151. echo "Not found.";
  152. fi;
  153. if [ -e "${launcherUpdater}" ]; then
  154. rm -Rf "${launcherUpdater}"
  155. fi;
  156. echo -n "Checking for client updates in ${profiledir} - ";
  157. if [ -e "${profiledir}/.DMDirc.jar" ]; then
  158. echo "Found!";
  159. echo "Attempting to update..";
  160. mv -fv ${profiledir}/.DMDirc.jar ${jar}
  161. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  162. echo "Update successful."
  163. messagedialog "Client Update" "Client Update successful"
  164. else
  165. if [ "${UID}" = "" ]; then
  166. UID=`id -u`;
  167. fi
  168. if [ "0" != "${UID}" ]; then
  169. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  170. if [ $? -eq 0 ]; then
  171. echo "Password dialog on display"
  172. osascript -e "do shell script \"mv -fv \\\"${profiledir}/.launcher.sh\\\" \\\"${0}\\\"\" with administrator privileges"
  173. fi;
  174. fi
  175. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  176. echo "Update successful."
  177. messagedialog "Client Update" "Client Update successful"
  178. else
  179. echo "Update failed."
  180. errordialog "Client Update" "Client Update failed, using old version"
  181. fi;
  182. fi
  183. else
  184. echo "Not found.";
  185. fi;
  186. echo -n "Looking for java - ";
  187. JAVA=`which java`
  188. if [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java" ]; then
  189. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java"
  190. elif [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java" ]; then
  191. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java"
  192. fi;
  193. if [ "" != "${JAVA}" ]; then
  194. echo "Success!"
  195. else
  196. echo "Failed!"
  197. ERROR="Sorry, java is not installed on this machine.";
  198. ERROR=${ERROR}"\n"
  199. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, this is currently:";
  200. ERROR=${ERROR}"\nonly availble as a Developer Preview from the Apple Developer site.";
  201. errordialog "Unable to launch dmdirc!" "${ERROR}";
  202. exit 1;
  203. fi
  204. echo -n "Running DMDirc - "
  205. if [ -e "${jar}" ]; then
  206. # Check that DMDirc will run, if java is not 1.6 this will fail.
  207. # We do it this way otherwise segfaults etc would cause an unable to launch
  208. # error message to be printed.
  209. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  210. if [ $? -ne 0 ]; then
  211. echo "Failed."
  212. ERROR="Sorry, the currently installed version of java is not compatible with";
  213. ERROR=${ERROR}"\nDMDirc.";
  214. ERROR=${ERROR}"\n";
  215. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, this is currently:";
  216. ERROR=${ERROR}"\nonly availble as a Developer Preview from the Apple Developer site.";
  217. errordialog "Unable to launch dmdirc!" "${ERROR}";
  218. exit 1;
  219. fi
  220. # Now we can run the client for real, this allows stderr/stdout output
  221. # to be seen, and the shell script exits with the correct exit code.
  222. APPLEOPTS=""
  223. # APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.growbox.intrudes=false"
  224. # APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.live-resize=true"
  225. # APPLEOPTS="${APPLEOPTS} -Dcom.apple.mrj.application.apple.menu.about.name=DMDirc"
  226. # APPLEOPTS="${APPLEOPTS} -Dapple.awt.showGrowBox=true"
  227. # APPLEOPTS="${APPLEOPTS} -Dapple.laf.useScreenMenuBar=true"
  228. ${JAVA}${APPLEOPTS} -ea -jar ${jar} -l osx-${LAUNCHERVERSION} ${params}
  229. exit $?;
  230. else
  231. echo "Failed.";
  232. errordialog "Unable to launch dmdirc!" "No jar file found";
  233. fi