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.

functions.sh 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/bin/sh
  2. # Check for OS X
  3. OSASCRIPT=`which osascript`
  4. KERNEL=`uname -s`
  5. ISOSX="0"
  6. # Kernel is darwin, and osascript exists, probably OS X!
  7. if [ "${KERNEL}" = "Darwin" -a "" != "${OSASCRIPT}" ]; then
  8. ISOSX="1"
  9. fi;
  10. if [ "${ISOSX}" != "1" ]; then
  11. PIDOF=`which pidof`
  12. if [ "${PIDOF}" = "" ]; then
  13. # For some reason some distros hide pidof...
  14. if [ -e /sbin/pidof ]; then
  15. PIDOF=/sbin/pidof
  16. elif [ -e /usr/sbin/pidof ]; then
  17. PIDOF=/usr/sbin/pidof
  18. fi;
  19. fi;
  20. PGREP=`which pgrep`
  21. if [ "${PIDOF}" != "" ]; then
  22. ISKDE=`${PIDOF} -x -s kdeinit kdeinit4`
  23. ISGNOME=`${PIDOF} -x -s gnome-panel`
  24. elif [ "${PGREP}" != "" ]; then
  25. ISKDE=`pgrep kdeinit`
  26. ISGNOME=`pgrep gnome-panel`
  27. else
  28. ISKDE=`ps -Af | grep kdeinit | grep -v grep`
  29. ISGNOME=`ps -Af | grep gnome-panel | grep -v grep`
  30. fi;
  31. KDIALOG=`which kdialog`
  32. ZENITY=`which zenity`
  33. DIALOG=`which dialog`
  34. KSUDO=`which kdesudo`
  35. GSUDO=`which gksudo`
  36. fi;
  37. if [ "${ISKDE}" != "" -o "${ZENITY}" = "" ]; then
  38. USEKDIALOG="1";
  39. else
  40. USEKDIALOG="0";
  41. fi;
  42. messagedialog() {
  43. # Send message to console.
  44. echo ""
  45. echo "-----------------------------------------------------------------------"
  46. echo "DMDirc: ${1}"
  47. echo "-----------------------------------------------------------------------"
  48. echo "${2}"
  49. echo "-----------------------------------------------------------------------"
  50. # If we are on OSX
  51. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  52. echo "Displaying dialog.."
  53. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} giving up after 120 with icon note" -e 'end tell'
  54. elif [ "" != "${KDIALOG}" -a "" != "${DISPLAY}" -a "" = "${ISGNOME}" -a "${USEKDIALOG}" = "1" ]; then
  55. # else if kdialog exists, and we have a display, and we are not running
  56. # gnome, and either we are running kde or zenity doesn't exist..
  57. echo "Dialog on Display: ${DISPLAY}"
  58. ${KDIALOG} --title "DMDirc: ${1}" --msgbox "${2}"
  59. elif [ "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  60. # Else, if zenity exists and we have a display
  61. echo "Dialog on Display: ${DISPLAY}"
  62. ${ZENITY} --info --title "DMDirc: ${1}" --text "${2}"
  63. elif [ "" != "${DIALOG}" ]; then
  64. # Else, if dialog exists and we have a display
  65. ${DIALOG} --title "DMDirc: ${1}" --msgbox "${2}" 8 40
  66. fi;
  67. }
  68. questiondialog() {
  69. # Send question to console.
  70. echo ""
  71. echo "-----------------------------------------------------------------------"
  72. echo "DMDirc: ${1}"
  73. echo "-----------------------------------------------------------------------"
  74. echo "${2}"
  75. echo "-----------------------------------------------------------------------"
  76. # If we are on OSX
  77. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  78. echo "Displaying dialog.."
  79. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"Line 1\nLine 2\" with icon note" -e 'end tell'
  80. elif [ "" != "${KDIALOG}" -a "" != "${DISPLAY}" -a "" = "${ISGNOME}" -a "${USEKDIALOG}" = "1" ]; then
  81. # else if kdialog exists, and we have a display, and we are not running
  82. # gnome, and either we are running kde or zenity doesn't exist..
  83. echo "Dialog on Display: ${DISPLAY}"
  84. ${KDIALOG} --title "DMDirc: ${1}" --yesno "${2}"
  85. elif [ "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  86. # Else, if zenity exists and we have a display
  87. echo "Dialog on Display: ${DISPLAY}"
  88. ${ZENITY} --question --title "DMDirc: ${1}" --text "${2}"
  89. elif [ "" != "${DIALOG}" ]; then
  90. # Else, if dialog exists and we have a display
  91. ${DIALOG} --title "DMDirc: ${1}" --yesno "${2}" 8 40
  92. elif [ "${3}" != "" ]; then
  93. # Else, fail and return default.
  94. echo "Unable to ask question, assuming '${3}'."
  95. return ${3};
  96. else
  97. # Else, fail and return no.
  98. echo "Unable to ask question, assuming no."
  99. return 1;
  100. fi;
  101. }
  102. errordialog() {
  103. # Send error to console.
  104. echo ""
  105. echo "-----------------------------------------------------------------------"
  106. echo "[Error] DMDirc: ${1}"
  107. echo "-----------------------------------------------------------------------"
  108. echo "${2}"
  109. echo "-----------------------------------------------------------------------"
  110. # If we are on OSX
  111. if [ "${ISOSX}" = "1" -a "" != "${OSASCRIPT}" ]; then
  112. echo "Displaying dialog.."
  113. ${OSASCRIPT} -e 'tell application "System Events"' -e "activate" -e "display dialog \"${1}\n${2}\" buttons {\"Ok\"} with icon stop" -e 'end tell'
  114. elif [ "" != "${KDIALOG}" -a "" != "${DISPLAY}" -a "" = "${ISGNOME}" -a "${USEKDIALOG}" = "1" ]; then
  115. # else if kdialog exists, and we have a display, and we are not running
  116. # gnome, and either we are running kde or zenity doesn't exist..
  117. echo "Dialog on Display: ${DISPLAY}"
  118. ${KDIALOG} --title "DMDirc: ${1}" --error "${2}"
  119. elif [ "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  120. # Else, if zenity exists and we have a display
  121. echo "Dialog on Display: ${DISPLAY}"
  122. ${ZENITY} --error --title "DMDirc: ${1}" --text "${2}"
  123. elif [ "" != "${DIALOG}" ]; then
  124. # Else, if dialog exists and we have a display
  125. ${DIALOG} --title "[Error] DMDirc: ${1}" --msgbox "${2}" 8 40
  126. fi
  127. }