#!/bin/sh
# Script used by kdesktop to eject a removable media (CDROM/Tape/SCSI/Floppy)
# Relies on the 'eject' program, 'cdcontrol' on *BSD
#
# Copyright GPL v2 by David Faure <david@mandrakesoft.com>
#
# TODO: This should be turned into a KDE app, or at least it should use
# kmessage, to show a message box in case of error.
# We could even borrow code from kscd, apparently.
#
if [ $# = 1 -a "$1" != "--help" ]; then
  # Checking for stuff in the PATH is ugly with sh.
  # I guess this is the reason for making this a kde app...
  OS=`uname -s`
  case "$OS" in
    *BSD)
      dev=`echo $1 | sed -E -e 's#/dev/##' -e 's/([0-9])./\1/'`
      cdcontrol -f $dev eject >/dev/null 2>&1
      ;;
    *)
      eject $1 >/dev/null 2>&1
      ;;
  esac
  if [ $? = 0 ]; then
    dcop kdesktop default refreshIcons
    exit 0
  else
    echo "eject $1 failed !"
  fi
else
  echo "Usage: $0 <name>  where name is a device or a mountpoint"
fi
exit 1

