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 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. ## Helper Functions
  52. if [ "${PIDOF}" != "" ]; then
  53. ISKDE=`${PIDOF} -x -s kdeinit`
  54. ISGNOME=`${PIDOF} -x -s gnome-panel`
  55. else
  56. ISKDE=`ps -Af | grep kdeinit | grep -v grep`
  57. ISGNOME=`ps -Af | grep gnome-panel | grep -v grep`
  58. fi;
  59. KDIALOG=`which kdialog`
  60. ZENITY=`which zenity`
  61. errordialog() {
  62. # Send message to console.
  63. echo ""
  64. echo "-----------------------------------------------------------------------"
  65. echo "Error: ${1}"
  66. echo "-----------------------------------------------------------------------"
  67. echo "${2}"
  68. echo "-----------------------------------------------------------------------"
  69. # Now try to use the GUI Dialogs.
  70. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  71. echo "Dialog on Display: ${DISPLAY}"
  72. ${KDIALOG} --title "DMDirc: ${1}" --error "${2}"
  73. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  74. echo "Dialog on Display: ${DISPLAY}"
  75. ${ZENITY} --error --title "DMDirc: ${1}" --text "${2}"
  76. fi
  77. }
  78. messagedialog() {
  79. # Send message to console.
  80. echo ""
  81. echo "-----------------------------------------------------------------------"
  82. echo "Info: ${1}"
  83. echo "-----------------------------------------------------------------------"
  84. echo "${2}"
  85. echo "-----------------------------------------------------------------------"
  86. # Now try to use the GUI Dialogs.
  87. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  88. echo "Dialog on Display: ${DISPLAY}"
  89. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${2}"
  90. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  91. echo "Dialog on Display: ${DISPLAY}"
  92. ${ZENITY} --info --title "DMDirc: ${1}" --text "${2}"
  93. fi
  94. }
  95. questiondialog() {
  96. # Send question to console.
  97. echo ""
  98. echo "-----------------------------------------------------------------------"
  99. echo "Question: ${1}"
  100. echo "-----------------------------------------------------------------------"
  101. echo "${2}"
  102. echo "-----------------------------------------------------------------------"
  103. # Now try to use the GUI Dialogs.
  104. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  105. echo "Dialog on Display: ${DISPLAY}"
  106. ${KDIALOG} --title "DMDirc: ${1}" --yesno "${2}"
  107. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  108. echo "Dialog on Display: ${DISPLAY}"
  109. ${ZENITY} --question --title "DMDirc: ${1}" --text "${2}"
  110. else
  111. echo "Unable to ask question, assuming no."
  112. return 1;
  113. fi
  114. }
  115. showLicense() {
  116. # Get License Text
  117. FILE=`mktemp -p ${PWD} license.XXXXXXXXXXXXXX`
  118. # Location of license start
  119. STARTLINE=`grep ${GREPOPTS} "^more <<\"EOF\"$" jre.bin`
  120. STARTLINE=$((${STARTLINE%%:*} + 1))
  121. # Location of license end
  122. ENDLINE=`grep ${GREPOPTS} "Do you agree to the above license terms?" jre.bin`
  123. ENDLINE=$((${ENDLINE%%:*} - 2))
  124. head -n ${ENDLINE} jre.bin | tail ${TAILOPTS}${STARTLINE} > ${FILE}
  125. # Send text to console.
  126. echo ""
  127. echo "-----------------------------------------------------------------------"
  128. echo "Java License"
  129. echo "-----------------------------------------------------------------------"
  130. cat ${FILE}
  131. echo "-----------------------------------------------------------------------"
  132. # Now try to use the GUI Dialogs.
  133. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  134. echo "Dialog on Display: ${DISPLAY}"
  135. ${KDIALOG} --title "DMDirc: Java License" --textbox ${FILE} 600 400
  136. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  137. echo "Dialog on Display: ${DISPLAY}"
  138. ${ZENITY} --text-info --title "DMDirc: Java License" --filename=${FILE} --width=600 --height=400
  139. fi
  140. # Remove temp file
  141. rm -Rf ${FILE}
  142. }
  143. if [ "" != "${1}" ]; then
  144. questiondialog "Java Install" "${1}"
  145. result=$?
  146. if [ $result -ne 0 ]; then
  147. exit 1;
  148. fi;
  149. fi;
  150. messagedialog "Java Install" "Before java can be installed, please review the following license."
  151. showLicense
  152. questiondialog "Java Install" "Do you agree to the Java License?"
  153. if [ $? -eq 0 ]; then
  154. # Look to see where the JRE wants to install to
  155. JREJAVAHOME=`grep ${GREPOPTS} "^javahome=" jre.bin`
  156. JREJAVAHOME=${JREJAVAHOME##*=}
  157. echo "JREJAVAHOME: ${JREJAVAHOME}"
  158. if [ "${UID}" = "" ]; then
  159. UID=`id -u`;
  160. fi
  161. if [ "0" = "${UID}" ]; then
  162. mkdir -p /usr/lib/jvm/
  163. installdir=/usr/lib/jvm/${JREJAVAHOME}
  164. else
  165. installdir=${HOME}/${JREJAVAHOME}
  166. fi;
  167. echo "installdir: ${installdir}"
  168. if [ ! -e ${installdir} ]; then
  169. # Hack jre.bin to allow us to install without asking for a license, or failing
  170. # the checksum.
  171. # Location of license start
  172. STARTLINE=`grep ${GREPOPTS} "^more <<\"EOF\"$" jre.bin`
  173. STARTLINE=${STARTLINE%%:*}
  174. # Location of license end
  175. ENDLINE=`grep ${GREPOPTS} "If you don't agree to the license you can't install this software" jre.bin`
  176. ENDLINE=$((${ENDLINE%%:*} + 3))
  177. # Location of checksum start
  178. CSSTARTLINE=`grep ${GREPOPTS} "^if \[ -x /usr/bin/sum \]; then$" jre.bin`
  179. CSSTARTLINE=${CSSTARTLINE%%:*}
  180. # Location of checksum end
  181. CSENDLINE=`grep ${GREPOPTS} "Can't find /usr/bin/sum to do checksum" jre.bin`
  182. CSENDLINE=$((${CSENDLINE%%:*} + 2))
  183. # Location of script end
  184. SCENDLINE=`grep ${GREPOPTS} "^echo \"Done.\"$" jre.bin`
  185. SCENDLINE=$((${SCENDLINE%%:*} + 2 - (${ENDLINE} - ${STARTLINE}) - (${CSENDLINE} - ${CSSTARTLINE})))
  186. # Remove the license and checksum stuff!
  187. head -n $((${STARTLINE} -1)) jre.bin > jre.bin.tmp
  188. tail ${TAILOPTS}$((${ENDLINE})) jre.bin | head -n $((${CSSTARTLINE} -1 - ${ENDLINE})) >> jre.bin.tmp
  189. echo "tail \${tail_args} +${SCENDLINE} \"\$0\" > \$outname" >> jre.bin.tmp
  190. tail ${TAILOPTS}$((${CSENDLINE})) jre.bin >> jre.bin.tmp
  191. 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."
  192. yes | sh jre.bin.tmp
  193. rm -Rf jre.bin.tmp
  194. mv ${JREJAVAHOME} ${installdir}
  195. if [ "0" = "${UID}" ]; then
  196. # Add to global path.
  197. if [ -e "/usr/bin/java" ]; then
  198. rm -Rf /usr/bin/java
  199. fi;
  200. ln -s /usr/lib/jvm/${JREJAVAHOME}/bin/java /usr/bin/java
  201. # This allows the main installer to continue with the new java version,
  202. # incase the shell doesn't find the new binary.
  203. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  204. ln -s ${installdir}/bin/java ${PWD}/java-bin
  205. else
  206. # Add to path.
  207. if [ -e ${HOME}/.profile ]; then
  208. echo "" >> ${HOME}/.profile
  209. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.profile
  210. echo "if [ -d ~/${JREJAVAHOME}/bin ] ; then" >> ${HOME}/.profile
  211. echo " PATH=~/${JREJAVAHOME}/bin:\${PATH}" >> ${HOME}/.profile
  212. echo "fi" >> ${HOME}/.profile
  213. fi
  214. if [ -e ${HOME}/.cshrc ]; then
  215. echo "" >> ${HOME}/.cshrc
  216. echo "# set PATH so it includes user's private java if it exists" >> ${HOME}/.cshrc
  217. echo "if( -d ~/${JREJAVAHOME}/bin ) then" >> ${HOME}/.cshrc
  218. echo " set path = (~/${JREJAVAHOME}/bin \$path)" >> ${HOME}/.cshrc
  219. echo "endfi" >> ${HOME}/.cshrc
  220. fi
  221. # This allows the main installer to continue with the new java version.
  222. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  223. ln -s ${installdir}/bin/java ${PWD}/java-bin
  224. # This allows dmdirc launcher to find the jre if the path is not set.
  225. ln -sf ${installdir} ${HOME}/jre
  226. fi;
  227. messagedialog "Java Install" "Java installation complete"
  228. exit 0;
  229. else
  230. 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."
  231. echo "Adding java-bin: ${installdir}/bin/java -> ${PWD}/java-bin"
  232. ln -s ${installdir}/bin/java ${PWD}/java-bin
  233. exit 0;
  234. fi;
  235. else
  236. errordialog "Java Install" "You must agree to the license before java can be installed"
  237. fi;
  238. exit 1;