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

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