systemd/udev-check-cdrom.sh
2023-12-30 11:35:14 +01:00

59 lines
1.5 KiB
Bash

#!/bin/bash
# check-cdrom -- udev helper script for QiLinux
# Copyright (C) 2005 Davide Madrisan <davide.madrisan@qilinux.it>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the
# Free Software Foundation. There is NO warranty; not even for MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.
#
# Report bugs to <davide.madrisan@qilinux.it>
# NOTE : not enough info in /sys/block/<dev>, so we use /proc
[ -e /proc/sys/dev/cdrom/info ] || exit 1
dev=$1
what=$2
unset vcdrom vwhat
# NOTE: example of /proc/sys/dev/cdrom/info
# CD-ROM information, Id: cdrom.c 3.20 2003/12/17
# drive name: hdd hdc
# drive speed: 52 32
# ...
# Can play audio: 1 1
# Can write CD-R: 0 1
# Can write CD-RW: 0 1
# Can read DVD: 0 1
# Can write DVD-R: 0 1
# Can write DVD-RAM: 0 0
# ...
/bin/cat /proc/sys/dev/cdrom/info | {
while read line; do
case "$line" in
drive\ name:*)
set ${line##*:}
vcdrom=($@)
let "found_dev = 0"
for cdrom in ${vcdrom[@]}; do
[ "$cdrom" = "$dev" ] &&
{ let "found_dev = 1"; break; }
done
[ "$found_dev" = 1 ] || exit 1
;;
*\ $what:*)
set ${line##*:}
for cdrom in ${vcdrom[@]}; do
[ "$cdrom" = "$dev" -a "$1" = 1 ] && exit 0
shift
done
;;
esac
done
exit 1
}