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

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