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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #!/bin/sh
  2. #
  3. # Install the JRE.
  4. #
  5. PIDOF=`which pidof`
  6. if [ "${PIDOF}" = "" ]; then
  7. # For some reason some distros hide pidof...
  8. if [ -e /sbin/pidof ]; then
  9. PIDOF=/sbin/pidof
  10. elif [ -e /usr/sbin/pidof ]; then
  11. PIDOF=/usr/sbin/pidof
  12. fi;
  13. fi;
  14. ## Helper Functions
  15. if [ "${PIDOF}" = "" ]; then
  16. ISKDE=`${PIDOF} -x -s kdeinit`
  17. ISGNOME=`${PIDOF} -x -s gnome-panel`
  18. else
  19. ISKDE=`ps ux | grep kdeinit | grep -v grep`
  20. ISGNOME=`ps ux | grep gnome-panel | grep -v grep`
  21. fi;
  22. KDIALOG=`which kdialog`
  23. ZENITY=`which zenity`
  24. errordialog() {
  25. # Send message to console.
  26. echo ""
  27. echo "-----------------------------------------------------------------------"
  28. echo "Error: ${1}"
  29. echo "-----------------------------------------------------------------------"
  30. echo "${2}"
  31. echo "-----------------------------------------------------------------------"
  32. # Now try to use the GUI Dialogs.
  33. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  34. echo "Dialog on Display: ${DISPLAY}"
  35. ${KDIALOG} --title "DMDirc: ${1}" --error "${2}"
  36. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  37. echo "Dialog on Display: ${DISPLAY}"
  38. ${ZENITY} --error --title "DMDirc: ${1}" --text "${2}"
  39. fi
  40. }
  41. messagedialog() {
  42. # Send message to console.
  43. echo ""
  44. echo "-----------------------------------------------------------------------"
  45. echo "Info: ${1}"
  46. echo "-----------------------------------------------------------------------"
  47. echo "${2}"
  48. echo "-----------------------------------------------------------------------"
  49. # Now try to use the GUI Dialogs.
  50. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  51. echo "Dialog on Display: ${DISPLAY}"
  52. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${2}"
  53. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  54. echo "Dialog on Display: ${DISPLAY}"
  55. ${ZENITY} --info --title "DMDirc: ${1}" --text "${2}"
  56. fi
  57. }
  58. questiondialog() {
  59. # Send question to console.
  60. echo ""
  61. echo "-----------------------------------------------------------------------"
  62. echo "Question: ${1}"
  63. echo "-----------------------------------------------------------------------"
  64. echo "${2}"
  65. echo "-----------------------------------------------------------------------"
  66. # Now try to use the GUI Dialogs.
  67. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  68. echo "Dialog on Display: ${DISPLAY}"
  69. ${KDIALOG} --title "DMDirc: ${1}" --yesno "${2}"
  70. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  71. echo "Dialog on Display: ${DISPLAY}"
  72. ${ZENITY} --question --title "DMDirc: ${1}" --text "${2}"
  73. else
  74. echo "Unable to ask question, assuming no."
  75. return 1;
  76. fi
  77. }
  78. showLicense() {
  79. # Get License Text
  80. FILE=`mktemp -p ${PWD} license.XXXXXXXXXXXXXX`
  81. # Location of license start
  82. STARTLINE=`grep -na "^more <<\"EOF\"$" jre.bin`
  83. STARTLINE=$((${STARTLINE%%:*} + 1))
  84. # Location of license end
  85. ENDLINE=`grep -na "Do you agree to the above license terms?" jre.bin`
  86. ENDLINE=$((${ENDLINE%%:*} - 2))
  87. head -n ${ENDLINE} jre.bin | tail -n +${STARTLINE} > ${FILE}
  88. # Send text to console.
  89. echo ""
  90. echo "-----------------------------------------------------------------------"
  91. echo "Java License"
  92. echo "-----------------------------------------------------------------------"
  93. cat ${FILE}
  94. echo "-----------------------------------------------------------------------"
  95. # Now try to use the GUI Dialogs.
  96. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  97. echo "Dialog on Display: ${DISPLAY}"
  98. ${KDIALOG} --title "DMDirc: Java License" --textbox ${FILE} 600 400
  99. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  100. echo "Dialog on Display: ${DISPLAY}"
  101. ${ZENITY} --text-info --title "DMDirc: Java License" --filename=${FILE} --width=600 --height=400
  102. fi
  103. # Remove temp file
  104. rm -Rf ${FILE}
  105. }
  106. if [ "" != "${1}" ]; then
  107. questiondialog "Java Install" "${1}"
  108. result=$?
  109. if [ $result -ne 0 ]; then
  110. exit 1;
  111. fi;
  112. fi;
  113. messagedialog "Java Install" "Before java can be installed, please review the following license."
  114. showLicense
  115. questiondialog "Java Install" "Do you agree to the Java License?"
  116. if [ $? -eq 0 ]; then
  117. # Look to see where the JRE wants to install to
  118. JREJAVAHOME=`grep -na "^javahome=" jre.bin`
  119. JREJAVAHOME=${JREJAVAHOME##*=}
  120. if [ "${UID}" = "" ]; then
  121. UID=`id -u`;
  122. fi
  123. if [ "0" = "${UID}" ]; then
  124. installdir=/usr/lib/jvm/${JREJAVAHOME}
  125. else
  126. installdir=${HOME}/${JREJAVAHOME}
  127. fi;
  128. if [ -e ${installdir} ]; then
  129. # Hack jre.bin to allow us to install without asking for a license, or failing
  130. # the checksum.
  131. # Location of license start
  132. STARTLINE=`grep -na "^more <<\"EOF\"$" jre.bin`
  133. STARTLINE=${STARTLINE%%:*}
  134. # Location of license end
  135. ENDLINE=`grep -na "If you don't agree to the license you can't install this software" jre.bin`
  136. ENDLINE=$((${ENDLINE%%:*} + 3))
  137. # Location of checksum start
  138. CSSTARTLINE=`grep -na "^if \[ -x /usr/bin/sum \]; then$" jre.bin`
  139. CSSTARTLINE=${CSSTARTLINE%%:*}
  140. # Location of checksum end
  141. CSENDLINE=`grep -na "Can't find /usr/bin/sum to do checksum" jre.bin`
  142. CSENDLINE=$((${CSENDLINE%%:*} + 2))
  143. # Location of script end
  144. SCENDLINE=`grep -na "^echo \"Done.\"$" jre.bin`
  145. SCENDLINE=$((${SCENDLINE%%:*} + 2 - (${ENDLINE} - ${STARTLINE}) - (${CSENDLINE} - ${CSSTARTLINE})))
  146. # Remove the license and checksum stuff!
  147. head -n $((${STARTLINE} -1)) jre.bin > jre.bin.tmp
  148. tail -n +$((${ENDLINE})) jre.bin | head -n $((${CSSTARTLINE} -1 - ${ENDLINE})) >> jre.bin.tmp
  149. echo "tail \${tail_args} +${SCENDLINE} \"\$0\" > \$outname" >> jre.bin.tmp
  150. tail -n +$((${CSENDLINE})) jre.bin >> jre.bin.tmp
  151. 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."
  152. yes | sh jre.bin.tmp
  153. rm -Rf jre.bin.tmp
  154. mv ${JREJAVAHOME} ${installdir}
  155. if [ "0" = "${UID}" ]; then
  156. mkdir -p /usr/lib/jvm/
  157. # Add to global path.
  158. if [ -e "/usr/bin/java" ]; then
  159. rm -Rf /usr/bin/java
  160. fi;
  161. ln -s /usr/lib/jvm/${JREJAVAHOME}/bin/java /usr/bin/java
  162. else
  163. # Add to path.
  164. if [ -e ${HOME}/.profile ]; then
  165. echo "" >> ${HOME}/.profile
  166. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.profile
  167. echo "if [ -d ~/${JREJAVAHOME}/bin ] ; then" >> ${HOME}/.profile
  168. echo " PATH=~/${JREJAVAHOME}/bin:\"\${PATH}\"" >> ${HOME}/.profile
  169. echo "fi" >> ${HOME}/.profile
  170. fi
  171. if [ -e ${HOME}/.cshrc ]; then
  172. echo "" >> ${HOME}/.cshrc
  173. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.cshrc
  174. echo "if( -d ~/${JREJAVAHOME}/bin ) then" >> ${HOME}/.cshrc
  175. echo " set path = (~/${JREJAVAHOME}/bin \$path)" >> ${HOME}/.cshrc
  176. echo "endfi" >> ${HOME}/.cshrc
  177. fi
  178. # This allows the main installer to continue with the new java version.
  179. echo "export PATH=~/${JREJAVAHOME}/bin:\"\${PATH}\"" > .jrepath
  180. # This allows dmdirc launcher to find the jre if the path is not set.
  181. ln -sf ${installdir} ${HOME}/jre
  182. fi;
  183. messagedialog "Java Install" "Java installation complete"
  184. exit 0;
  185. else
  186. messagedialog "Java Install" "An existing install was found at ${installdir}, but this directory is not in the current path."
  187. echo "export PATH=~/${JREJAVAHOME}/bin:\"\${PATH}\"" > .jrepath
  188. exit 0;
  189. fi;
  190. else
  191. errordialog "Java Install" "You must agree to the license before java can be installed"
  192. fi;
  193. exit 1;