source: udev-lfs/write_cd_rules@ b2b1e1a

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 7.3 7.4 7.5 7.5-systemd 7.6 7.6-systemd 7.7 7.7-systemd 7.8 7.8-systemd 7.9 7.9-systemd 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since b2b1e1a was b2b1e1a, checked in by Bruce Dubbs <bdubbs@…>, 12 years ago

Move directory to make build easier

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@9973 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100755
File size: 3.5 KB
Line 
1#!/bin/sh -e
2
3# This script is run if an optical drive lacks a rule for persistent naming.
4#
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.
7
8# (C) 2006 Marco d'Itri <md@Linux.IT>
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 2 of the License, or
13# (at your option) any later version.
14
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19
20# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23# debug, if UDEV_LOG=<debug>
24if [ -n "$UDEV_LOG" ]; then
25 if [ "$UDEV_LOG" -ge 7 ]; then
26 set -x
27 fi
28fi
29
30RULES_FILE="/etc/udev/rules.d/70-persistent-cd.rules"
31
32. /lib/udev/rule_generator.functions
33
34find_next_available() {
35 raw_find_next_available "$(find_all_rules 'SYMLINK\+=' "$1")"
36}
37
38write_rule() {
39 local match="$1"
40 local link="$2"
41 local comment="$3"
42
43 {
44 if [ "$PRINT_HEADER" ]; then
45 PRINT_HEADER=
46 echo "# This file was automatically generated by the $0"
47 echo "# program, run by the cd-aliases-generator.rules rules file."
48 echo "#"
49 echo "# You can modify it, as long as you keep each rule on a single"
50 echo "# line, and set the \$GENERATED variable."
51 echo ""
52 fi
53
54 [ "$comment" ] && echo "# $comment"
55 echo "$match, SYMLINK+=\"$link\", ENV{GENERATED}=\"1\""
56 } >> $RULES_FILE
57 SYMLINKS="$SYMLINKS $link"
58}
59
60if [ -z "$DEVPATH" ]; then
61 echo "Missing \$DEVPATH." >&2
62 exit 1
63fi
64if [ -z "$ID_CDROM" ]; then
65 echo "$DEVPATH is not a CD reader." >&2
66 exit 1
67fi
68
69if [ "$1" ]; then
70 METHOD="$1"
71else
72 METHOD='by-path'
73fi
74
75case "$METHOD" in
76 by-path)
77 if [ -z "$ID_PATH" ]; then
78 echo "$DEVPATH not supported by path_id. by-id may work." >&2
79 exit 1
80 fi
81 RULE="ENV{ID_PATH}==\"$ID_PATH\""
82 ;;
83
84 by-id)
85 if [ "$ID_SERIAL" ]; then
86 RULE="ENV{ID_SERIAL}==\"$ID_SERIAL\""
87 elif [ "$ID_MODEL" -a "$ID_REVISION" ]; then
88 RULE="ENV{ID_MODEL}==\"$ID_MODEL\", ENV{ID_REVISION}==\"$ID_REVISION\""
89 else
90 echo "$DEVPATH not supported by ata_id. by-path may work." >&2
91 exit 1
92 fi
93 ;;
94
95 *)
96 echo "Invalid argument (must be either by-path or by-id)." >&2
97 exit 1
98 ;;
99esac
100
101# Prevent concurrent processes from modifying the file at the same time.
102lock_rules_file
103
104# Check if the rules file is writeable.
105choose_rules_file
106
107link_num=$(find_next_available 'cdrom[0-9]*')
108
109match="SUBSYSTEM==\"block\", ENV{ID_CDROM}==\"?*\", $RULE"
110
111comment="$ID_MODEL ($ID_PATH)"
112
113 write_rule "$match" "cdrom$link_num" "$comment"
114[ "$ID_CDROM_CD_R" -o "$ID_CDROM_CD_RW" ] && \
115 write_rule "$match" "cdrw$link_num"
116[ "$ID_CDROM_DVD" ] && \
117 write_rule "$match" "dvd$link_num"
118[ "$ID_CDROM_DVD_R" -o "$ID_CDROM_DVD_RW" -o "$ID_CDROM_DVD_RAM" ] && \
119 write_rule "$match" "dvdrw$link_num"
120echo >> $RULES_FILE
121
122unlock_rules_file
123
124echo $SYMLINKS
125
126exit 0
Note: See TracBrowser for help on using the repository browser.