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

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