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

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