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

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="3"
  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. jarDir=`dirname $0`/../Resources/Java/
  79. jar=${jarDir}DMDirc.jar
  80. launcherUpdater=${profiledir}/updateLauncher.sh
  81. echo "---------------------"
  82. echo "DMDirc - Open Source IRC Client"
  83. echo "Launcher Version: ${LAUNCHERVERSION}"
  84. echo "Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes"
  85. echo "---------------------"
  86. echo -n "Checking for launcher updates in ${profiledir} - ";
  87. if [ -e "${profiledir}/.launcher.sh.ignore" ]; then
  88. rm -Rf "${profiledir}/.launcher.sh.ignore"
  89. echo "Ignoring!";
  90. elif [ -e "${profiledir}/.launcher.sh" ]; then
  91. echo "Found!";
  92. echo "Attempting to update..";
  93. cat <<EOF> ${launcherUpdater}
  94. cd `dirname $0`
  95. OSASCRIPT=`which osascript`
  96. errordialog() {
  97. # Send message to console.
  98. echo ""
  99. echo "-----------------------------------------------------------------------"
  100. echo "Error: \${1}"
  101. echo "-----------------------------------------------------------------------"
  102. echo "\${2}"
  103. echo "-----------------------------------------------------------------------"
  104. if [ "" != "${OSASCRIPT}" ]; then
  105. echo "Displaying dialog.."
  106. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  107. fi;
  108. }
  109. messagedialog() {
  110. # Send message to console.
  111. echo ""
  112. echo "-----------------------------------------------------------------------"
  113. echo "Info: \${1}"
  114. echo "-----------------------------------------------------------------------"
  115. echo "\${2}"
  116. echo "-----------------------------------------------------------------------"
  117. if [ "" != "${OSASCRIPT}" ]; then
  118. echo "Displaying dialog.."
  119. ${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'
  120. fi;
  121. }
  122. mv -fv ${profiledir}/.launcher.sh ${0}
  123. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  124. echo "Launcher Update successful."
  125. messagedialog "Launcher Update" "Launcher Update successful"
  126. else
  127. if [ "${UID}" = "" ]; then
  128. UID=`id -u`;
  129. fi
  130. if [ "0" != "${UID}" ]; then
  131. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  132. if [ $? -eq 0 ]; then
  133. echo "Password dialog on display"
  134. osascript -e do shell script "mv -fv \"${profiledir}/.launcher.sh\" \"${0}\"" with administrator privileges
  135. fi;
  136. fi
  137. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  138. echo "Update successful."
  139. messagedialog "Launcher Update" "Launcher Update successful"
  140. else
  141. echo "Launcher failed."
  142. errordialog "Launcher Update" "Launcher Update failed, using old version"
  143. touch ${profiledir}/.launcher.sh.ignore
  144. fi;
  145. fi;
  146. sh ${0} ${params}
  147. EOF
  148. chmod a+x ${launcherUpdater}
  149. ${launcherUpdater}
  150. exit 0;
  151. else
  152. echo "Not found.";
  153. fi;
  154. if [ -e "${launcherUpdater}" ]; then
  155. rm -Rf "${launcherUpdater}"
  156. fi;
  157. echo -n "Checking for client updates in ${profiledir} - ";
  158. if [ -e "${profiledir}/.DMDirc.jar" ]; then
  159. echo "Found!";
  160. echo "Attempting to update..";
  161. mv -fv ${profiledir}/.DMDirc.jar ${jar}
  162. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  163. echo "Update successful."
  164. messagedialog "Client Update" "Client Update successful"
  165. else
  166. if [ "${UID}" = "" ]; then
  167. UID=`id -u`;
  168. fi
  169. if [ "0" != "${UID}" ]; then
  170. messagedialog "DMDirc" "The DMDirc Client Updater was unable to modify the client installation, trying again with administrator access"
  171. if [ $? -eq 0 ]; then
  172. echo "Password dialog on display"
  173. osascript -e "do shell script \"mv -fv \\\"${profiledir}/.DMDirc.jar\\\" \\\"${jar}\\\"\" with administrator privileges"
  174. fi;
  175. fi
  176. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  177. echo "Update successful."
  178. messagedialog "Client Update" "Client Update successful"
  179. else
  180. echo "Update failed."
  181. errordialog "Client Update" "Client Update failed, using old version"
  182. fi;
  183. fi
  184. else
  185. echo "Not found.";
  186. fi;
  187. echo -n "Looking for java - ";
  188. JAVA=`which java`
  189. if [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java" ]; then
  190. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java"
  191. elif [ -e "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java" ]; then
  192. JAVA="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java"
  193. fi;
  194. if [ "" != "${JAVA}" ]; then
  195. echo "Success!"
  196. else
  197. echo "Failed!"
  198. ERROR="Sorry, java is not installed on this machine.";
  199. ERROR=${ERROR}"\n"
  200. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM.";
  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.";
  216. errordialog "Unable to launch dmdirc!" "${ERROR}";
  217. exit 1;
  218. fi
  219. # Now we can run the client for real, this allows stderr/stdout output
  220. # to be seen, and the shell script exits with the correct exit code.
  221. APPLEOPTS=""
  222. APPLEOPTS="${APPLEOPTS} -Djava.library.path=${jarDir}"
  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