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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. ## Helper Functions
  37. if [ "${PIDOF}" != "" ]; then
  38. ISKDE=`${PIDOF} -x -s kdeinit`
  39. ISGNOME=`${PIDOF} -x -s gnome-panel`
  40. else
  41. ISKDE=`ps -Af | grep kdeinit | grep -v grep`
  42. ISGNOME=`ps -Af | grep gnome-panel | grep -v grep`
  43. fi;
  44. KDIALOG=`which kdialog`
  45. ZENITY=`which zenity`
  46. errordialog() {
  47. # Send message to console.
  48. echo ""
  49. echo "-----------------------------------------------------------------------"
  50. echo "Error: ${1}"
  51. echo "-----------------------------------------------------------------------"
  52. echo "${2}"
  53. echo "-----------------------------------------------------------------------"
  54. # Now try to use the GUI Dialogs.
  55. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  56. echo "Dialog on Display: ${DISPLAY}"
  57. ${KDIALOG} --title "DMDirc: ${1}" --error "${2}"
  58. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  59. echo "Dialog on Display: ${DISPLAY}"
  60. ${ZENITY} --error --title "DMDirc: ${1}" --text "${2}"
  61. fi
  62. }
  63. messagedialog() {
  64. # Send message to console.
  65. echo ""
  66. echo "-----------------------------------------------------------------------"
  67. echo "Info: ${1}"
  68. echo "-----------------------------------------------------------------------"
  69. echo "${2}"
  70. echo "-----------------------------------------------------------------------"
  71. # Now try to use the GUI Dialogs.
  72. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  73. echo "Dialog on Display: ${DISPLAY}"
  74. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${2}"
  75. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  76. echo "Dialog on Display: ${DISPLAY}"
  77. ${ZENITY} --info --title "DMDirc: ${1}" --text "${2}"
  78. fi
  79. }
  80. questiondialog() {
  81. # Send question to console.
  82. echo ""
  83. echo "-----------------------------------------------------------------------"
  84. echo "Question: ${1}"
  85. echo "-----------------------------------------------------------------------"
  86. echo "${2}"
  87. echo "-----------------------------------------------------------------------"
  88. # Now try to use the GUI Dialogs.
  89. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  90. echo "Dialog on Display: ${DISPLAY}"
  91. ${KDIALOG} --title "DMDirc: ${1}" --yesno "${2}"
  92. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  93. echo "Dialog on Display: ${DISPLAY}"
  94. ${ZENITY} --question --title "DMDirc: ${1}" --text "${2}"
  95. else
  96. echo "Unable to ask question, assuming no."
  97. return 1;
  98. fi
  99. }
  100. # Get the JRE.
  101. ARCH=`uname -m`
  102. ISAINFO=`which isainfo`
  103. ISFREEBSD=`uname -s | grep -i FreeBSD`
  104. if [ "${ISAINFO}" != "" ]; then
  105. # Solaris-ish
  106. ARCH=`uname -p`
  107. fi;
  108. URL="http://www.dmdirc.com/getjava/`uname -s`/${ARCH}"
  109. if [ "${ISFREEBSD}" != "" ]; then
  110. RELEASE=`uname -r`
  111. URL="${URL}/${RELEASE}"
  112. fi;
  113. WGET=`which wget`
  114. FETCH=`which fetch`
  115. CURL=`which curl`
  116. if [ "${WGET}" != "" ]; then
  117. length=`${WGET} --spider ${URL} 2>&1 | grep "Length:"| awk '{print $2, $3}' | sed 's/,//g'`
  118. actualLength=${length%% *}
  119. elif [ "${FETCH}" != "" ]; then
  120. actualLength=`${FETCH} -s ${URL}`
  121. elif [ "${CURL}" != "" ]; then
  122. length=`${CURL} -# -I ${URL} 2>&1 | grep "Content-Length:"| awk '{print $2}'`
  123. fi;
  124. # Convert the length from Bytes to something user-friendly
  125. if [ ${actualLength} -ge 1048576 ]; then
  126. niceLength=`echo "scale=2; ${actualLength}/1048576" | bc`"MB"
  127. elif [ ${actualLength} -ge 1024 ]; then
  128. niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"KB"
  129. else
  130. niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"B"
  131. fi;
  132. if [ "${actualLength}" = "6" ]; then
  133. # Unable to download.
  134. errordialog "Download Failed" "Unable to find JRE for this platform (`uname -s`/${ARCH})."
  135. exit 1;
  136. fi;
  137. PIPE=""
  138. wgetpid=""
  139. # Make sure wget and the progressbar die if we do.
  140. badclose() {
  141. if [ "${wgetpid}" != "" ]; then
  142. kill -9 ${wgetpid}
  143. fi;
  144. if [ "${PIPE}" != "" ]; then
  145. if [ -e ${PIPE} ]; then
  146. echo "quit" > ${PIPE}
  147. echo "Closing badly, pipe still exists."
  148. fi
  149. fi
  150. }
  151. trap 'badclose' INT TERM EXIT
  152. if [ "" != "${1}" ]; then
  153. questiondialog "Download JRE" "${1} (Download Size: ${niceLength})"
  154. result=$?
  155. else
  156. questiondialog "Download JRE" "Would you like to download the java JRE? (Download Size: ${niceLength})"
  157. result=$?
  158. fi;
  159. if [ $result -eq 0 ]; then
  160. PIPE=`mktemp progresspipe.XXXXXXXXXXXXXX`
  161. if [ "${WGET}" != "" ]; then
  162. ${WGET} -q -O jre.bin ${URL} &
  163. wgetpid=${!}
  164. elif [ "${FETCH}" != "" ]; then
  165. ${FETCH} -q -o jre.bin ${URL} &
  166. wgetpid=${!}
  167. elif [ "${CURL}" != "" ]; then
  168. ${CURL} -s -o jre.bin ${URL} &
  169. wgetpid=${!}
  170. fi;
  171. /bin/sh ${PWD}/progressbar.sh "Downloading JRE.." ${actualLength} ${PIPE} ${wgetpid} &
  172. progressbarpid=${!}
  173. while [ `ps -p ${wgetpid} | wc -l` = 2 ]; do
  174. SIZE=`ls -l jre.bin | awk '{print $5}'`
  175. if [ -e ${PIPE} ]; then
  176. echo "${SIZE}" > ${PIPE}
  177. else
  178. kill -9 ${wgetpid}
  179. errordialog "Download Canceled" "Download Canceled by user"
  180. exit 1;
  181. fi;
  182. done;
  183. wgetpid=""
  184. if [ "${ISFREEBSD}" != "" -o "${ISAINFO}" != "" ]; then
  185. echo "Killing progressbar"
  186. kill ${progressbarpid}
  187. fi;
  188. messagedialog "Download Completed" "Download Completed"
  189. if [ -e ${PIPE} ]; then
  190. echo "Deleting Pipe ${PIPE}"
  191. rm -Rf "${PIPE}"
  192. fi;
  193. exit 0;
  194. else
  195. messagedialog "Download JRE" "JRE Download Canceled"
  196. exit 1;
  197. fi;
  198. exit 1;