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.

getjre.sh 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/bin/sh
  2. #
  3. # This script downloads a JRE.
  4. #
  5. # Check the which command exists, and if so make sure it behaves how we want
  6. # it to...
  7. WHICH=`which which 2>/dev/null`
  8. if [ "" = "${WHICH}" ]; then
  9. echo "which command not found. Aborting.";
  10. exit 0;
  11. else
  12. # Solaris sucks
  13. BADWHICH=`which /`
  14. if [ "${BADWHICH}" != "" ]; then
  15. echo "Replacing bad which command.";
  16. # "Which" on solaris gives non-empty results for commands that don't exist
  17. which() {
  18. OUT=`${WHICH} ${1}`
  19. if [ $? -eq 0 ]; then
  20. echo ${OUT}
  21. else
  22. echo ""
  23. fi;
  24. }
  25. fi;
  26. fi
  27. # Find out where we are
  28. BASEDIR=${0%/*}
  29. if [ "${BASEDIR}" = "${0}" ]; then
  30. BASEDIR=`which $0`
  31. BASEDIR=${BASEDIR%/*}
  32. fi
  33. CHECKBASEDIR=`echo "${BASEDIR}" | sed 's#^/##'`
  34. if [ "${CHECKBASEDIR}" = "${BASEDIR}" ]; then
  35. BASEDIR=${PWD}/${BASEDIR}
  36. fi;
  37. PIDOF=`which pidof`
  38. if [ "${PIDOF}" = "" ]; then
  39. # For some reason some distros hide pidof...
  40. if [ -e /sbin/pidof ]; then
  41. PIDOF=/sbin/pidof
  42. elif [ -e /usr/sbin/pidof ]; then
  43. PIDOF=/usr/sbin/pidof
  44. fi;
  45. fi;
  46. if [ -e "${BASEDIR}/functions.sh" ]; then
  47. . ${BASEDIR}/functions.sh
  48. else
  49. echo "Unable to find functions.sh, unable to continue."
  50. exit 1;
  51. fi;
  52. # Get the JRE.
  53. ARCH=`uname -m`
  54. ISAINFO=`which isainfo`
  55. ISFREEBSD=`uname -s | grep -i FreeBSD`
  56. if [ "${ISAINFO}" != "" ]; then
  57. # Solaris-ish
  58. ARCH=`uname -p`
  59. fi;
  60. URL="http://www.dmdirc.com/getjava/`uname -s`/${ARCH}"
  61. if [ "${ISFREEBSD}" != "" ]; then
  62. RELEASE=`uname -r`
  63. URL="${URL}/${RELEASE}"
  64. fi;
  65. WGET=`which wget`
  66. FETCH=`which fetch`
  67. CURL=`which curl`
  68. if [ "${WGET}" != "" ]; then
  69. length=`${WGET} --spider ${URL} 2>&1 | grep "Length:"| awk '{print $2, $3}' | sed 's/,//g'`
  70. actualLength=${length%% *}
  71. elif [ "${FETCH}" != "" ]; then
  72. actualLength=`${FETCH} -s ${URL}`
  73. elif [ "${CURL}" != "" ]; then
  74. length=`${CURL} -# -I ${URL} 2>&1 | grep "Content-Length:"| awk '{print $2}'`
  75. fi;
  76. # Convert the length from Bytes to something user-friendly is possible.
  77. BC=`which bc`
  78. if [ "${BC}" = "" ]; then
  79. niceLength=${actualLength}"B"
  80. elif [ ${actualLength} -ge 1048576 ]; then
  81. niceLength=`echo "scale=2; ${actualLength}/1048576" | bc`"MB"
  82. elif [ ${actualLength} -ge 1024 ]; then
  83. niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"KB"
  84. else
  85. niceLength=`echo "scale=2; ${actualLength}" | bc`"B"
  86. fi;
  87. if [ "${actualLength}" = "6" ]; then
  88. # Unable to download.
  89. errordialog "Download Failed" "Unable to find JRE for this platform (`uname -s`/${ARCH})."
  90. exit 1;
  91. fi;
  92. PIPE=""
  93. wgetpid=""
  94. # Make sure wget and the progressbar die if we do.
  95. badclose() {
  96. if [ "${wgetpid}" != "" ]; then
  97. kill -9 ${wgetpid}
  98. fi;
  99. if [ "${PIPE}" != "" ]; then
  100. if [ -e ${PIPE} ]; then
  101. echo "quit" > ${PIPE}
  102. echo "Closing badly, pipe still exists."
  103. fi
  104. fi
  105. }
  106. trap 'badclose' INT TERM EXIT
  107. if [ "" != "${1}" ]; then
  108. questiondialog "Download JRE" "${1} (Download Size: ${niceLength})"
  109. result=$?
  110. else
  111. questiondialog "Download JRE" "Would you like to download the java JRE? (Download Size: ${niceLength})\n(Choose no if you want to manually install or install using a package manager)"
  112. result=$?
  113. fi;
  114. if [ $result -eq 0 ]; then
  115. PIPE=`mktemp progresspipe.XXXXXXXXXXXXXX`
  116. if [ "${WGET}" != "" ]; then
  117. ${WGET} -q -O jre.bin ${URL} &
  118. wgetpid=${!}
  119. elif [ "${FETCH}" != "" ]; then
  120. ${FETCH} -q -o jre.bin ${URL} &
  121. wgetpid=${!}
  122. elif [ "${CURL}" != "" ]; then
  123. ${CURL} -s -o jre.bin ${URL} &
  124. wgetpid=${!}
  125. fi;
  126. /bin/sh ${PWD}/progressbar.sh "Downloading JRE.." ${actualLength} ${PIPE} ${wgetpid} &
  127. sleep 1;
  128. progressbarpid=${!}
  129. while [ `ps -p ${wgetpid} | wc -l` = 2 ]; do
  130. SIZE=`ls -l jre.bin | awk '{print $5}'`
  131. if [ -e ${PIPE} ]; then
  132. echo "${SIZE}" > ${PIPE}
  133. else
  134. kill -9 ${wgetpid}
  135. errordialog "Download Canceled" "Download Canceled by user"
  136. exit 1;
  137. fi;
  138. done;
  139. if [ -e ".downloadWasCancelled" ]; then
  140. kill -9 ${wgetpid}
  141. errordialog "Download Canceled" "Download Canceled by user"
  142. exit 1;
  143. fi;
  144. SIZE=`ls -l jre.bin | awk '{print $5}'`
  145. /bin/sh ${PWD}/progressbar.sh --watchdog ${progressbarpid} &
  146. if [ -e ${PIPE} ]; then
  147. echo "${SIZE}" > ${PIPE}
  148. fi;
  149. wgetpid=""
  150. if [ "${ISFREEBSD}" != "" -o "${ISAINFO}" != "" ]; then
  151. echo "Killing progressbar"
  152. kill ${progressbarpid}
  153. fi;
  154. messagedialog "Download Completed" "Download Completed"
  155. if [ -e ${PIPE} ]; then
  156. echo "Deleting Pipe ${PIPE}"
  157. rm -Rf "${PIPE}"
  158. fi;
  159. exit 0;
  160. else
  161. messagedialog "Download JRE" "JRE Download Canceled"
  162. exit 1;
  163. fi;
  164. exit 1;