Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: littlebat on January 07, 2012, 05:15:59 AM
-
#!/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?
-
Hi littlebat
It can't detect audio CD inserting and mount it with "-t cdfs", any idea?
/bin/dd if=/dev/cdrom of=cdpresent count=1
If there is no disc in the drive, no file is created.
If there is an audio disc in the drive, an empty file is created.
If there is a data disc in the drive, a 512 byte file is created.
Or you can set of=/dev/null and parse the output of /bin/dd.
-
Try 'blkid /dev/sr0'
-
Hi gerald_clark
He is also trying to detect if the disc is an audio CD. I tried that command and it doesn't return
anything for an audio CD.
-
You can't mount audio CDs, and I am not aware of any CDfs for core.
-
Hi gerald_clark
Quite correct. I was just offering a possible solution to detecting an audio CD, which he ask about.
In order for him to make use of it, he will of course need to create a cdfs extension.
@littlebat: Although I have not tried it, my solution will probably flag a blank disc as being an audio CD.