Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

getjre.sh 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/sh
  2. #
  3. # This script downloads a JRE.
  4. #
  5. ## Helper Functions
  6. ISKDE=`pidof -x -s kdeinit`
  7. KDIALOG=`which kdialog`
  8. ISGNOME=`pidof -x -s gnome-panel`
  9. ZENITY=`which zenity`
  10. errordialog() {
  11. # Send message to console.
  12. echo ""
  13. echo "-----------------------------------------------------------------------"
  14. echo "Error: ${1}"
  15. echo "-----------------------------------------------------------------------"
  16. echo "${2}"
  17. echo "-----------------------------------------------------------------------"
  18. # Now try to use the GUI Dialogs.
  19. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  20. echo "Dialog on Display: ${DISPLAY}"
  21. ${KDIALOG} --title "DMDirc: ${1}" --error "${2}"
  22. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  23. echo "Dialog on Display: ${DISPLAY}"
  24. ${ZENITY} --error --title "DMDirc: ${1}" --text "${2}"
  25. fi
  26. }
  27. messagedialog() {
  28. # Send message to console.
  29. echo ""
  30. echo "-----------------------------------------------------------------------"
  31. echo "Info: ${1}"
  32. echo "-----------------------------------------------------------------------"
  33. echo "${2}"
  34. echo "-----------------------------------------------------------------------"
  35. # Now try to use the GUI Dialogs.
  36. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  37. echo "Dialog on Display: ${DISPLAY}"
  38. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${2}"
  39. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  40. echo "Dialog on Display: ${DISPLAY}"
  41. ${ZENITY} --info --title "DMDirc: ${1}" --text "${2}"
  42. fi
  43. }
  44. questiondialog() {
  45. # Send question to console.
  46. echo ""
  47. echo "-----------------------------------------------------------------------"
  48. echo "Question: ${1}"
  49. echo "-----------------------------------------------------------------------"
  50. echo "${2}"
  51. echo "-----------------------------------------------------------------------"
  52. # Now try to use the GUI Dialogs.
  53. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  54. echo "Dialog on Display: ${DISPLAY}"
  55. ${KDIALOG} --title "DMDirc: ${1}" --yesno "${2}"
  56. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  57. echo "Dialog on Display: ${DISPLAY}"
  58. ${ZENITY} --question --title "DMDirc: ${1}" --text "${2}"
  59. else
  60. echo "Unable to ask question, assuming no."
  61. return 1;
  62. fi
  63. }
  64. ARCH=`uname -m`
  65. # This page redirects us to the correct JRE
  66. URL="http://www.dmdirc.com/getjava/linux/`uname -m`"
  67. length=`wget --spider ${URL} 2>&1 | grep "Length:"| awk '{print $2, $3}' | sed 's/,//g'`
  68. actualLength=${length%% *}
  69. niceLength=`echo ${length##* } | sed 's/[()]//g'`
  70. PIPE=""
  71. wgetpid=""
  72. # Make sure wget and the progressbar die if we do.
  73. badclose() {
  74. if [ "${wgetpid}" != "" ]; then
  75. kill -9 ${wgetpid}
  76. fi;
  77. if [ "${PIPE}" != "" ]; then
  78. if [ -e ${PIPE} ]; then
  79. echo "quit" > ${PIPE}
  80. rm -Rf ${PIPE}
  81. fi
  82. fi
  83. }
  84. trap 'badclose' INT TERM EXIT
  85. if [ "" != "${1}" ]; then
  86. questiondialog "Download JRE" "${1} (Download Size: ${niceLength})"
  87. result=$?
  88. else
  89. questiondialog "Download JRE" "Would you like to download the java JRE? (Download Size: ${niceLength})"
  90. result=$?
  91. fi;
  92. if [ $result -eq 0 ]; then
  93. PIPE=`mktemp -p ${PWD} progresspipe.XXXXXXXXXXXXXX`
  94. /bin/sh ${PWD}/progressbar.sh "Downloading JRE.." ${actualLength} ${PIPE} &
  95. wget -q ${URL} -O jre.bin &
  96. wgetpid=${!}
  97. while [ `ps ${wgetpid} | wc -l` = 2 ]; do
  98. SIZE=`ls -l jre.bin | awk '{print $5}'`
  99. if [ -e ${PIPE} ]; then
  100. echo "${SIZE}" > ${PIPE}
  101. else
  102. kill -9 ${wgetpid}
  103. errordialog "Download Canceled" "Download Canceled by user"
  104. exit 1;
  105. fi;
  106. done;
  107. wgetpid=""
  108. echo "quit" > ${PIPE}
  109. messagedialog "Download Completed" "Download Completed"
  110. exit 1;
  111. else
  112. messagedialog "Download JRE" "JRE Download Canceled"
  113. fi;