Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

installjre.sh 8.1KB

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