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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/bin/sh
  2. #
  3. # This script downloads a JRE.
  4. #
  5. PIDOF=`which pidof`
  6. if [ "${PIDOF}" = "" ]; then
  7. # For some reason some distros hide pidof...
  8. if [ -e /sbin/pidof ]; then
  9. PIDOF=/sbin/pidof
  10. elif [ -e /usr/sbin/pidof ]; then
  11. PIDOF=/usr/sbin/pidof
  12. fi;
  13. fi;
  14. ## Helper Functions
  15. if [ "${PIDOF}" = "" ]; then
  16. ISKDE=`${PIDOF} -x -s kdeinit`
  17. ISGNOME=`${PIDOF} -x -s gnome-panel`
  18. else
  19. ISKDE=`ps ux | grep kdeinit | grep -v grep`
  20. ISGNOME=`ps ux | grep gnome-panel | grep -v grep`
  21. fi;
  22. KDIALOG=`which kdialog`
  23. ZENITY=`which zenity`
  24. errordialog() {
  25. # Send message to console.
  26. echo ""
  27. echo "-----------------------------------------------------------------------"
  28. echo "Error: ${1}"
  29. echo "-----------------------------------------------------------------------"
  30. echo "${2}"
  31. echo "-----------------------------------------------------------------------"
  32. # Now try to use the GUI Dialogs.
  33. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  34. echo "Dialog on Display: ${DISPLAY}"
  35. ${KDIALOG} --title "DMDirc: ${1}" --error "${2}"
  36. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  37. echo "Dialog on Display: ${DISPLAY}"
  38. ${ZENITY} --error --title "DMDirc: ${1}" --text "${2}"
  39. fi
  40. }
  41. messagedialog() {
  42. # Send message to console.
  43. echo ""
  44. echo "-----------------------------------------------------------------------"
  45. echo "Info: ${1}"
  46. echo "-----------------------------------------------------------------------"
  47. echo "${2}"
  48. echo "-----------------------------------------------------------------------"
  49. # Now try to use the GUI Dialogs.
  50. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  51. echo "Dialog on Display: ${DISPLAY}"
  52. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${2}"
  53. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  54. echo "Dialog on Display: ${DISPLAY}"
  55. ${ZENITY} --info --title "DMDirc: ${1}" --text "${2}"
  56. fi
  57. }
  58. questiondialog() {
  59. # Send question to console.
  60. echo ""
  61. echo "-----------------------------------------------------------------------"
  62. echo "Question: ${1}"
  63. echo "-----------------------------------------------------------------------"
  64. echo "${2}"
  65. echo "-----------------------------------------------------------------------"
  66. # Now try to use the GUI Dialogs.
  67. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  68. echo "Dialog on Display: ${DISPLAY}"
  69. ${KDIALOG} --title "DMDirc: ${1}" --yesno "${2}"
  70. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  71. echo "Dialog on Display: ${DISPLAY}"
  72. ${ZENITY} --question --title "DMDirc: ${1}" --text "${2}"
  73. else
  74. echo "Unable to ask question, assuming no."
  75. return 1;
  76. fi
  77. }
  78. ARCH=`uname -m`
  79. # This page redirects us to the correct JRE
  80. URL="http://www.dmdirc.com/getjava/linux/`uname -m`"
  81. length=`wget --spider ${URL} 2>&1 | grep "Length:"| awk '{print $2, $3}' | sed 's/,//g'`
  82. actualLength=${length%% *}
  83. niceLength=`echo ${length##* } | sed 's/[()]//g'`
  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. rm -Rf ${PIPE}
  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})"
  104. result=$?
  105. fi;
  106. if [ $result -eq 0 ]; then
  107. PIPE=`mktemp -p ${PWD} progresspipe.XXXXXXXXXXXXXX`
  108. /bin/sh ${PWD}/progressbar.sh "Downloading JRE.." ${actualLength} ${PIPE} &
  109. wget -q ${URL} -O jre.bin &
  110. wgetpid=${!}
  111. while [ `ps ${wgetpid} | wc -l` = 2 ]; do
  112. SIZE=`ls -l jre.bin | awk '{print $5}'`
  113. if [ -e ${PIPE} ]; then
  114. echo "${SIZE}" > ${PIPE}
  115. else
  116. kill -9 ${wgetpid}
  117. errordialog "Download Canceled" "Download Canceled by user"
  118. exit 1;
  119. fi;
  120. done;
  121. wgetpid=""
  122. echo "quit" > ${PIPE}
  123. messagedialog "Download Completed" "Download Completed"
  124. exit 1;
  125. else
  126. messagedialog "Download JRE" "JRE Download Canceled"
  127. fi;