source: udev-lfs/contrib/debian/write_cd_aliases@ 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 100644
File size: 2.6 KB
Line 
1#!/bin/sh -e
2
3RULES_FILE="/etc/udev/rules.d/82-persistent-cd.rules"
4
5##############################################################################
6lock_rules_file() {
7 RULES_LOCK="/dev/.udev/.lock-${RULES_FILE##*/}"
8
9 retry=30
10 while ! mkdir $RULES_LOCK 2> /dev/null; do
11 if [ $retry -eq 0 ]; then
12 echo "Cannot lock $RULES_FILE!" >&2
13 exit 2
14 fi
15 sleep 1
16 retry=$(($retry - 1))
17 done
18}
19
20unlock_rules_file() {
21 rmdir $RULES_LOCK || true
22}
23
24##############################################################################
25find_next_available() {
26 # use echo to convert newlines to spaces
27 local links=`echo $(find_all_symlinks $1)`
28 local basename=${links%%[ 0-9]*}
29 local max=-1
30 for name in $links; do
31 local num=${name#$basename}
32 [ "$num" ] || num=0
33 [ $num -gt $max ] && max=$num
34 done
35
36 max=$(($max + 1))
37 # "name0" actually is just "name"
38 [ $max -eq 0 ] && return
39 echo "$max"
40}
41
42find_all_symlinks() {
43 local linkre="$1"
44 local match="$2"
45
46 [ -e $RULES_FILE ] || return
47
48 local search='.*[[:space:],]SYMLINK+="\('"$linkre"'\)"[[:space:]]*\(,.*\|\\\|\)$'
49
50 sed -n -e "${match}s/${search}/\1/p" $RULES_FILE
51}
52
53write_rule() {
54 local match="$1"
55 local link="$2"
56 local comment="$3"
57
58 [ -e "$RULES_FILE" ] || PRINT_HEADER=1
59 {
60 if [ "$PRINT_HEADER" ]; then
61 PRINT_HEADER=
62 echo "# This file was automatically generated by the $0"
63 echo "# program, probably run by the 83-cdrom.rules rules file."
64 echo "#"
65 echo "# You can modify it, as long as you keep each rule on a single line"
66 echo "# and set the \$GENERATED variable."
67 echo ""
68 fi
69
70 [ "$comment" ] && echo "# $comment"
71 echo "ACTION==\"add\", SUBSYSTEM==\"block\", $match, ENV{ID_CDROM}==\"1\", SYMLINK+=\"$link\", ENV{GENERATED}=\"1\""
72 } >> $RULES_FILE
73 SYMLINKS="$SYMLINKS $link"
74}
75
76##############################################################################
77if [ -z "$DEVPATH" ]; then
78 echo "Missing \$DEVPATH." >&2
79 exit 1
80fi
81if [ -z "$ID_CDROM" ]; then
82 echo "$DEVPATH is not a CD reader." >&2
83 exit 1
84fi
85
86# Prevent parallel processes from modifying the file at the same time.
87lock_rules_file
88
89link_num=$(find_next_available 'cdrom[0-9]*')
90
91#match="ENV{ID_PATH}==\"$ID_PATH\""
92
93#kernel=${DEVPATH##*/}
94#match="KERNEL==\"$kernel\""
95
96id=${PHYSDEVPATH##*/}
97match="BUS==\"$PHYSDEVBUS\", ID==\"$id\""
98
99comment="$ID_MODEL ($ID_PATH)"
100
101 write_rule "$match" "cdrom$link_num" "$comment"
102[ "$ID_CDROM_CD_RW" ] && write_rule "$match" "cdrw$link_num"
103[ "$ID_CDROM_DVD" ] && write_rule "$match" "dvd$link_num"
104[ "$ID_CDROM_DVD_RW" ] && write_rule "$match" "dvdrw$link_num"
105
106unlock_rules_file
107
108echo $SYMLINKS
109
110exit 0
111
Note: See TracBrowser for help on using the repository browser.