TDE base libraries and programs
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.

80 lines
1.8KB

  1. #!/bin/sh
  2. # Script used by kdesktop to eject a removable media (CDROM/Tape/SCSI/Floppy)
  3. # Relies on the 'eject' program, 'cdcontrol' on FreeBSD
  4. #
  5. # Copyright GPL v2 by David Faure <david@mandrakesoft.com>
  6. #
  7. quiet=0
  8. if test "$1" = "-q"; then
  9. quiet=1
  10. shift
  11. fi
  12. if test "$1" = "--help"; then
  13. echo "Usage: $0 <name> where name is a device or a mountpoint."
  14. exit 0
  15. fi
  16. if test -z "$1"; then
  17. for dev in /dev/cdrom /dev/dvd /dev/dvdram /dev/cdrecorder; do
  18. if test -e $dev; then
  19. lp=`readlink $dev`
  20. if test -n "$lp"; then
  21. device=/dev/$lp
  22. else
  23. device=$dev
  24. fi
  25. break
  26. fi
  27. done
  28. else
  29. device=$1
  30. fi
  31. udi=`dcop kded mediamanager properties $device 2>/dev/null | head -n 1 `
  32. if test -n "$udi"; then
  33. dcop kded mediamanager unmount "$udi" >/dev/null 2>&1
  34. fi
  35. # Checking for stuff in the PATH is ugly with sh.
  36. # I guess this is the reason for making this a TDE app...
  37. OS=`uname -s`
  38. case "$OS" in
  39. OpenBSD)
  40. cdio -f $device eject #>/dev/null 2>&1
  41. ;;
  42. NetBSD)
  43. dev=$1
  44. if [ -h $1 ]; then
  45. dev=$(readlink $dev 2> /dev/null) || dev=$1;
  46. fi
  47. case $(sysctl -n kern.rawpartition 2> /dev/null) in
  48. 2) rapw=c ;;
  49. 3) rapw=d ;;
  50. esac
  51. rdev=$(echo $dev | sed -E -e 's#(/dev/)#1r#; s#[a-z]$#'$rawp'#')
  52. if [ -e $rdev]; then
  53. eject $rdev >/dev/null 2>&1
  54. else
  55. eject $dev >/dev/null 2>&1
  56. fi
  57. ;;
  58. *BSD)
  59. dev=`echo $device | sed -E -e 's#/dev/##' -e 's/([0-9])./\1/'`
  60. cdcontrol -f $dev eject #>/dev/null 2>&1
  61. ;;
  62. *)
  63. # Warning, it has to be either eject 2.0.x or >=2.1.5
  64. # Otherwise it doesn't work as expected (it requires a
  65. # fstab entry for no reason).
  66. eject -v $device #>/dev/null 2>&1
  67. ;;
  68. esac
  69. if test $? -eq 0; then
  70. #dcop kdesktop default refreshIcons
  71. exit 0
  72. elif test $quiet -eq 0; then
  73. kdialog --title "TDE Eject" --error "Eject $device failed!"
  74. fi
  75. exit 1