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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. if [ "${ISAINFO}" != "" ]; then
  104. # Solaris-ish
  105. ARCH=`uname -p`
  106. fi;
  107. URL="http://www.dmdirc.com/getjava/`uname -s`/${ARCH}"
  108. WGET=`which wget`
  109. FETCH=`which fetch`
  110. CURL=`which curl`
  111. if [ "${WGET}" != "" ]; then
  112. length=`${WGET} --spider ${URL} 2>&1 | grep "Length:"| awk '{print $2, $3}' | sed 's/,//g'`
  113. actualLength=${length%% *}
  114. elif [ "${FETCH}" != "" ]; then
  115. actualLength=`${FETCH} -s ${URL}`
  116. elif [ "${CURL}" != "" ]; then
  117. length=`${CURL} -# -I ${URL} 2>&1 | grep "Content-Length:"| awk '{print $2}'`
  118. fi;
  119. # Convert the length from Bytes to something user-friendly
  120. if [ ${actualLength} -ge 1048576 ]; then
  121. niceLength=`echo "scale=2; ${actualLength}/1048576" | bc`"MB"
  122. elif [ ${actualLength} -ge 1024 ]; then
  123. niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"KB"
  124. else
  125. niceLength=`echo "scale=2; ${actualLength}/1024" | bc`"B"
  126. fi;
  127. if [ "${actualLength}" = "6" ]; then
  128. # Unable to download.
  129. errordialog "Download Failed" "Unable to find JRE for this platform (`uname -s`/${ARCH})."
  130. exit 1;
  131. fi;
  132. PIPE=""
  133. wgetpid=""
  134. # Make sure wget and the progressbar die if we do.
  135. badclose() {
  136. if [ "${wgetpid}" != "" ]; then
  137. kill -9 ${wgetpid}
  138. fi;
  139. if [ "${PIPE}" != "" ]; then
  140. if [ -e ${PIPE} ]; then
  141. echo "quit" > ${PIPE}
  142. echo "Closing badly, pipe still exists."
  143. fi
  144. fi
  145. }
  146. trap 'badclose' INT TERM EXIT
  147. if [ "" != "${1}" ]; then
  148. questiondialog "Download JRE" "${1} (Download Size: ${niceLength})"
  149. result=$?
  150. else
  151. questiondialog "Download JRE" "Would you like to download the java JRE? (Download Size: ${niceLength})"
  152. result=$?
  153. fi;
  154. if [ $result -eq 0 ]; then
  155. PIPE=`mktemp -p ${PWD} progresspipe.XXXXXXXXXXXXXX`
  156. if [ "${WGET}" != "" ]; then
  157. ${WGET} -q -O jre.bin ${URL} &
  158. wgetpid=${!}
  159. elif [ "${FETCH}" != "" ]; then
  160. ${FETCH} -q -o jre.bin &
  161. wgetpid=${!}
  162. elif [ "${CURL}" != "" ]; then
  163. ${CURL} -s -o jre.bin ${URL} &
  164. wgetpid=${!}
  165. fi;
  166. /bin/sh ${PWD}/progressbar.sh "Downloading JRE.." ${actualLength} ${PIPE} ${wgetpid} &
  167. progressbarpid=${!}
  168. while [ `ps -p ${wgetpid} | wc -l` = 2 ]; do
  169. SIZE=`ls -l jre.bin | awk '{print $5}'`
  170. if [ -e ${PIPE} ]; then
  171. echo "${SIZE}" > ${PIPE}
  172. else
  173. kill -9 ${wgetpid}
  174. errordialog "Download Canceled" "Download Canceled by user"
  175. exit 1;
  176. fi;
  177. done;
  178. wgetpid=""
  179. # echo "Killing progressbar"
  180. # kill ${progressbarpid}
  181. messagedialog "Download Completed" "Download Completed"
  182. if [ -e ${PIPE} ]; then
  183. echo "Deleting Pipe ${PIPE}"
  184. rm -Rf "${PIPE}"
  185. fi;
  186. exit 0;
  187. else
  188. messagedialog "Download JRE" "JRE Download Canceled"
  189. exit 1;
  190. fi;
  191. exit 1;