]>
git.ipfire.org Git - thirdparty/systemd.git/blob - extras/rule_generator/write_cd_rules
3 # This script is run if an optical drive lacks a rule for persistent naming.
5 # It adds symlinks for optical drives based on the device class determined
6 # by cdrom_id and used ID_PATH to identify the device.
8 # (C) 2006 Marco d'Itri <md@Linux.IT>
10 # This program is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by the
12 # Free Software Foundation version 2 of the License.
14 RULES_FILE
="/etc/udev/rules.d/70-persistent-cd.rules"
16 .
/lib
/udev
/rule_generator.functions
18 find_next_available
() {
19 raw_find_next_available
"$(find_all_rules 'SYMLINK+=' $1)"
28 if [ "$PRINT_HEADER" ]; then
30 echo "# This file was automatically generated by the $0"
31 echo "# program, probably run by the cd-aliases-generator.rules rules file."
33 echo "# You can modify it, as long as you keep each rule on a single line"
34 echo "# and set the \$GENERATED variable."
38 [ "$comment" ] && echo "# $comment"
39 echo "$match, SYMLINK+=\"$link\", ENV{GENERATED}=\"1\""
41 SYMLINKS
="$SYMLINKS $link"
44 if [ -z "$DEVPATH" ]; then
45 echo "Missing \$DEVPATH." >&2
48 if [ -z "$ID_CDROM" ]; then
49 echo "$DEVPATH is not a CD reader." >&2
53 # Prevent concurrent processes from modifying the file at the same time.
56 # Check if the rules file is writeable.
59 link_num
=$
(find_next_available
'cdrom[0-9]*')
61 match
="ENV{ID_CDROM}==\"?*\", ENV{ID_PATH}==\"$ID_PATH\""
63 comment
="$ID_MODEL ($ID_PATH)"
65 write_rule
"$match" "cdrom$link_num" "$comment"
66 [ "$ID_CDROM_CD_R" -o "$ID_CDROM_CD_RW" ] && \
67 write_rule
"$match" "cdrw$link_num"
68 [ "$ID_CDROM_DVD" ] && \
69 write_rule
"$match" "dvd$link_num"
70 [ "$ID_CDROM_DVD_R" -o "$ID_CDROM_DVD_RW" -o "$ID_CDROM_DVD_RAM" ] && \
71 write_rule
"$match" "dvdrw$link_num"