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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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="4"
  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. PIDOF=`which pidof`
  49. if [ "${PIDOF}" = "" ]; then
  50. # For some reason some distros hide pidof...
  51. if [ -e /sbin/pidof ]; then
  52. PIDOF=/sbin/pidof
  53. elif [ -e /usr/sbin/pidof ]; then
  54. PIDOF=/usr/sbin/pidof
  55. fi;
  56. fi;
  57. ## Helper Functions
  58. if [ "${PIDOF}" != "" ]; then
  59. ISKDE=`${PIDOF} -x -s kdeinit`
  60. ISGNOME=`${PIDOF} -x -s gnome-panel`
  61. else
  62. ISKDE=`ps -Af | grep kdeinit | grep -v grep`
  63. ISGNOME=`ps -Af | grep gnome-panel | grep -v grep`
  64. fi;
  65. KDIALOG=`which kdialog`
  66. ZENITY=`which zenity`
  67. KSUDO=`which kdesudo`
  68. GSUDO=`which gksudo`
  69. errordialog() {
  70. # Send message to console.
  71. echo ""
  72. echo "-----------------------------------------------------------------------"
  73. echo "Error: ${1}"
  74. echo "-----------------------------------------------------------------------"
  75. echo "${2}"
  76. echo "-----------------------------------------------------------------------"
  77. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  78. echo "Dialog on Display: ${DISPLAY}"
  79. ${KDIALOG} --title "DMDirc: ${1}" --error "${1}\n\n${2}"
  80. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  81. echo "Dialog on Display: ${DISPLAY}"
  82. ${ZENITY} --error --title "DMDirc: ${1}" --text "${1}\n\n${2}"
  83. fi
  84. }
  85. messagedialog() {
  86. # Send message to console.
  87. echo ""
  88. echo "-----------------------------------------------------------------------"
  89. echo "Info: ${1}"
  90. echo "-----------------------------------------------------------------------"
  91. echo "${2}"
  92. echo "-----------------------------------------------------------------------"
  93. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  94. echo "Dialog on Display: ${DISPLAY}"
  95. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${1}\n\n${2}"
  96. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  97. echo "Dialog on Display: ${DISPLAY}"
  98. ${ZENITY} --info --title "DMDirc: ${1}" --text "${1}\n\n${2}"
  99. fi
  100. }
  101. jar=`dirname $0`/DMDirc.jar
  102. launcherUpdater=${profiledir}/updateLauncher.sh
  103. echo "---------------------"
  104. echo "DMDirc - Open Source IRC Client"
  105. echo "Launcher Version: ${LAUNCHERVERSION}"
  106. echo "Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes"
  107. echo "---------------------"
  108. echo -n "Checking for launcher updates in ${profiledir} - ";
  109. if [ -e "${profiledir}/.launcher.sh.ignore" ]; then
  110. rm -Rf "${profiledir}/.launcher.sh.ignore"
  111. echo "Ignoring!";
  112. elif [ -e "${profiledir}/.launcher.sh" ]; then
  113. echo "Found!";
  114. echo "Attempting to update..";
  115. cat <<EOF> ${launcherUpdater}
  116. cd `dirname $0`
  117. errordialog() {
  118. # Send message to console.
  119. echo ""
  120. echo "-----------------------------------------------------------------------"
  121. echo "Error: \${1}"
  122. echo "-----------------------------------------------------------------------"
  123. echo "\${2}"
  124. echo "-----------------------------------------------------------------------"
  125. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  126. echo "Dialog on Display: ${DISPLAY}"
  127. ${KDIALOG} --title "DMDirc: \${1}" --error "\${1}\n\n\${2}"
  128. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  129. echo "Dialog on Display: ${DISPLAY}"
  130. ${ZENITY} --error --title "DMDirc: \${1}" --text "\${1}\n\n\${2}"
  131. fi
  132. }
  133. messagedialog() {
  134. # Send message to console.
  135. echo ""
  136. echo "-----------------------------------------------------------------------"
  137. echo "Info: \${1}"
  138. echo "----------------------------------------------------------------------"
  139. echo "\${2}"
  140. echo "-----------------------------------------------------------------------"
  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. }
  149. mv -fv ${profiledir}/.launcher.sh ${0}
  150. if [ ! -e "${profiledir}/.launcher.sh" ]; then
  151. echo "Launcher Update successful."
  152. messagedialog "Launcher Update" "Launcher Update successful"
  153. else
  154. if [ "${UID}" = "" ]; then
  155. UID=`id -u`;
  156. fi
  157. if [ "0" != "${UID}" ]; then
  158. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  159. echo "Password dialog on ${DISPLAY}"
  160. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  161. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  162. echo "Password dialog on ${DISPLAY}"
  163. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" -- mv -fv "${profiledir}/.launcher.sh" "${0}"
  164. else
  165. echo "DMDirc Client Updater requires root access to modify the global installation"
  166. sudo mv -fv "${profiledir}/.launcher.sh" "${0}"
  167. fi;
  168. fi
  169. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  170. echo "Update successful."
  171. messagedialog "Launcher Update" "Launcher Update successful"
  172. else
  173. echo "Launcher failed."
  174. errordialog "Launcher Update" "Launcher Update failed, using old version"
  175. touch ${profiledir}/.launcher.sh.ignore
  176. fi;
  177. fi;
  178. sh ${0} ${params}
  179. EOF
  180. chmod a+x ${launcherUpdater}
  181. ${launcherUpdater}
  182. exit 0;
  183. else
  184. echo "Not found.";
  185. fi;
  186. if [ -e "${launcherUpdater}" ]; then
  187. rm -Rf "${launcherUpdater}"
  188. fi;
  189. echo -n "Checking for client updates in ${profiledir} - ";
  190. if [ -e "${profiledir}/.DMDirc.jar" ]; then
  191. echo "Found!";
  192. echo "Attempting to update..";
  193. mv -fv ${profiledir}/.DMDirc.jar ${jar}
  194. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  195. echo "Update successful."
  196. messagedialog "Client Update" "Client Update successful"
  197. else
  198. if [ "${UID}" = "" ]; then
  199. UID=`id -u`;
  200. fi
  201. if [ "0" != "${UID}" ]; then
  202. if [ "" != "${ISKDE}" -a "" != "${KSUDO}" -a "" != "${DISPLAY}" ]; then
  203. echo "Password dialog on ${DISPLAY}"
  204. ${KSUDO} --comment "DMDirc Client Updater requires root access to modify the global installation" mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  205. elif [ "" != "${ISGNOME}" -a "" != "${GSUDO}" -a "" != "${DISPLAY}" ]; then
  206. echo "Password dialog on ${DISPLAY}"
  207. ${GSUDO} -k --message "DMDirc Client Updater requires root access to modify the global installation" mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  208. else
  209. echo "DMDirc Client Updater requires root access to modify the global installation"
  210. sudo mv -fv "${profiledir}/.DMDirc.jar" "${jar}"
  211. fi;
  212. fi
  213. if [ ! -e "${profiledir}/.DMDirc.jar" ]; then
  214. echo "Update successful."
  215. messagedialog "Client Update" "Client Update successful"
  216. else
  217. echo "Update failed."
  218. errordialog "Client Update" "Client Update failed, using old version"
  219. fi;
  220. fi
  221. else
  222. echo "Not found.";
  223. fi;
  224. echo -n "Looking for java - ";
  225. # Check for BSD Ports version of java first as its not always in the path
  226. JAVA="/usr/local/jdk1.6.0/jre/bin/java"
  227. if [ ! -e "${JAVA}" ]; then
  228. JAVA=`which java`
  229. fi
  230. if [ "" != "${JAVA}" ]; then
  231. echo "Success! (${JAVA})"
  232. else
  233. echo "Failed!"
  234. ERROR="Sorry, java does ont appear to be installed on this machine.";
  235. ERROR=${ERROR}"\n"
  236. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  237. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  238. errordialog "Unable to launch dmdirc!" "${ERROR}";
  239. exit 1;
  240. fi
  241. echo -n "Running DMDirc - "
  242. if [ -e "${jar}" ]; then
  243. # Check that DMDirc will run, if java is not 1.6 this will fail.
  244. # We do it this way otherwise segfaults etc would cause an unable to launch
  245. # error message to be printed.
  246. ${JAVA} -jar ${jar} --help >/dev/null 2>&1
  247. if [ $? -ne 0 ]; then
  248. echo "Failed."
  249. ERROR="Sorry, the currently installed version of java is not compatible with DMDirc.";
  250. ERROR=${ERROR}"\n";
  251. ERROR=${ERROR}"\nDMDirc requires a 1.6.0 compatible JVM, you can get one from: http://www.java.com";
  252. ERROR=${ERROR}"\nor reinstall DMDirc and let the installer install one for you.";
  253. errordialog "Unable to launch dmdirc!" "${ERROR}";
  254. exit 1;
  255. fi
  256. # Now we can run the client for real, this allows stderr/stdout output
  257. # to be seen, and the shell script exits with the correct exit code.
  258. ${JAVA} -ea -jar ${jar} -l linux-${LAUNCHERVERSION} ${params}
  259. exit $?;
  260. else
  261. echo "Failed.";
  262. errordialog "Unable to launch dmdirc!" "No jar file found";
  263. fi