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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. questiondialog() {
  84. # Send question to console.
  85. echo ""
  86. echo "-----------------------------------------------------------------------"
  87. echo "Question: ${1}"
  88. echo "-----------------------------------------------------------------------"
  89. echo "${2}"
  90. echo "-----------------------------------------------------------------------"
  91. # Now try to use the GUI Dialogs.
  92. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  93. echo "Dialog on Display: ${DISPLAY}"
  94. ${KDIALOG} --title "${1}" --yesno "${2}"
  95. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  96. echo "Dialog on Display: ${DISPLAY}"
  97. ${ZENITY} --question --title "${1}" --text "${2}"
  98. else
  99. if [ "${3}" != "" ]; then
  100. echo "Unable to ask question, assuming '${3}'."
  101. return ${3};
  102. else
  103. echo "Unable to ask question, assuming no."
  104. return 1;
  105. fi;
  106. fi
  107. }
  108. UNAME=`uname -a`
  109. echo ""
  110. echo "---------------------"
  111. echo "Setup.sh"
  112. echo "---------------------"
  113. echo -n "Looking for java.. ";
  114. # Location where ports on FreeBSD/PCBSD installs java6
  115. # check it first, because it isn't added to the path automatically
  116. JAVA="/usr/local/jdk1.6.0/jre/bin/java"
  117. if [ ! -e "${JAVA}" ]; then
  118. # Try alternative BSD Location
  119. JAVA="/usr/local/diablo-jdk1.6.0/jre/bin/java"
  120. if [ ! -e "${JAVA}" ]; then
  121. # Look in path
  122. if [ -e "${HOME}/.profile" ]; then
  123. # Source the profile incase java can't be found otherwise
  124. . ${HOME}/.profile
  125. fi;
  126. JAVA=`which java`
  127. fi
  128. fi
  129. installjre() {
  130. result=1
  131. if [ ! -e "jre.bin" ]; then
  132. message="Would you like to download and install java?"
  133. if [ "install" = "${1}" ]; then
  134. message="Java was not detected on your machine. Would you like to download and install it now?"
  135. elif [ "upgrade" = "${1}" ]; then
  136. 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?"
  137. fi;
  138. /bin/sh getjre.sh "${message}"
  139. if [ $? -eq 0 ]; then
  140. /bin/sh installjre.sh
  141. result=$?
  142. fi;
  143. else
  144. message="Would you like to install java?"
  145. if [ "install" = "${1}" ]; then
  146. message="Java was not detected on your machine. Would you like to install it now?"
  147. elif [ "upgrade" = "${1}" ]; then
  148. message="The version of java detected on your machine is not compatible with DMDirc. Would you like to install a compatible version now?"
  149. fi;
  150. /bin/sh installjre.sh "${message}"
  151. result=$?
  152. fi;
  153. if [ ${result} -ne 0 ]; then
  154. if [ "upgrade" = "${1}" ]; then
  155. errordialog "DMDirc Setup" "Sorry, DMDirc setup can not continue without an updated version of java."
  156. else
  157. errordialog "DMDirc Setup" "Sorry, DMDirc setup can not continue without java."
  158. fi;
  159. exit 1;
  160. else
  161. if [ -e "${PWD}/java-bin" ]; then
  162. echo "Found JREBin: ${PWD}/java-bin"
  163. JAVA="${PWD}/java-bin"
  164. else
  165. JAVA=`which java`
  166. fi;
  167. fi;
  168. }
  169. if [ "" != "${JAVA}" ]; then
  170. echo "Success! ("${JAVA}")"
  171. else
  172. echo "Failed!"
  173. installjre "install"
  174. fi
  175. echo "Success!"
  176. if [ "${UID}" = "" ]; then
  177. UID=`id -u`;
  178. fi
  179. if [ "0" = "${UID}" ]; then
  180. echo "Running as root.."
  181. isRoot="--isroot";
  182. else
  183. echo "Running as user.."
  184. isRoot="";
  185. fi
  186. showHelp() {
  187. echo "This will setup DMDirc on a unix based system."
  188. echo "The following command line arguments are known:"
  189. echo "---------------------"
  190. echo "-h, --help Help information"
  191. echo "-r, --release [version] This is a release"
  192. echo "---------------------"
  193. exit 0;
  194. }
  195. # Check for some CLI params
  196. isRelease=""
  197. while test -n "$1"; do
  198. case "$1" in
  199. --release|-r)
  200. shift
  201. isRelease=${1}
  202. shift
  203. ;;
  204. --help|-h)
  205. showHelp;
  206. ;;
  207. esac
  208. done
  209. if [ "${isRelease}" != "" ]; then
  210. isRelease=" --release "${isRelease}
  211. fi
  212. if [ -e "DMDirc.jar" ]; then
  213. echo "Checking for openJDK.."
  214. ISOPENJDK=`${JAVA} -version 2>&1 | grep -i openjdk`
  215. if [ "" != "${ISOPENJDK}" ]; then
  216. message="The DMDirc installer has detected that you are using OpenJDK. There are currently known issues with some versions of OpenJDK and DMDirc. To ensure DMDirc runs optimally we recommend you use the Sun JRE."
  217. message="${message}\n\nWould you like to continue anyway?"
  218. questiondialog "OpenJDK" "${message}" 0
  219. if [ $? -ne 0 ]; then
  220. echo "Aborting."
  221. exit 1;
  222. fi;
  223. fi;
  224. echo "Checking java version.."
  225. ${JAVA} -cp DMDirc.jar com.dmdirc.installer.Main --help >/dev/null
  226. if [ $? -ne 0 ]; then
  227. installjre "upgrade"
  228. echo "Trying to run installer.."
  229. ${JAVA} -cp DMDirc.jar com.dmdirc.installer.Main ${isRoot}${isRelease}
  230. if [ $? -ne 0 ]; then
  231. exit 1;
  232. fi;
  233. else
  234. echo "Running installer.."
  235. ${JAVA} -cp DMDirc.jar com.dmdirc.installer.Main ${isRoot}${isRelease}
  236. exit $?
  237. fi
  238. else
  239. echo "No installer found!"
  240. fi
  241. ## Script-Only install goes here.
  242. echo "Script-Only functionality not implemented."
  243. exit 1;