nonas wrote:truc wrote:...
Merci pour l'info, je regarderai ça à l'occasion mais pour le moment je ne fais tourner ni dbus ni hal donc bon ^^
Une question néanmoins, est-ce que ça gère le démontage propre des disques durs externes ? J'entends par là avec démontage et mise en veille du disque. Actuellement j'utilise ce
script.
Bon, tu n'as toujours pas hal&Cie, mais au cas ou pour les autres, j'ai adapté le script pour pouvoir le mettre dans les options de ROX à la place de la commande umount : ( ROX -> Options -> Action Windows -> umount command : path/to/my-halevt-umount )
Code: Select all
#!/usr/bin/env sh
# Heavily based on http://elliotli.blogspot.com/2009/01/safely-remove-usb-hard-drive-in-linux.html
# From Yan Li <elliot.li.tech@gmail.com>
: ${VERBOSE:=false}
set -e -u
if [ 0 -eq $# ]; then
cat<<EOT
Unmount and suspend a usb device, so you can safely remove it.
Usage:
[VERBOSE=true ]$0 /mount/point
Heavily based on Yan Ly's work:
http://elliotli.blogspot.com/2009/01/safely-remove-usb-hard-drive-in-linux.html
Targeted Users: Those using halevt.
Use this script with your file manager:
eg: ROX -> Options -> Action Windows -> umount command : $0
EOT
exit 1
fi
# turning on/off output
if ! $VERBOSE ; then
exec 1>/dev/null
fi
echo "'\$0: $0' : \$@ $@"
MPT=${1%/}
# INFO='udi:device:mountpoint'
INFO=$(halevt-mount -l | sed -n '\#:'"${MPT}"'$#p')
[ -z "$INFO" ] && { echo "Mountpoint '${MPT}' not found" ; exit 1; }
MOUNTPOINT=${INFO##*:}
INFO=${INFO%:*}
UDI=${INFO%%:*}
DEVICE=${INFO##*:}
echo -e "MOUNTPOINT=${MOUNTPOINT} UDI=${UDI} DEVICE=${DEVICE}"
#lshal -u ${UDI} >> ~/test
DEVICESYS=$(/sbin/udevadm info --query=path --name=${DEVICE} --attribute-walk | \
egrep "parent device.*usb[[:digit:]]+/[[:digit:]]+-[[:digit:]]+'" | \
head -n 1 | cut -d"'" -f2)
# the trailing basename of ${DEVICESYS} is USB_BUS_ID
USB_BUS_ID=${DEVICESYS##*/}
echo "DEVICESYS=${DEVICESYS} USB_BUS_ID=${USB_BUS_ID}"
# Unmounting the device
echo "halevt-umount -u '${UDI}'"
halevt-umount -u "${UDI}"
# send SCSI sync command, some devices don't support this so we just
# ignore errors
echo "sudo sdparm --command=sync '$DEVICE' 2>&1 || true"
sudo sdparm --command=sync "$DEVICE" 2>&1 || true
# send SCSI stop command
echo "sudo sdparm --command=stop '$DEVICE' 2>&1"
sudo sdparm --command=stop "$DEVICE" 2>&1
# unbind it
echo "echo -n '${USB_BUS_ID}' | sudo tee /sys/bus/usb/drivers/usb/unbind > /dev/null"
echo -n "${USB_BUS_ID}" | sudo tee /sys/bus/usb/drivers/usb/unbind > /dev/null
# check if CONFIG_USB_SUSPEND is enabled
POWER_LEVEL_FILE=/sys${DEVICESYS}/power/level
if [ ! -f "$POWER_LEVEL_FILE" ]; then
1>&2 cat<<EOF
It's safe to remove the USB device now but better can be done. The
power level control file $POWER_LEVEL_FILE
doesn't exist on the system so I have no way to put the USB device
into suspend mode, perhaps you don't have CONFIG_USB_SUSPEND enabled
in your running kernel.
Read
http://elliotli.blogspot.com/2009/01/safely-remove-usb-hard-drive-in-linux.html
for an detailed explanation.
EOF
exit 3
fi
echo "echo 'suspend' | sudo tee '$POWER_LEVEL_FILE' >/dev/null"
echo 'suspend' | sudo tee "$POWER_LEVEL_FILE"
# vim: set et sts=3 sw=3 foldmethod=marker :
et les entrées dans le fichier sudoers (elles devraient être suffisantes, mais peut-être avez vous plus de dédé internes que moi, donc à vérifier

)
Code: Select all
Cmnd_Alias SAFE_HW_REMOVAL1= /usr/bin/sdparm --command=sync /dev/sd[bcd][1-9], /usr/bin/sdparm --command=stop /dev/sd[bcd][1-9]
Cmnd_Alias SAFE_HW_REMOVAL2= /usr/bin/tee /sys/bus/usb/drivers/usb/unbind, /usr/bin/tee /sys/devices/*/usb*
%wheel ALL=(root) NOPASSWD: SAFE_HW_REMOVAL1, SAFE_HW_REMOVAL2
(Moyennant les lignes cassées, c'est à peu près tout, et tout roule)