Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

installjre.sh 9.4KB

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