#!/bin/sh
# amountcd.sh
# A simple script for mounting cdrom disc automatically when insert disc.
# It poll cdrom every 2 seconds just like "HAL" and "Udisks" do.
# But it can't take advantage of newer SATA ATAPI hardware which
# supports Asynchronous Notification(AN), see: "man hal-disable-polling".
# Usage: copy it as "/usr/local/bin/amountcd.sh", and
# "chmod +x /usr/local/bin/amountcd.sh", add it into "/opt/bootlocal.sh"
# or some where else, for example: "/usr/local/bin/amountcd.sh &"
# I have tested it on tinycore-3.7.1 and tinycore-4.1 ok.
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
# Read a list of CDROM/DVD Drives
CDROMS=""
CDROMSF=/etc/sysconfig/cdroms
[ -s "$CDROMSF" ] && read CDROMS < "$CDROMSF"
for cdrom in $CDROMS
do
FSTYPE="$(fstype $cdrom)"
devname=`echo $cdrom | sed "s@/dev/@@"`
if [ -z $FSTYPE ]
then
eval sta_$devname="0"
else
eval sta_$devname="1"
fi
#eval echo "first sta_$devname=\${sta_$devname}"
done
while [ 1 ]
do
sleep 2s
#echo "******************"
for cdrom in $CDROMS
do
FSTYPE="$(fstype $cdrom)"
devname=`echo $cdrom | sed "s@/dev/@@"`
if [ -z $FSTYPE ]
then
eval stb_$devname="0"
else
eval stb_$devname="1"
fi
#eval echo sta_$devname=\${sta_$devname}
#eval echo stb_$devname=\${stb_$devname}
eval sta=\${sta_$devname}
eval stb=\${stb_$devname}
if [[ "$sta" == "0" -a "$stb" == "1" ]]
then
mount $cdrom
#echo "mount $cdrom ok"
fi
eval sta_$devname=\${stb_$devname}
done
done
Todo: It can't detect audio CD inserting and mount it with "-t cdfs", any idea?