source: udev-lfs/contrib/debian/write_cd_aliases@ 2e70df0

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.4 7.5 7.6 7.7 7.8 7.9 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 2e70df0 was 14377f4, checked in by Bruce Dubbs <bdubbs@…>, 12 years ago

Update LFS target architectures.
Fix a url in pkgmgfor LFS.
Tweak a debian udev script for LFS.

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

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