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.

installjre.sh 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/sh
  2. #
  3. # Install the JRE.
  4. #
  5. # Find out what params we should pass to things.
  6. # Solaris has a nice and ancient version of grep in /usr/bin
  7. grep -na "" /dev/null >/dev/null 2>&1
  8. if [ $? -eq 2 ]; then
  9. GREPOPTS="-n"
  10. else
  11. GREPOPTS="-na"
  12. fi;
  13. # Solaris also has a crappy version of tail!
  14. tail -n +1 /dev/null >/dev/null 2>&1
  15. if [ $? -eq 2 ]; then
  16. TAILOPTS="+"
  17. else
  18. TAILOPTS="-n +"
  19. fi;
  20. # Check the which command exists, and if so make sure it behaves how we want
  21. # it to...
  22. WHICH=`which which 2>/dev/null`
  23. if [ "" = "${WHICH}" ]; then
  24. echo "which command not found. Aborting.";
  25. exit 0;
  26. else
  27. # Solaris sucks
  28. BADWHICH=`which /`
  29. if [ "${BADWHICH}" != "" ]; then
  30. echo "Replacing bad which command.";
  31. # "Which" on solaris gives non-empty results for commands that don't exist
  32. which() {
  33. OUT=`${WHICH} ${1}`
  34. if [ $? -eq 0 ]; then
  35. echo ${OUT}
  36. else
  37. echo ""
  38. fi;
  39. }
  40. fi;
  41. fi
  42. PIDOF=`which pidof`
  43. if [ "${PIDOF}" = "" ]; then
  44. # For some reason some distros hide pidof...
  45. if [ -e /sbin/pidof ]; then
  46. PIDOF=/sbin/pidof
  47. elif [ -e /usr/sbin/pidof ]; then
  48. PIDOF=/usr/sbin/pidof
  49. fi;
  50. fi;
  51. ISFREEBSD=`uname -s | grep -i FreeBSD`
  52. if [ -e "functions.sh" ]; then
  53. . `dirname $0`/functions.sh
  54. else
  55. echo "Unable to find functions.sh, unable to continue."
  56. exit 1;
  57. fi;
  58. showLicense() {
  59. # Get License Text
  60. FILE=`mktemp license.XXXXXXXXXXXXXX`
  61. if [ "${ISFREEBSD}" != "" ]; then
  62. WGET=`which wget`
  63. FETCH=`which fetch`
  64. CURL=`which curl`
  65. ARCH=`uname -m`
  66. RELEASE=`uname -r`
  67. URL="http://www.dmdirc.com/getjavalicense/`uname -s`/${ARCH}/${RELEASE}"
  68. if [ "${WGET}" != "" ]; then
  69. ${WGET} -q -O ${FILE} ${URL}
  70. elif [ "${FETCH}" != "" ]; then
  71. ${FETCH} -q -o ${FILE} ${URL}
  72. elif [ "${CURL}" != "" ]; then
  73. ${CURL} -s -o ${FILE} ${URL}
  74. fi;
  75. else
  76. # Location of license start
  77. STARTLINE=`grep ${GREPOPTS} "^more <<\"EOF\"$" jre.bin`
  78. STARTLINE=$((${STARTLINE%%:*} + 1))
  79. # Location of license end
  80. ENDLINE=`grep ${GREPOPTS} "Do you agree to the above license terms?" jre.bin`
  81. ENDLINE=$((${ENDLINE%%:*} - 2))
  82. head -n ${ENDLINE} jre.bin | tail ${TAILOPTS}${STARTLINE} > ${FILE}
  83. fi;
  84. # Send text to console.
  85. echo ""
  86. echo "-----------------------------------------------------------------------"
  87. echo "Java License"
  88. echo "-----------------------------------------------------------------------"
  89. cat ${FILE}
  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 "DMDirc: Java License" --textbox ${FILE} 600 400
  95. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  96. echo "Dialog on Display: ${DISPLAY}"
  97. ${ZENITY} --text-info --title "DMDirc: Java License" --filename=${FILE} --width=600 --height=400
  98. fi
  99. # Remove temp file
  100. rm -Rf ${FILE}
  101. }
  102. if [ "" != "${1}" ]; then
  103. questiondialog "Java Install" "${1}"
  104. result=$?
  105. if [ $result -ne 0 ]; then
  106. exit 1;
  107. fi;
  108. fi;
  109. messagedialog "Java Install" "Before java can be installed, please review the following license."
  110. showLicense
  111. questiondialog "Java Install" "Do you agree to the Java License?"
  112. if [ $? -eq 0 ]; then
  113. if [ "${ISFREEBSD}" != "" ]; then
  114. JREJAVAHOME="diablo-jre1.6.0_07"
  115. else
  116. # Look to see where the JRE wants to install to
  117. JREJAVAHOME=`grep ${GREPOPTS} "^javahome=" jre.bin`
  118. JREJAVAHOME=${JREJAVAHOME##*=}
  119. fi;
  120. echo "JREJAVAHOME: ${JREJAVAHOME}"
  121. if [ "${UID}" = "" ]; then
  122. UID=`id -u`;
  123. fi
  124. if [ "0" = "${UID}" ]; then
  125. mkdir -p /usr/lib/jvm/
  126. installdir=/usr/lib/jvm/${JREJAVAHOME}
  127. else
  128. installdir=${HOME}/${JREJAVAHOME}
  129. fi;
  130. echo "installdir: ${installdir}"
  131. if [ ! -e ${installdir} ]; then
  132. messagedialog "Java Install" "Java install will begin when you press OK.\nThis may take some time, so please wait.\n\nYou will be informed when the installation is completed."
  133. if [ "${ISFREEBSD}" != "" ]; then
  134. mv jre.bin jre.tar.bz2
  135. tar -jxvf jre.tar.bz2
  136. mv jre.tar.bz2 jre.bin
  137. else
  138. # Hack jre.bin to allow us to install without asking for a license, or failing
  139. # the checksum.
  140. # Location of license start
  141. STARTLINE=`grep ${GREPOPTS} "^more <<\"EOF\"$" jre.bin`
  142. STARTLINE=${STARTLINE%%:*}
  143. # Location of license end
  144. ENDLINE=`grep ${GREPOPTS} "If you don't agree to the license you can't install this software" jre.bin`
  145. ENDLINE=$((${ENDLINE%%:*} + 3))
  146. # Location of checksum start
  147. CSSTARTLINE=`grep ${GREPOPTS} "^if \[ -x /usr/bin/sum \]; then$" jre.bin`
  148. CSSTARTLINE=${CSSTARTLINE%%:*}
  149. # Location of checksum end
  150. CSENDLINE=`grep ${GREPOPTS} "Can't find /usr/bin/sum to do checksum" jre.bin`
  151. CSENDLINE=$((${CSENDLINE%%:*} + 2))
  152. # Location of script end
  153. SCENDLINE=`grep ${GREPOPTS} "^echo \"Done.\"$" jre.bin`
  154. SCENDLINE=$((${SCENDLINE%%:*} + 2 - (${ENDLINE} - ${STARTLINE}) - (${CSENDLINE} - ${CSSTARTLINE})))
  155. # Remove the license and checksum stuff!
  156. head -n $((${STARTLINE} -1)) jre.bin > jre.bin.tmp
  157. tail ${TAILOPTS}$((${ENDLINE})) jre.bin | head -n $((${CSSTARTLINE} -1 - ${ENDLINE})) >> jre.bin.tmp
  158. echo "tail \${tail_args} +${SCENDLINE} \"\$0\" > \$outname" >> jre.bin.tmp
  159. tail ${TAILOPTS}$((${CSENDLINE})) jre.bin >> jre.bin.tmp
  160. yes | sh jre.bin.tmp
  161. rm -Rf jre.bin.tmp
  162. fi;
  163. mv ${JREJAVAHOME} ${installdir}
  164. if [ "0" = "${UID}" ]; then
  165. # Add to global path.
  166. if [ -e "/usr/bin/java" ]; then
  167. rm -Rf /usr/bin/java
  168. fi;
  169. ln -s /usr/lib/jvm/${JREJAVAHOME}/bin/java /usr/bin/java
  170. # This allows the main installer to continue with the new java version,
  171. # incase the shell doesn't find the new binary.
  172. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  173. ln -s ${installdir}/bin/java ${PWD}/java-bin
  174. else
  175. # Add to path.
  176. echo "" >> ${HOME}/.profile
  177. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.profile
  178. echo "if [ -d ~/${JREJAVAHOME}/bin ] ; then" >> ${HOME}/.profile
  179. echo " PATH=~/${JREJAVAHOME}/bin:\${PATH}" >> ${HOME}/.profile
  180. echo "fi" >> ${HOME}/.profile
  181. if [ -e ${HOME}/.cshrc ]; then
  182. echo "" >> ${HOME}/.cshrc
  183. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.cshrc
  184. echo "if( -d ~/${JREJAVAHOME}/bin ) then" >> ${HOME}/.cshrc
  185. echo " set path = (~/${JREJAVAHOME}/bin \$path)" >> ${HOME}/.cshrc
  186. echo "endfi" >> ${HOME}/.cshrc
  187. fi
  188. # This allows the main installer to continue with the new java version.
  189. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  190. ln -s ${installdir}/bin/java ${PWD}/java-bin
  191. # This allows dmdirc launcher to find the jre if the path is not set.
  192. ln -sf ${installdir} ${HOME}/jre
  193. fi;
  194. messagedialog "Java Install" "Java installation complete"
  195. exit 0;
  196. else
  197. messagedialog "Java Install" "An existing install was found at ${installdir}, but this directory is not in the current path, DMDirc setup will try to use this version of java for the install."
  198. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  199. ln -s ${installdir}/bin/java ${PWD}/java-bin
  200. exit 0;
  201. fi;
  202. else
  203. errordialog "Java Install" "You must agree to the license before java can be installed"
  204. fi;
  205. exit 1;