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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. PIDOF=`which pidof`
  28. if [ "${PIDOF}" = "" ]; then
  29. # For some reason some distros hide pidof...
  30. if [ -e /sbin/pidof ]; then
  31. PIDOF=/sbin/pidof
  32. elif [ -e /usr/sbin/pidof ]; then
  33. PIDOF=/usr/sbin/pidof
  34. fi;
  35. fi;
  36. if [ -e "functions.sh" ]; then
  37. . `dirname $0`/functions.sh
  38. else
  39. echo "Unable to find functions.sh, unable to continue."
  40. exit 1;
  41. fi;
  42. # Get the JRE.
  43. ARCH=`uname -m`
  44. ISAINFO=`which isainfo`
  45. ISFREEBSD=`uname -s | grep -i FreeBSD`
  46. if [ "${ISAINFO}" != "" ]; then
  47. # Solaris-ish
  48. ARCH=`uname -p`
  49. fi;
  50. URL="http://www.dmdirc.com/getjava/`uname -s`/${ARCH}"
  51. if [ "${ISFREEBSD}" != "" ]; then
  52. RELEASE=`uname -r`
  53. URL="${URL}/${RELEASE}"
  54. fi;
  55. WGET=`which wget`
  56. FETCH=`which fetch`
  57. CURL=`which curl`
  58. if [ "${WGET}" != "" ]; then
  59. length=`${WGET} --spider ${URL} 2>&1 | grep "Length:"| awk '{print $2, $3}' | sed 's/,//g'`
  60. actualLength=${length%% *}
  61. elif [ "${FETCH}" != "" ]; then
  62. actualLength=`${FETCH} -s ${URL}`
  63. elif [ "${CURL}" != "" ]; then
  64. length=`${CURL} -# -I ${URL} 2>&1 | grep "Content-Length:"| awk '{print $2}'`
  65. fi;
  66. # Convert the length from Bytes to something user-friendly is possible.
  67. BC=`which bc`
  68. if [ "${BC}" = "" ]; then
  69. niceLength=${actualLength}"B"
  70. elif [ ${actualLength} -ge 1048576 ]; then
  71. niceLength=`echo "scale=2; ${actualLength}/1048576" | bc`"MB"
  72. elif [ ${actualLength} -ge 1024 ]; then
  73. niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"KB"
  74. else
  75. niceLength=`echo "scale=2; ${actualLength}" | bc`"B"
  76. fi;
  77. if [ "${actualLength}" = "6" ]; then
  78. # Unable to download.
  79. errordialog "Download Failed" "Unable to find JRE for this platform (`uname -s`/${ARCH})."
  80. exit 1;
  81. fi;
  82. PIPE=""
  83. wgetpid=""
  84. # Make sure wget and the progressbar die if we do.
  85. badclose() {
  86. if [ "${wgetpid}" != "" ]; then
  87. kill -9 ${wgetpid}
  88. fi;
  89. if [ "${PIPE}" != "" ]; then
  90. if [ -e ${PIPE} ]; then
  91. echo "quit" > ${PIPE}
  92. echo "Closing badly, pipe still exists."
  93. fi
  94. fi
  95. }
  96. trap 'badclose' INT TERM EXIT
  97. if [ "" != "${1}" ]; then
  98. questiondialog "Download JRE" "${1} (Download Size: ${niceLength})"
  99. result=$?
  100. else
  101. questiondialog "Download JRE" "Would you like to download the java JRE? (Download Size: ${niceLength})"
  102. result=$?
  103. fi;
  104. if [ $result -eq 0 ]; then
  105. PIPE=`mktemp progresspipe.XXXXXXXXXXXXXX`
  106. if [ "${WGET}" != "" ]; then
  107. ${WGET} -q -O jre.bin ${URL} &
  108. wgetpid=${!}
  109. elif [ "${FETCH}" != "" ]; then
  110. ${FETCH} -q -o jre.bin ${URL} &
  111. wgetpid=${!}
  112. elif [ "${CURL}" != "" ]; then
  113. ${CURL} -s -o jre.bin ${URL} &
  114. wgetpid=${!}
  115. fi;
  116. /bin/sh ${PWD}/progressbar.sh "Downloading JRE.." ${actualLength} ${PIPE} ${wgetpid} &
  117. sleep 1;
  118. progressbarpid=${!}
  119. while [ `ps -p ${wgetpid} | wc -l` = 2 ]; do
  120. SIZE=`ls -l jre.bin | awk '{print $5}'`
  121. if [ -e ${PIPE} ]; then
  122. echo "${SIZE}" > ${PIPE}
  123. else
  124. kill -9 ${wgetpid}
  125. errordialog "Download Canceled" "Download Canceled by user"
  126. exit 1;
  127. fi;
  128. done;
  129. /bin/sh ${PWD}/progressbar.sh --watchdog ${progressbarpid}
  130. wgetpid=""
  131. if [ "${ISFREEBSD}" != "" -o "${ISAINFO}" != "" ]; then
  132. echo "Killing progressbar"
  133. kill ${progressbarpid}
  134. fi;
  135. messagedialog "Download Completed" "Download Completed"
  136. if [ -e ${PIPE} ]; then
  137. echo "Deleting Pipe ${PIPE}"
  138. rm -Rf "${PIPE}"
  139. fi;
  140. exit 0;
  141. else
  142. messagedialog "Download JRE" "JRE Download Canceled"
  143. exit 1;
  144. fi;
  145. exit 1;