Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

installjre.sh 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. # Find out where we are
  43. BASEDIR=$(cd "${0%/*}" 2>/dev/null; echo $PWD)
  44. PIDOF=`which pidof`
  45. if [ "${PIDOF}" = "" ]; then
  46. # For some reason some distros hide pidof...
  47. if [ -e /sbin/pidof ]; then
  48. PIDOF=/sbin/pidof
  49. elif [ -e /usr/sbin/pidof ]; then
  50. PIDOF=/usr/sbin/pidof
  51. fi;
  52. fi;
  53. ISFREEBSD=`uname -s | grep -i FreeBSD`
  54. if [ -e "${BASEDIR}/functions.sh" ]; then
  55. . ${BASEDIR}/functions.sh
  56. else
  57. echo "Unable to find functions.sh, unable to continue."
  58. exit 1;
  59. fi;
  60. showLicence() {
  61. # Get Licence Text
  62. FILE=`mktemp licence.XXXXXXXXXXXXXX`
  63. if [ "${ISFREEBSD}" != "" ]; then
  64. WGET=`which wget`
  65. FETCH=`which fetch`
  66. CURL=`which curl`
  67. ARCH=`uname -m`
  68. RELEASE=`uname -r`
  69. URL="http://www.dmdirc.com/getjavalicense/`uname -s`/${ARCH}/${RELEASE}"
  70. if [ "${WGET}" != "" ]; then
  71. ${WGET} -q -O ${FILE} ${URL}
  72. elif [ "${FETCH}" != "" ]; then
  73. ${FETCH} -q -o ${FILE} ${URL}
  74. elif [ "${CURL}" != "" ]; then
  75. ${CURL} -s -o ${FILE} ${URL}
  76. fi;
  77. else
  78. # Location of licence start
  79. STARTLINE=`grep ${GREPOPTS} "^more <<\"EOF\"$" jre.bin`
  80. STARTLINE=$((${STARTLINE%%:*} + 1))
  81. # Location of licence end
  82. ENDLINE=`grep ${GREPOPTS} "Do you agree to the above license terms?" jre.bin`
  83. ENDLINE=$((${ENDLINE%%:*} - 4))
  84. if [ ${ENDLINE} -lt 4 ]; then
  85. errordialog "Installer Error" "DMDirc has been unable to figure out what to do with this jre download and can not continue. Please raise an issue about this at http://bugs.dmdirc.com"
  86. exit 1;
  87. fi;
  88. head -n ${ENDLINE} jre.bin | tail ${TAILOPTS}${STARTLINE} > ${FILE}
  89. fi;
  90. # Send text to console.
  91. echo ""
  92. echo "-----------------------------------------------------------------------"
  93. echo "Java Licence"
  94. echo "-----------------------------------------------------------------------"
  95. cat ${FILE}
  96. echo "-----------------------------------------------------------------------"
  97. # Now try to use the GUI Dialogs.
  98. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  99. echo "Dialog on Display: ${DISPLAY}"
  100. ${KDIALOG} --title "DMDirc: Java Licence" --textbox ${FILE} 600 400
  101. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  102. echo "Dialog on Display: ${DISPLAY}"
  103. ${ZENITY} --text-info --title "DMDirc: Java Licence" --filename=${FILE} --width=600 --height=400
  104. fi
  105. # Remove temp file
  106. rm -Rf ${FILE}
  107. }
  108. if [ "" != "${1}" ]; then
  109. questiondialog "Java Install" "${1}"
  110. result=$?
  111. if [ $result -ne 0 ]; then
  112. exit 1;
  113. fi;
  114. fi;
  115. messagedialog "Java Install" "Before java can be installed, please review the following licence."
  116. showLicence
  117. questiondialog "Java Install" "Do you agree to the Java Licence?"
  118. if [ $? -eq 0 ]; then
  119. if [ "${ISFREEBSD}" != "" ]; then
  120. JREJAVAHOME="diablo-jre1.6.0_07"
  121. else
  122. # Look to see where the JRE wants to install to
  123. JREJAVAHOME=`grep ${GREPOPTS} "^javahome=" jre.bin`
  124. JREJAVAHOME=${JREJAVAHOME##*=}
  125. fi;
  126. echo "JREJAVAHOME: ${JREJAVAHOME}"
  127. if [ "${UID}" = "" ]; then
  128. UID=`id -u`;
  129. fi
  130. if [ "0" = "${UID}" ]; then
  131. mkdir -p /usr/lib/jvm/
  132. installdir=/usr/lib/jvm/${JREJAVAHOME}
  133. else
  134. installdir=${HOME}/${JREJAVAHOME}
  135. fi;
  136. echo "installdir: ${installdir}"
  137. if [ ! -e ${installdir} ]; then
  138. 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."
  139. if [ "${ISFREEBSD}" != "" ]; then
  140. mv jre.bin jre.tar.bz2
  141. tar -jxvf jre.tar.bz2
  142. mv jre.tar.bz2 jre.bin
  143. else
  144. # Hack jre.bin to allow us to install without asking for a licence, or failing
  145. # the checksum.
  146. # Location of licence start
  147. STARTLINE=`grep ${GREPOPTS} "^more <<\"EOF\"$" jre.bin`
  148. STARTLINE=${STARTLINE%%:*}
  149. # Location of licence end
  150. ENDLINE=`grep ${GREPOPTS} "Do you agree to the above license terms?" jre.bin`
  151. ENDLINE=$((${ENDLINE%%:*} - 2))
  152. if [ ${ENDLINE} -lt 2 ]; then
  153. errordialog "Installer Error" "DMDirc has been unable to figure out what to do with this jre download and can not continue. Please raise an issue about this at http://bugs.dmdirc.com"
  154. exit 1;
  155. fi;
  156. # Location of checksum start
  157. CSSTARTLINE=`grep ${GREPOPTS} "^if \[ -x /usr/bin/sum \]; then$" jre.bin`
  158. CSSTARTLINE=${CSSTARTLINE%%:*}
  159. # Location of checksum end
  160. CSENDLINE=`grep ${GREPOPTS} "Can't find /usr/bin/sum to do checksum" jre.bin`
  161. CSENDLINE=$((${CSENDLINE%%:*} + 2))
  162. # Location of script end
  163. SCENDLINE=`grep ${GREPOPTS} "^echo \"Done.\"$" jre.bin`
  164. SCENDLINE=$((${SCENDLINE%%:*} + 2 - (${ENDLINE} - ${STARTLINE}) - (${CSENDLINE} - ${CSSTARTLINE})))
  165. # Remove the licence and checksum stuff!
  166. head -n $((${STARTLINE} -1)) jre.bin > jre.bin.tmp
  167. tail ${TAILOPTS}$((${ENDLINE})) jre.bin | head -n $((${CSSTARTLINE} -1 - ${ENDLINE})) >> jre.bin.tmp
  168. echo "tail \${tail_args} +${SCENDLINE} \"\$0\" > \$outname" >> jre.bin.tmp
  169. tail ${TAILOPTS}$((${CSENDLINE})) jre.bin >> jre.bin.tmp
  170. PIPE=`mktemp installprogresspipe.XXXXXXXXXXXXXX`
  171. /bin/sh ${PWD}/progressbar.sh --pulsate "Installing JRE. Please wait.." 100 ${PIPE} &
  172. sleep 1;
  173. echo "-1" > ${PIPE}
  174. # This is supposed to write to the pipe as it does stuff, but it appears
  175. # not to work properly.
  176. yes | sh jre.bin.tmp | egrep --line-buffered -i "(extracting|inflating):" > ${PIPE};
  177. echo "quit" > ${PIPE}
  178. # rm -Rf jre.bin.tmp
  179. fi;
  180. mv ${JREJAVAHOME} ${installdir}
  181. if [ "0" = "${UID}" ]; then
  182. # Add to global path.
  183. if [ -e "/usr/bin/java" ]; then
  184. rm -Rf /usr/bin/java
  185. fi;
  186. ln -s /usr/lib/jvm/${JREJAVAHOME}/bin/java /usr/bin/java
  187. # This allows the main installer to continue with the new java version,
  188. # incase the shell doesn't find the new binary.
  189. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  190. ln -s ${installdir}/bin/java ${PWD}/java-bin
  191. else
  192. # Add to path.
  193. echo "" >> ${HOME}/.profile
  194. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.profile
  195. echo "if [ -d ~/${JREJAVAHOME}/bin ] ; then" >> ${HOME}/.profile
  196. echo " PATH=~/${JREJAVAHOME}/bin:\${PATH}" >> ${HOME}/.profile
  197. echo "fi" >> ${HOME}/.profile
  198. if [ -e ${HOME}/.cshrc ]; then
  199. echo "" >> ${HOME}/.cshrc
  200. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.cshrc
  201. echo "if( -d ~/${JREJAVAHOME}/bin ) then" >> ${HOME}/.cshrc
  202. echo " set path = (~/${JREJAVAHOME}/bin \$path)" >> ${HOME}/.cshrc
  203. echo "endfi" >> ${HOME}/.cshrc
  204. fi
  205. # This allows the main installer to continue with the new java version.
  206. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  207. ln -s ${installdir}/bin/java ${PWD}/java-bin
  208. # This allows dmdirc launcher to find the jre if the path is not set.
  209. ln -sf ${installdir} ${HOME}/jre
  210. fi;
  211. messagedialog "Java Install" "Java installation complete"
  212. exit 0;
  213. else
  214. 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."
  215. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  216. ln -s ${installdir}/bin/java ${PWD}/java-bin
  217. exit 0;
  218. fi;
  219. else
  220. errordialog "Java Install" "You must agree to the licence before java can be installed"
  221. fi;
  222. exit 1;