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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #!/bin/sh
  2. #
  3. # This script launches the dmdirc java-based installer.
  4. #
  5. # DMDirc - Open Source IRC Client
  6. # Copyright (c) 2006-2010 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. if [ -e "functions.sh" ]; then
  57. . `dirname $0`/functions.sh
  58. else
  59. echo "Unable to find functions.sh, unable to continue."
  60. exit 1;
  61. fi;
  62. UNAME=`uname -a`
  63. # Store params so that we can pass them back to ourself if needed.
  64. for param in "$@"; do
  65. PSN=`echo "${param}" | grep "^-psn_"`
  66. if [ "" = "${PSN}" ]; then
  67. SPACE=`echo "${param}" | grep " "`
  68. if [ "${SPACE}" != "" ]; then
  69. niceParam=`echo "${param}" | sed 's/"/\\\\"/g'`
  70. params=${params}" \"${niceParam}\""
  71. else
  72. params=${params}" ${param}"
  73. fi;
  74. fi;
  75. done;
  76. # Check for some CLI params
  77. isRelease=""
  78. USEPROFILE=1;
  79. while test -n "$1"; do
  80. case "$1" in
  81. --release|-r)
  82. shift
  83. isRelease=${1}
  84. ;;
  85. --help|-h)
  86. showHelp;
  87. ;;
  88. --noprofile)
  89. USEPROFILE=0;
  90. ;;
  91. esac
  92. shift;
  93. done
  94. relaunch() {
  95. trap - INT TERM EXIT
  96. echo ""
  97. echo "============================================================="
  98. echo "ERROR"
  99. echo "============================================================="
  100. echo "${HOME}/.profile has errors in it (or an 'exit' command)."
  101. echo "Setup will now restart with the --noprofile option."
  102. echo "============================================================="
  103. sh ${0} ${params} --noprofile
  104. }
  105. echo ""
  106. echo "---------------------"
  107. echo "Setup.sh"
  108. echo "---------------------"
  109. echo -n "Looking for java.. ";
  110. # Location where ports on FreeBSD/PCBSD installs java6
  111. # check it first, because it isn't added to the path automatically
  112. JAVA="/usr/local/jdk1.6.0/jre/bin/java"
  113. if [ ! -e "${JAVA}" ]; then
  114. # Try alternative BSD Location
  115. JAVA="/usr/local/diablo-jdk1.6.0/jre/bin/java"
  116. if [ ! -e "${JAVA}" ]; then
  117. # Look in path
  118. if [ -e "${HOME}/.profile" -a "${USEPROFILE}" = "1" ]; then
  119. # Source the profile incase java can't be found otherwise
  120. # First, lets add a nice handler for the script exiting because of this crap.
  121. trap relaunch INT TERM EXIT
  122. . ${HOME}/.profile
  123. trap - INT TERM EXIT
  124. fi;
  125. JAVA=`which java`
  126. fi
  127. fi
  128. installjre() {
  129. result=1
  130. if [ ! -e "jre.bin" ]; then
  131. message="Would you like to download and install java?"
  132. if [ "install" = "${1}" ]; then
  133. message="Java was not detected on your machine. Would you like to download and install it now?"
  134. elif [ "upgrade" = "${1}" ]; then
  135. 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?"
  136. fi;
  137. /bin/sh getjre.sh "${message}"
  138. if [ $? -eq 0 ]; then
  139. /bin/sh installjre.sh
  140. result=$?
  141. fi;
  142. else
  143. message="Would you like to install java?"
  144. if [ "install" = "${1}" ]; then
  145. message="Java was not detected on your machine. Would you like to install it now?"
  146. elif [ "upgrade" = "${1}" ]; then
  147. message="The version of java detected on your machine is not compatible with DMDirc. Would you like to install a compatible version now?"
  148. fi;
  149. /bin/sh installjre.sh "${message}"
  150. result=$?
  151. fi;
  152. if [ ${result} -ne 0 ]; then
  153. if [ "upgrade" = "${1}" ]; then
  154. errordialog "DMDirc Setup" "Sorry, DMDirc setup can not continue without an updated version of java."
  155. else
  156. errordialog "DMDirc Setup" "Sorry, DMDirc setup can not continue without java."
  157. fi;
  158. exit 1;
  159. else
  160. if [ -e "${PWD}/java-bin" ]; then
  161. echo "Found JREBin: ${PWD}/java-bin"
  162. JAVA="${PWD}/java-bin"
  163. else
  164. JAVA=`which java`
  165. fi;
  166. fi;
  167. }
  168. if [ "" != "${JAVA}" ]; then
  169. echo "Success! ("${JAVA}")"
  170. else
  171. echo "Failed!"
  172. installjre "install"
  173. fi
  174. echo "Success!"
  175. if [ "${UID}" = "" ]; then
  176. UID=`id -u`;
  177. fi
  178. if [ "0" = "${UID}" ]; then
  179. echo "Running as root.."
  180. isRoot="--isroot";
  181. else
  182. echo "Running as user.."
  183. isRoot="";
  184. fi
  185. showHelp() {
  186. echo "This will setup DMDirc on a unix based system."
  187. echo "The following command line arguments are known:"
  188. echo "---------------------"
  189. echo "-h, --help Help information"
  190. echo "-r, --release [version] This is a release"
  191. echo "---------------------"
  192. exit 0;
  193. }
  194. if [ "${isRelease}" != "" ]; then
  195. isRelease=" --release "${isRelease}
  196. fi
  197. if [ -e "DMDirc.jar" ]; then
  198. echo "Checking for openJDK.."
  199. ISOPENJDK=`${JAVA} -version 2>&1 | grep -i openjdk`
  200. if [ "" != "${ISOPENJDK}" ]; then
  201. 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."
  202. message="${message}\n\nWould you like to continue anyway?"
  203. questiondialog "OpenJDK" "${message}" 0
  204. if [ $? -ne 0 ]; then
  205. echo "Aborting."
  206. exit 1;
  207. fi;
  208. fi;
  209. echo "Checking java version.."
  210. ${JAVA} -cp DMDirc.jar com.dmdirc.installer.Main --help >/dev/null
  211. if [ $? -ne 0 ]; then
  212. installjre "upgrade"
  213. echo "Trying to run installer.."
  214. ${JAVA} -cp DMDirc.jar com.dmdirc.installer.Main ${isRoot}${isRelease}
  215. if [ $? -ne 0 ]; then
  216. exit 1;
  217. fi;
  218. else
  219. echo "Running installer.."
  220. ${JAVA} -cp DMDirc.jar com.dmdirc.installer.Main ${isRoot}${isRelease}
  221. exit $?
  222. fi
  223. else
  224. echo "No installer found!"
  225. fi
  226. ## Script-Only install goes here.
  227. echo "Script-Only functionality not implemented."
  228. exit 1;