General TC > Programming & Scripting - Unofficial
A simple script for mounting cdrom disc automatically when insert disc
littlebat:
--- Code: (bash) ---#!/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
--- End code ---
Todo: It can't detect audio CD inserting and mount it with "-t cdfs", any idea?
Rich:
Hi littlebat
--- Quote ---It can't detect audio CD inserting and mount it with "-t cdfs", any idea?
--- End quote ---
--- Code: ---/bin/dd if=/dev/cdrom of=cdpresent count=1
--- End code ---
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.
gerald_clark:
Try 'blkid /dev/sr0'
Rich:
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.
gerald_clark:
You can't mount audio CDs, and I am not aware of any CDfs for core.
Navigation
[0] Message Index
[#] Next page
Go to full version