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

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-2007 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. # Check for some CLI params
  28. profiledir="${HOME}/.DMDirc/"
  29. while test -n "$1"; do
  30. case "$1" in
  31. --directory|-d)
  32. shift
  33. profiledir=${1}
  34. ;;
  35. esac
  36. shift
  37. done
  38. ISKDE=`pidof -x -s kdeinit`
  39. KDIALOG=`which kdialog`
  40. KSUDO=`which kdesudo`
  41. ISGNOME=`pidof -x -s gnome-panel`
  42. ZENITY=`which zenity`
  43. GSUDO=`which gksudo`
  44. errordialog() {
  45. # Send message to console.
  46. echo ""
  47. echo "-----------------------------------------------------------------------"
  48. echo "Error: ${1}"
  49. echo "-----------------------------------------------------------------------"
  50. echo "${2}"
  51. echo "-----------------------------------------------------------------------"
  52. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  53. echo "Dialog on Display: ${DISPLAY}"
  54. ${KDIALOG} --title "DMDirc: ${1}" --error "${1}\n\n${2}"
  55. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  56. echo "Dialog on Display: ${DISPLAY}"
  57. ${ZENITY} --error --title "DMDirc: ${1}" --text "${1}\n\n${2}"
  58. fi
  59. }
  60. messagedialog() {
  61. # Send message to console.
  62. echo ""
  63. echo "-----------------------------------------------------------------------"
  64. echo "Info: ${1}"
  65. echo "-----------------------------------------------------------------------"
  66. echo "${2}"
  67. echo "-----------------------------------------------------------------------"
  68. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  69. echo "Dialog on Display: ${DISPLAY}"
  70. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${1}\n\n${2}"
  71. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  72. echo "Dialog on Display: ${DISPLAY}"
  73. ${ZENITY} --info --title "DMDirc: ${1}" --text "${1}\n\n${2}"
  74. fi
  75. }
  76. jar=`dirname $0`/DMDirc.jar
  77. launcherUpdater=${profiledir}/updateLauncher.sh
  78. echo "---------------------"
  79. echo "DMDirc - Open Source IRC Client"
  80. echo "Launcher Version: ${LAUNCHERVERSION}"
  81. echo "Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes"
  82. echo "---------------------"
  83. echo -n "Checking for launcher updates in ${profiledir} - ";
  84. if [ -e "${profiledir}/.launcher.sh.ignore" ]; then
  85. rm -Rf "${profiledir}/.launcher.sh.ignore"
  86. echo "Ignoring!";
  87. elif [ -e "${profiledir}/.launcher.sh" ]; then
  88. echo "Found!";
  89. echo "Attempting to update..";
  90. cat <<EOF> ${launcherUpdater}
  91. cd `dirname $0`
  92. errordialog() {
  93. # Send message to console.
  94. echo ""
  95. echo "-----------------------------------------------------------------------"
  96. echo "Error: \${1}"
  97. echo "-----------------------------------------------------------------------"
  98. echo "\${2}"
  99. echo "-----------------------------------------------------------------------"
  100. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  101. echo "Dialog on Display: ${DISPLAY}"
  102. ${KDIALOG} --title "DMDirc: \${1}" --error "\${1}\n\n\${2}"
  103. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  104. echo "Dialog on Display: ${DISPLAY}"
  105. ${ZENITY} --error --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  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 [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  117. echo "Dialog on Display: ${DISPLAY}"
  118. ${KDIALOG} --title "DMDirc: \${1}" --msgbox "\${1}\n\n\${2}"
  119. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  120. echo "Dialog on Display: ${DISPLAY}"
  121. ${ZENITY} --info --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  122. fi
  123. }
  124. mv -fv ${profiledir}/.launcher.sh ${0}
  125. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  126. echo "Launcher Update successful."
  127. messagedialog "Launcher Update" "Launcher Update successful"
  128. else
  129. if [ "${UID}" = "" ]; then
  130. UID=`id -u`;
  131. fi
  132. if [ "0" != "${UID}" ]; then
  133. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  134. echo "Password dialog on ${DISPLAY}"
  135. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  136. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  137. echo "Password dialog on ${DISPLAY}"
  138. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  139. else
  140. echo "DMDirc Client Updater requires root access to modify the global installation"
  141. sudo mv -fv "${profiledir}/.launcher.sh" "${0}"
  142. fi;
  143. fi
  144. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  145. echo "Update successful."
  146. messagedialog "Launcher Update" "Launcher Update successful"
  147. else
  148. echo "Launcher failed."
  149. errordialog "Launcher Update" "Launcher Update failed, using old version"
  150. touch ${profiledir}/.launcher.sh.ignore
  151. fi;
  152. fi;
  153. sh ${0} ${params}
  154. EOF
  155. chmod a+x ${launcherUpdater}
  156. ${launcherUpdater}
  157. exit 0;
  158. else
  159. echo "Not found.";
  160. fi;
  161. if [ -e "${launcherUpdater}" ]; then
  162. rm -Rf "${launcherUpdater}"
  163. fi;
  164. echo -n "Checking for client updates in ${profiledir} - ";
  165. if [ -e "${profiledir}/.DMDirc.jar" ]; then
  166. echo "Found!";
  167. echo "Attempting to update..";
  168. mv -fv ${profiledir}/.DMDirc.jar ${jar}
  169. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  170. echo "Update successful."
  171. messagedialog "Client Update" "Client Update successful"
  172. else
  173. if [ "${UID}" = "" ]; then
  174. UID=`id -u`;
  175. fi
  176. if [ "0" != "${UID}" ]; then
  177. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  178. echo "Password dialog on ${DISPLAY}"
  179. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  180. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  181. echo "Password dialog on ${DISPLAY}"
  182. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  183. else
  184. echo "DMDirc Client Updater requires root access to modify the global installation"
  185. sudo mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  186. fi;
  187. fi
  188. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  189. echo "Update successful."
  190. messagedialog "Client Update" "Client Update successful"
  191. else
  192. echo "Update failed."
  193. errordialog "Client Update" "Client Update failed, using old version"
  194. fi;
  195. fi
  196. else
  197. echo "Not found.";
  198. fi;
  199. echo -n "Looking for java - ";
  200. JAVA=`which java`
  201. if [ "" != "${JAVA}" ]; then
  202. echo "Success!"
  203. else
  204. echo "Failed!"
  205. # This should in future offer to download and install the JVM automatically.
  206. ERROR="Sorry, java is not installed on this machine.";
  207. ERROR=${ERROR}"\n"
  208. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from:";
  209. ERROR=${ERROR}"\nhttp://jdl.sun.com/webapps/getjava/BrowserRedirect";
  210. errordialog "Unable to launch dmdirc!" "${ERROR}";
  211. exit 1;
  212. fi
  213. echo -n "Running DMDirc - "
  214. if [ -e "${jar}" ]; then
  215. # Check that DMDirc will run, if java is not 1.6 this will fail.
  216. # We do it this way otherwise segfaults etc would cause an unable to launch
  217. # error message to be printed.
  218. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  219. if [ $? -ne 0 ]; then
  220. echo "Failed."
  221. ERROR="Sorry, the currently installed version of java is not compatible with";
  222. ERROR=${ERROR}"\nDMDirc.";
  223. ERROR=${ERROR}"\n";
  224. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from:";
  225. ERROR=${ERROR}"\nhttp://jdl.sun.com/webapps/getjava/BrowserRedirect";
  226. errordialog "Unable to launch dmdirc!" "${ERROR}";
  227. exit 1;
  228. fi
  229. # Now we can run the client for real, this allows stderr/stdout output
  230. # to be seen, and the shell script exits with the correct exit code.
  231. ${JAVA} -ea -jar ${jar} -l linux-${LAUNCHERVERSION} ${params}
  232. exit $?;
  233. else
  234. echo "Failed.";
  235. errordialog "Unable to launch dmdirc!" "No jar file found";
  236. fi