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.

setup.sh 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #!/bin/sh
  2. #
  3. # This script launches the dmdirc java-based installer.
  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. # Check the which command exists, and if so make sure it behaves how we want
  26. # it to...
  27. WHICH=`which which 2>/dev/null`
  28. if [ "" = "${WHICH}" ]; then
  29. echo "which command not found. Aborting.";
  30. exit 0;
  31. else
  32. # Solaris sucks
  33. BADWHICH=`which /`
  34. if [ "${BADWHICH}" != "" ]; then
  35. echo "Replacing bad which command.";
  36. # "Which" on solaris gives non-empty results for commands that don't exist
  37. which() {
  38. OUT=`${WHICH} ${1}`
  39. if [ $? -eq 0 ]; then
  40. echo ${OUT}
  41. else
  42. echo ""
  43. fi;
  44. }
  45. fi;
  46. fi
  47. PIDOF=`which pidof`
  48. if [ "${PIDOF}" = "" ]; then
  49. # For some reason some distros hide pidof...
  50. if [ -e /sbin/pidof ]; then
  51. PIDOF=/sbin/pidof
  52. elif [ -e /usr/sbin/pidof ]; then
  53. PIDOF=/usr/sbin/pidof
  54. fi;
  55. fi;
  56. ## Helper Functions
  57. if [ "${PIDOF}" != "" ]; then
  58. ISKDE=`${PIDOF} -x -s kdeinit`
  59. ISGNOME=`${PIDOF} -x -s gnome-panel`
  60. else
  61. ISKDE=`ps -Af | grep kdeinit | grep -v grep`
  62. ISGNOME=`ps -Af | grep gnome-panel | grep -v grep`
  63. fi;
  64. KDIALOG=`which kdialog`
  65. ZENITY=`which zenity`
  66. errordialog() {
  67. # Send message to console.
  68. echo ""
  69. echo "-----------------------------------------------------------------------"
  70. echo "Error: ${1}"
  71. echo "-----------------------------------------------------------------------"
  72. echo "${2}"
  73. echo "-----------------------------------------------------------------------"
  74. # Now try to use the GUI Dialogs.
  75. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  76. echo "Dialog on Display: ${DISPLAY}"
  77. ${KDIALOG} --title "DMDirc: ${1}" --error "${2}"
  78. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  79. echo "Dialog on Display: ${DISPLAY}"
  80. ${ZENITY} --error --title "DMDirc: ${1}" --text "${2}"
  81. fi
  82. }
  83. UNAME=`uname -a`
  84. echo ""
  85. echo "---------------------"
  86. echo "Setup.sh"
  87. echo "---------------------"
  88. echo -n "Looking for java.. ";
  89. # Location where ports on FreeBSD/PCBSD installs java6
  90. # check it first, because it isn't added to the path automatically
  91. JAVA="/usr/local/jdk1.6.0/jre/bin/java"
  92. if [ ! -e "${JAVA}" ]; then
  93. JAVA=`which java`
  94. fi
  95. installjre() {
  96. result=1
  97. if [ ! -e "jre.bin" ]; then
  98. message="Would you like to download and install java?"
  99. if [ "install" != "${1}" ]; then
  100. message="Java was not detected on your machine. Would you like to download and install it now?"
  101. elif [ "upgrade" != "${1}" ]; then
  102. message="The version of java detected on your machine is not compatible with DMDirc. Would you like to download and install a compatible version now?"
  103. fi;
  104. /bin/sh getjre.sh "${message}"
  105. if [ $? -eq 0 ]; then
  106. /bin/sh installjre.sh
  107. result=$?
  108. fi;
  109. else
  110. message="Would you like to install java?"
  111. if [ "install" != "${1}" ]; then
  112. message="Java was not detected on your machine. Would you like to install it now?"
  113. elif [ "upgrade" != "${1}" ]; then
  114. message="The version of java detected on your machine is not compatible with DMDirc. Would you like to install a compatible version now?"
  115. fi;
  116. /bin/sh installjre.sh "${message}"
  117. result=$?
  118. fi;
  119. if [ ${result} -ne 0 ]; then
  120. if [ "upgrade" = "${1}" ]; then
  121. errordialog "DMDirc Setup" "Sorry, DMDirc setup can not continue without an updated version of java."
  122. else
  123. errordialog "DMDirc Setup" "Sorry, DMDirc setup can not continue without java."
  124. fi;
  125. exit 1;
  126. else
  127. if [ -e "${PWD}/java-bin" ]; then
  128. echo "Found JREBin: ${PWD}/java-bin"
  129. JAVA="${PWD}/java-bin"
  130. else
  131. JAVA=`which java`
  132. fi;
  133. fi;
  134. }
  135. if [ "" != "${JAVA}" ]; then
  136. echo "Success! ("${JAVA}")"
  137. else
  138. echo "Failed!"
  139. installjre "install"
  140. fi
  141. echo "Success!"
  142. if [ "${UID}" = "" ]; then
  143. UID=`id -u`;
  144. fi
  145. if [ "0" = "${UID}" ]; then
  146. echo "Running as root.."
  147. isRoot="--isroot";
  148. else
  149. echo "Running as user.."
  150. isRoot="";
  151. fi
  152. showHelp() {
  153. echo "This will setup DMDirc on a unix based system."
  154. echo "The following command line arguments are known:"
  155. echo "---------------------"
  156. echo "-h, --help Help information"
  157. echo "-r, --release [version] This is a release"
  158. # echo "-s, --script Don't use installer.jar (not implemented yet)"
  159. echo "---------------------"
  160. exit 0;
  161. }
  162. # Check for some CLI params
  163. scriptOnly="false"
  164. isRelease=""
  165. while test -n "$1"; do
  166. case "$1" in
  167. --script|-s)
  168. scriptOnly="true"
  169. shift
  170. ;;
  171. --release|-r)
  172. shift
  173. isRelease=${1}
  174. shift
  175. ;;
  176. --help|-h)
  177. showHelp;
  178. ;;
  179. esac
  180. done
  181. if [ "${isRelease}" != "" ]; then
  182. isRelease=" --release "${isRelease}
  183. fi
  184. if [ -e "DMDirc.jar" ]; then
  185. if [ "${scriptOnly}" = "true" ]; then
  186. echo "Script-only install requested."
  187. else
  188. echo "Running installer.."
  189. ${JAVA} -cp DMDirc.jar com.dmdirc.installer.Main ${isRoot}${isRelease}
  190. if [ $? -ne 0 ]; then
  191. installjre "upgrade"
  192. echo "Trying to run installer again.."
  193. ${JAVA} -cp DMDirc.jar com.dmdirc.installer.Main ${isRoot}${isRelease}
  194. if [ $? -ne 0 ]; then
  195. exit 1;
  196. fi;
  197. fi
  198. exit 0;
  199. fi
  200. else
  201. echo "No installer found!"
  202. fi
  203. ## Script-Only install goes here.
  204. echo "Script-Only functionality not implemented."
  205. exit 1;