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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. showLicence() {
  59. # Get Licence Text
  60. FILE=`mktemp licence.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 licence start
  77. STARTLINE=`grep ${GREPOPTS} "^more <<\"EOF\"$" jre.bin`
  78. STARTLINE=$((${STARTLINE%%:*} + 1))
  79. # Location of licence end
  80. ENDLINE=`grep ${GREPOPTS} "Do you agree to the above licence terms?" jre.bin`
  81. ENDLINE=$((${ENDLINE%%:*} - 4))
  82. head -n ${ENDLINE} jre.bin | tail ${TAILOPTS}${STARTLINE} > ${FILE}
  83. fi;
  84. # Send text to console.
  85. echo ""
  86. echo "-----------------------------------------------------------------------"
  87. echo "Java Licence"
  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 Licence" --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 Licence" --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 licence."
  110. showLicence
  111. questiondialog "Java Install" "Do you agree to the Java Licence?"
  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 licence, or failing
  139. # the checksum.
  140. # Location of licence start
  141. STARTLINE=`grep ${GREPOPTS} "^more <<\"EOF\"$" jre.bin`
  142. STARTLINE=${STARTLINE%%:*}
  143. # Location of licence end
  144. ENDLINE=`grep ${GREPOPTS} "Do you agree to the above licence terms?" jre.bin`
  145. ENDLINE=$((${ENDLINE%%:*} - 2))
  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 licence 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. PIPE=`mktemp installprogresspipe.XXXXXXXXXXXXXX`
  161. /bin/sh ${PWD}/progressbar.sh --pulsate "Installing JRE. Please wait.." 100 ${PIPE} &
  162. sleep 1;
  163. echo "-1" > ${PIPE}
  164. # This is supposed to write to the pipe as it does stuff, but it appears
  165. # not to work properly.
  166. yes | sh jre.bin.tmp | egrep --line-buffered -i "(extracting|inflating):" > ${PIPE};
  167. echo "quit" > ${PIPE}
  168. # rm -Rf jre.bin.tmp
  169. fi;
  170. mv ${JREJAVAHOME} ${installdir}
  171. if [ "0" = "${UID}" ]; then
  172. # Add to global path.
  173. if [ -e "/usr/bin/java" ]; then
  174. rm -Rf /usr/bin/java
  175. fi;
  176. ln -s /usr/lib/jvm/${JREJAVAHOME}/bin/java /usr/bin/java
  177. # This allows the main installer to continue with the new java version,
  178. # incase the shell doesn't find the new binary.
  179. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  180. ln -s ${installdir}/bin/java ${PWD}/java-bin
  181. else
  182. # Add to path.
  183. echo "" >> ${HOME}/.profile
  184. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.profile
  185. echo "if [ -d ~/${JREJAVAHOME}/bin ] ; then" >> ${HOME}/.profile
  186. echo " PATH=~/${JREJAVAHOME}/bin:\${PATH}" >> ${HOME}/.profile
  187. echo "fi" >> ${HOME}/.profile
  188. if [ -e ${HOME}/.cshrc ]; then
  189. echo "" >> ${HOME}/.cshrc
  190. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.cshrc
  191. echo "if( -d ~/${JREJAVAHOME}/bin ) then" >> ${HOME}/.cshrc
  192. echo " set path = (~/${JREJAVAHOME}/bin \$path)" >> ${HOME}/.cshrc
  193. echo "endfi" >> ${HOME}/.cshrc
  194. fi
  195. # This allows the main installer to continue with the new java version.
  196. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  197. ln -s ${installdir}/bin/java ${PWD}/java-bin
  198. # This allows dmdirc launcher to find the jre if the path is not set.
  199. ln -sf ${installdir} ${HOME}/jre
  200. fi;
  201. messagedialog "Java Install" "Java installation complete"
  202. exit 0;
  203. else
  204. 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."
  205. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  206. ln -s ${installdir}/bin/java ${PWD}/java-bin
  207. exit 0;
  208. fi;
  209. else
  210. errordialog "Java Install" "You must agree to the licence before java can be installed"
  211. fi;
  212. exit 1;