Created
October 28, 2011 14:44
-
-
Save xqms/1322438 to your computer and use it in GitHub Desktop.
Manages the Ultrabay on ThinkPad T400
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
for i in /sys/devices/platform/dock*; do | |
if grep ata_bay "$i/type" &> /dev/null; then | |
dock="$i" | |
break; | |
fi | |
done | |
if [[ -z $dock ]]; then | |
echo "No ultrabay found." | |
exit 1 | |
fi | |
acpi_power_is_on() | |
{ | |
echo '\_SB.PCI0.LPC.CSON' > /proc/acpi/call | |
if [[ $(< /proc/acpi/call) == "0x0" ]]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
acpi_power_enable() | |
{ | |
echo '\_SB.PCI0.LPC.EC.BPON' > /proc/acpi/call | |
} | |
case $1 in | |
dock) | |
if mount | grep /media/hdd &> /dev/null; then | |
echo "HDD already mounted!" | |
exit 0 | |
fi | |
modprobe acpi_call | |
enabled=0 | |
if acpi_power_is_on; then | |
echo "ACPI: Power is already on" | |
else | |
echo "ACPI: enabling power..." | |
acpi_power_enable | |
enabled=1 | |
fi | |
echo "Waiting for device to appear..." | |
i=0 | |
while [[ ! -e /dev/disk/by-uuid/363f6627-7b3e-4849-b8f5-d04e11912efa ]]; do | |
if [[ $i -gt 6 ]]; then | |
echo "Timeout!" | |
echo "Device failed to appear." | |
if [[ $enabled == 1 ]]; then | |
echo "Cutting power again..." | |
echo 1 > "$dock/undock" | |
fi | |
exit 1 | |
fi | |
i=$(( i + 1 )) | |
sleep 1 | |
done | |
echo "Mounting..." | |
mount /media/hdd | |
;; | |
undock) | |
if mount | grep /media/hdd &> /dev/null; then | |
if ! sudo umount /media/hdd; then | |
echo "Could not unmount /media/hdd" | |
exit 1 | |
fi | |
fi | |
sync | |
sleep 1 | |
echo 1 > "$dock/undock" | |
;; | |
*) | |
echo "Usage: $0 [command]" | |
echo "Commands:" | |
echo " undock - Undock ultrabay device" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment