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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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
  67. if [ ${actualLength} -ge 1048576 ]; then
  68. niceLength=`echo "scale=2; ${actualLength}/1048576" | bc`"MB"
  69. elif [ ${actualLength} -ge 1024 ]; then
  70. niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"KB"
  71. else
  72. niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"B"
  73. fi;
  74. if [ "${actualLength}" = "6" ]; then
  75. # Unable to download.
  76. errordialog "Download Failed" "Unable to find JRE for this platform (`uname -s`/${ARCH})."
  77. exit 1;
  78. fi;
  79. PIPE=""
  80. wgetpid=""
  81. # Make sure wget and the progressbar die if we do.
  82. badclose() {
  83. if [ "${wgetpid}" != "" ]; then
  84. kill -9 ${wgetpid}
  85. fi;
  86. if [ "${PIPE}" != "" ]; then
  87. if [ -e ${PIPE} ]; then
  88. echo "quit" > ${PIPE}
  89. echo "Closing badly, pipe still exists."
  90. fi
  91. fi
  92. }
  93. trap 'badclose' INT TERM EXIT
  94. if [ "" != "${1}" ]; then
  95. questiondialog "Download JRE" "${1} (Download Size: ${niceLength})"
  96. result=$?
  97. else
  98. questiondialog "Download JRE" "Would you like to download the java JRE? (Download Size: ${niceLength})"
  99. result=$?
  100. fi;
  101. if [ $result -eq 0 ]; then
  102. PIPE=`mktemp progresspipe.XXXXXXXXXXXXXX`
  103. if [ "${WGET}" != "" ]; then
  104. ${WGET} -q -O jre.bin ${URL} &
  105. wgetpid=${!}
  106. elif [ "${FETCH}" != "" ]; then
  107. ${FETCH} -q -o jre.bin ${URL} &
  108. wgetpid=${!}
  109. elif [ "${CURL}" != "" ]; then
  110. ${CURL} -s -o jre.bin ${URL} &
  111. wgetpid=${!}
  112. fi;
  113. /bin/sh ${PWD}/progressbar.sh "Downloading JRE.." ${actualLength} ${PIPE} ${wgetpid} &
  114. progressbarpid=${!}
  115. while [ `ps -p ${wgetpid} | wc -l` = 2 ]; do
  116. SIZE=`ls -l jre.bin | awk '{print $5}'`
  117. if [ -e ${PIPE} ]; then
  118. echo "${SIZE}" > ${PIPE}
  119. else
  120. kill -9 ${wgetpid}
  121. errordialog "Download Canceled" "Download Canceled by user"
  122. exit 1;
  123. fi;
  124. done;
  125. wgetpid=""
  126. if [ "${ISFREEBSD}" != "" -o "${ISAINFO}" != "" ]; then
  127. echo "Killing progressbar"
  128. kill ${progressbarpid}
  129. fi;
  130. messagedialog "Download Completed" "Download Completed"
  131. if [ -e ${PIPE} ]; then
  132. echo "Deleting Pipe ${PIPE}"
  133. rm -Rf "${PIPE}"
  134. fi;
  135. exit 0;
  136. else
  137. messagedialog "Download JRE" "JRE Download Canceled"
  138. exit 1;
  139. fi;
  140. exit 1;