From 2154628f87e25c3ec28e7f7e7d98b405166a0c4e Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Tue, 18 Dec 2012 18:58:25 -0600
Subject: linhes-udev-rules:  This pkg contains the rules that are custom to
 linhes  or once were in arch  but removed. Only the CD_DVD_symlinks rule has
 been tested

refs #884
---
 .../75-cd-aliases-generator.rules                  |  33 ++++++
 .../linhes-udev-rules/81-CD_DVD_symlinks.rules     |  23 ++++
 abs/core/linhes-udev-rules/81-OSS_Emulation.rules  |   6 +
 abs/core/linhes-udev-rules/81-SoundGraph.rules     |   3 +
 abs/core/linhes-udev-rules/81-SoundGraph_LCD.rules |   2 +
 abs/core/linhes-udev-rules/81-arch.rules           |  83 +++++++++++++
 abs/core/linhes-udev-rules/81-dvicoIR.rules        |  18 +++
 abs/core/linhes-udev-rules/PKGBUILD                |  52 +++++++++
 abs/core/linhes-udev-rules/__changelog             |  23 ++++
 abs/core/linhes-udev-rules/cdsymlinks.sh           |  44 +++++++
 .../linhes-udev-rules/rule_generator.functions     | 116 +++++++++++++++++++
 abs/core/linhes-udev-rules/write_cd_rules          | 128 +++++++++++++++++++++
 12 files changed, 531 insertions(+)
 create mode 100644 abs/core/linhes-udev-rules/75-cd-aliases-generator.rules
 create mode 100644 abs/core/linhes-udev-rules/81-CD_DVD_symlinks.rules
 create mode 100644 abs/core/linhes-udev-rules/81-OSS_Emulation.rules
 create mode 100644 abs/core/linhes-udev-rules/81-SoundGraph.rules
 create mode 100644 abs/core/linhes-udev-rules/81-SoundGraph_LCD.rules
 create mode 100644 abs/core/linhes-udev-rules/81-arch.rules
 create mode 100644 abs/core/linhes-udev-rules/81-dvicoIR.rules
 create mode 100644 abs/core/linhes-udev-rules/PKGBUILD
 create mode 100644 abs/core/linhes-udev-rules/__changelog
 create mode 100755 abs/core/linhes-udev-rules/cdsymlinks.sh
 create mode 100644 abs/core/linhes-udev-rules/rule_generator.functions
 create mode 100755 abs/core/linhes-udev-rules/write_cd_rules

diff --git a/abs/core/linhes-udev-rules/75-cd-aliases-generator.rules b/abs/core/linhes-udev-rules/75-cd-aliases-generator.rules
new file mode 100644
index 0000000..ee9b0c9
--- /dev/null
+++ b/abs/core/linhes-udev-rules/75-cd-aliases-generator.rules
@@ -0,0 +1,33 @@
+# Udev rules for creating CD/DVD symlinks
+# do not edit this file, it will be overwritten on update
+
+
+#####################################
+###### CD/DVD symlinks - begin
+#####################################
+ACTION=="add|change", SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", IMPORT="cdrom_id --export $tempnode"
+ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="sr[0-9]*", IMPORT="cdrom_id --export $tempnode"
+ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="scd[a-z]", IMPORT="cdrom_id --export $tempnode"
+ENV{ID_CDROM}=="?*", SYMLINK+="cd/cdrom-%b"
+ENV{ID_CDROM_CD_RW}=="?*", SYMLINK+="cd/cdrw-%b"
+ENV{ID_CDROM_DVD}=="?*", SYMLINK+="cd/dvd-%b"
+ENV{ID_CDROM_DVD_R}=="?*", SYMLINK+="cd/dvdrw-%b"
+
+#ACTION=="add|change", SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", ATTR{removable}=="1", ATTRS{media}=="cdrom*", ENV{GENERATED}!="?*", RUN+="write_cd_rules" , SYMLINK+="%c"
+#ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="sr[0-9]*", ATTRS{type}=="5", RUN+="write_cd_rules"
+#ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="sg[0-9]*", ATTRS{type}=="5", RUN+="write_cd_rules"
+
+ACTION=="add|change", SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", ATTR{removable}=="1", ATTRS{media}=="cdrom*", ENV{GENERATED}!="?*", RUN+="write_cd_rules" , SYMLINK+="%c"
+ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="sr[0-9]*", ATTRS{type}=="5", ENV{ID_CDROM}=="?*", ENV{GENERATED}!="?*", PROGRAM="write_cd_rules", SYMLINK+="%c"
+ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="sg[0-9]*", ATTRS{type}=="5", ENV{GENERATED}!="?*",SYMLINK+="%c" RUN+="write_cd_rules"
+
+#ACTION=="add", SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{GENERATED}!="?*", PROGRAM="write_cd_rules", SYMLINK+="%c"
+
+
+
+#ACTION=="remove", SUBSYSTEMS=="block", KERNEL=="hd[a-z]", RUN+="write_cd_rules by-id"
+#ACTION=="remove", SUBSYSTEMS=="block", KERNEL=="sr[0-9]*", RUN+="write_cd_rules by-id"
+#ACTION=="remove", SUBSYSTEMS=="block", KERNEL=="sg[0-9]*", RUN+="write_cd_rules by-id"
+#####################################
+###### CD/DVD symlinks - end
+#####################################
diff --git a/abs/core/linhes-udev-rules/81-CD_DVD_symlinks.rules b/abs/core/linhes-udev-rules/81-CD_DVD_symlinks.rules
new file mode 100644
index 0000000..6d278ac
--- /dev/null
+++ b/abs/core/linhes-udev-rules/81-CD_DVD_symlinks.rules
@@ -0,0 +1,23 @@
+# Udev rules for creating CD/DVD symlinks
+# do not edit this file, it will be overwritten on update
+
+
+#####################################
+###### CD/DVD symlinks - begin
+#####################################
+ACTION=="add|change", SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", IMPORT="cdrom_id --export $tempnode"
+ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="sr[0-9]*", IMPORT="cdrom_id --export $tempnode"
+ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="scd[a-z]", IMPORT="cdrom_id --export $tempnode"
+ENV{ID_CDROM}=="?*", SYMLINK+="cd/cdrom-%b"
+ENV{ID_CDROM_CD_RW}=="?*", SYMLINK+="cd/cdrw-%b"
+ENV{ID_CDROM_DVD}=="?*", SYMLINK+="cd/dvd-%b"
+ENV{ID_CDROM_DVD_R}=="?*", SYMLINK+="cd/dvdrw-%b"
+ACTION=="add|change", SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", ATTR{removable}=="1", ATTRS{media}=="cdrom*", RUN+="cdsymlinks.sh"
+ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="sr[0-9]*", ATTRS{type}=="5", RUN+="cdsymlinks.sh"
+ACTION=="add|change", SUBSYSTEMS=="scsi", KERNEL=="sg[0-9]*", ATTRS{type}=="5", RUN+="cdsymlinks.sh"
+ACTION=="remove", SUBSYSTEMS=="block", KERNEL=="hd[a-z]", RUN+="cdsymlinks.sh"
+ACTION=="remove", SUBSYSTEMS=="block", KERNEL=="sr[0-9]*", RUN+="cdsymlinks.sh"
+ACTION=="remove", SUBSYSTEMS=="block", KERNEL=="sg[0-9]*", RUN+="cdsymlinks.sh"
+#####################################
+###### CD/DVD symlinks - end
+#####################################
diff --git a/abs/core/linhes-udev-rules/81-OSS_Emulation.rules b/abs/core/linhes-udev-rules/81-OSS_Emulation.rules
new file mode 100644
index 0000000..373537e
--- /dev/null
+++ b/abs/core/linhes-udev-rules/81-OSS_Emulation.rules
@@ -0,0 +1,6 @@
+# Udev rules for OSS Emulation
+# do not edit this file, it will be overwritten on update
+
+# OSS Emulation SOUND addon modules
+SUBSYSTEM=="sound", RUN+="/sbin/modprobe snd-pcm-oss"
+SUBSYSTEM=="sound", RUN+="/sbin/modprobe snd-seq-oss"
diff --git a/abs/core/linhes-udev-rules/81-SoundGraph.rules b/abs/core/linhes-udev-rules/81-SoundGraph.rules
new file mode 100644
index 0000000..f3f5c84
--- /dev/null
+++ b/abs/core/linhes-udev-rules/81-SoundGraph.rules
@@ -0,0 +1,3 @@
+# Udev rules for SoundGraph receivers
+KERNEL=="event[0-9]*" , SUBSYSTEMS=="rc" , ENV(.rc_in_path)="true" 
+KERNEL=="event[0-9]*" , ATTRS{idVendor}=="15c2" , ENV(.rc_in_path)=="true" , SYMLINK+="remotes/SoundGraph"
diff --git a/abs/core/linhes-udev-rules/81-SoundGraph_LCD.rules b/abs/core/linhes-udev-rules/81-SoundGraph_LCD.rules
new file mode 100644
index 0000000..59f0eec
--- /dev/null
+++ b/abs/core/linhes-udev-rules/81-SoundGraph_LCD.rules
@@ -0,0 +1,2 @@
+# Udev rules for SoundGraph LCDs
+KERNEL=="lcd[0-9]*" , ATTRS{idVendor}=="15c2" , SYMLINK+="lcd"
diff --git a/abs/core/linhes-udev-rules/81-arch.rules b/abs/core/linhes-udev-rules/81-arch.rules
new file mode 100644
index 0000000..cd4e3e9
--- /dev/null
+++ b/abs/core/linhes-udev-rules/81-arch.rules
@@ -0,0 +1,83 @@
+# Udev rules for Archlinux by Tobias Powalowski <tpowa@archlinux.org>
+# do not edit this file, it will be overwritten on update
+#
+# There are a number of modifiers that are allowed to be used in some
+# of the different fields. They provide the following subsitutions:
+#
+# %n the "kernel number" of the device.
+#    For example, 'sda3' has a "kernel number" of '3'
+# %k the kernel name for the device.
+# %M the kernel major number for the device
+# %m the kernel minor number for the device
+# %b the bus id for the device
+# %c the string returned by the PROGRAM
+# %s{filename} the content of a sysfs attribute.
+# %% the '%' char itself.
+#
+# There are a number of modifiers that are allowed to be used in some of the
+# fields.  See the udev man page for a full description of them.
+# global stuff
+#
+
+# permission for sg devices
+KERNEL=="sg[0-9]*", ATTRS{type}!="3|6", GROUP="disk", MODE="0660"
+
+# permissions for IDE CD devices
+SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", ATTR{removable}=="1", ATTRS{media}=="cdrom*", GROUP="optical"
+
+# permissions for SCSI CD devices
+SUBSYSTEMS=="scsi", KERNEL=="sr[0-9]*", ATTRS{type}=="5", SYMLINK+="scd%n", GROUP="optical"
+SUBSYSTEMS=="scsi", KERNEL=="sg[0-9]*", ATTRS{type}=="5", GROUP="optical"
+
+# permissions for removable devices like cardreaders or sticks
+KERNEL=="sd*", ATTRS{scsi_level}=="3", ATTRS{type}=="0", GROUP="storage"
+
+# permissions for firewire external drives
+KERNEL=="sd*", ATTRS{scsi_level}=="5", GROUP="storage"
+
+# permissions for usb to scsi external adapters
+KERNEL=="sd*", ATTRS{scsi_level}=="3", ATTRS{type}=="7", GROUP="storage"
+
+# permissions for ide storage like pcmcia card readers
+ACTION!="add", GOTO="pcmcia_end"
+SUBSYSTEM!="block", GOTO="pcmcia_end"
+KERNEL=="hd*[!0-9]", IMPORT{program}="ata_id --export $tempnode"
+KERNEL=="hd*", IMPORT{parent}=="ID_*"
+KERNEL=="hd*", ENV{ID_TYPE}=="generic", GROUP="storage"
+LABEL="pcmcia_end"
+
+# permissions for SCSI scanners
+SUBSYSTEMS=="scsi", KERNEL=="sg[0-9]*", ATTRS{type}=="6", GROUP="scanner"
+
+# mem
+KERNEL=="ram0", SYMLINK+="ramdisk"
+KERNEL=="ram1", SYMLINK+="ram"
+
+# video4linux
+
+KERNEL=="vbi0",		SYMLINK+="vbi"
+KERNEL=="radio0",	SYMLINK+="radio"
+KERNEL=="radio[0-9]*",	GROUP="video"
+KERNEL=="video0",	SYMLINK+="video"
+KERNEL=="vtx0",		SYMLINK+="vtx"
+
+# video devices
+### xorg resets those permissions, adjust your xorg.conf!
+KERNEL=="3dfx*",	GROUP="video"
+KERNEL=="fb[0-9]*",	GROUP="video"
+
+# misc
+KERNEL=="sgi_fetchop",	MODE="0666"
+KERNEL=="sonypi",	MODE="0666"
+
+# USB devices
+KERNEL=="legousbtower*", MODE="0666"
+
+# kbd devices
+KERNEL=="kbd", MODE="0664"
+
+# miscellaneous
+KERNEL=="rtc|rtc0", GROUP="audio", MODE="0664"
+#######################################
+# Permissions and Symlinks - end
+#######################################
diff --git a/abs/core/linhes-udev-rules/81-dvicoIR.rules b/abs/core/linhes-udev-rules/81-dvicoIR.rules
new file mode 100644
index 0000000..8669f34
--- /dev/null
+++ b/abs/core/linhes-udev-rules/81-dvicoIR.rules
@@ -0,0 +1,18 @@
+# Udev rules for Dvico remotes
+# do not edit this file, it will be overwritten on update
+
+# This rule is for the Dvico Dual Digital 4 Rev 2. It has 2 IR modules 
+# identified, only the first of which is connected to the receiver.
+# The KERNELS=="*-1" part of this rule makes sure that the first 
+# device is the one that gets the symlink.
+KERNEL=="event*", \
+    KERNELS=="*-1", \
+    ATTRS{manufacturer}=="Dvico", \
+    ATTRS{idVendor}=="0fe9", \
+    ATTRS{idProduct}=="db98", \
+    SYMLINK="remotes/dvicoDualDigital4"
+
+# This rule is for the older style USB DVICO remote dongles.
+SUBSYSTEMS=="usb", KERNEL=="hiddev*", \
+    ATTRS{product}=="DVICO USB HID Remocon V1.00", \
+    SYMLINK+="remotes/dvicoIR"
diff --git a/abs/core/linhes-udev-rules/PKGBUILD b/abs/core/linhes-udev-rules/PKGBUILD
new file mode 100644
index 0000000..3b87ae1
--- /dev/null
+++ b/abs/core/linhes-udev-rules/PKGBUILD
@@ -0,0 +1,52 @@
+pkgname="linhes-udev-rules"
+pkgver=8
+pkgrel=1
+arch=(i686 x86_64)
+license=('GPL')
+groups=('base')
+# older initscripts versions required start_udev
+options=(!makeflags !libtool)
+makedepends=()
+source=(
+    81-CD_DVD_symlinks.rules
+	81-OSS_Emulation.rules
+	81-dvicoIR.rules
+	81-SoundGraph_LCD.rules
+	81-SoundGraph.rules
+    cdsymlinks.sh)
+    #75-cd-aliases-generator.rules
+    #rule_generator.functions
+    #write_cd_rules)
+
+
+build() {
+  cd $srcdir
+  # Install our rule for permissions and symlinks
+  #install -D -m644 $srcdir/81-arch.rules $pkgdir/lib/udev/rules.d/81-arch.rules
+
+  # Install OSS Emulation rules
+  install -D -m644 $srcdir/81-OSS_Emulation.rules $pkgdir/lib/udev/rules.d/81-OSS_Emulation.rules
+  # Install dvicoIR rules
+  install -D -m644 $srcdir/81-dvicoIR.rules $pkgdir/lib/udev/rules.d/81-dvicoIR.rules
+  # Install CD/DVD symlink rules
+  install -D -m644 $srcdir/81-CD_DVD_symlinks.rules  $pkgdir/lib/udev/rules.d/81-CD_DVD_symlinks.rules
+  #install -D -m644 $srcdir/75-cd-aliases-generator.rules $pkgdir/lib/udev/rules.d/75-cd-aliases-generator.rules
+  # Install SoundGraph LCD rules
+  install -D -m644 $srcdir/81-SoundGraph_LCD.rules $pkgdir/lib/udev/rules.d/81-SoundGraph_LCD.rules
+  # Install SoundGraph rules
+  install -D -m644 $srcdir/81-SoundGraph.rules $pkgdir/lib/udev/rules.d/81-SoundGraph.rules
+  # install cdsymlinks.sh
+  install -D -m755 $srcdir/cdsymlinks.sh $pkgdir/lib/udev/cdsymlinks.sh
+
+ #taken from suse
+  #install -D -m755 $srcdir/write_cd_rules $pkgdir/lib/udev/write_cd_rules
+  #install -D -m755 $srcdir/rule_generator.functions $pkgdir/lib/udev/rule_generator.functions
+
+}
+
+md5sums=('48845542d8250d6f2eddf07944f78014'
+         '18170020347b181b155ff5a1a8a904b4'
+         '85798a6599d4b24b68600c5f1d1f223b'
+         '5401def23fae53db3c94e39eb2debfb4'
+         '01eeeb532e1c82a12905c67814c1dde2'
+         '2e808ee78d237c478b57af2a68d43769')
diff --git a/abs/core/linhes-udev-rules/__changelog b/abs/core/linhes-udev-rules/__changelog
new file mode 100644
index 0000000..574222c
--- /dev/null
+++ b/abs/core/linhes-udev-rules/__changelog
@@ -0,0 +1,23 @@
+7/10/11 Britney Fransen
+- Added changelog
+- Added 81-LinHES.rules
+- Added 81-LinHES.rules to PKGBUILD
+
+8/9/11 Britney Fransen
+- Add cdsymlinks.sh to PKGBUILD
+
+1/24/2012
+- Renamed changelog to __changelog
+- Added 81-dvicoIR.rules
+- Moved OSS Emulation rules from 81-LinHES.rules to 81-OSS_Emulation.rules
+- Moved CD/DVD rules from 81-LinHES.rules to 81-CD_DVD_symlinks.rules
+- Removed 81-LinHES.rules
+
+3/1/2012
+- Added 81-SoundGraph_LCD.rules
+
+3/5/2012
+- Added 81-SoundGraph.rules
+
+12/17/2012 -jm
+  Removed all udev bits and kept only the rules. 
diff --git a/abs/core/linhes-udev-rules/cdsymlinks.sh b/abs/core/linhes-udev-rules/cdsymlinks.sh
new file mode 100755
index 0000000..498abda
--- /dev/null
+++ b/abs/core/linhes-udev-rules/cdsymlinks.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Creates cdsymlinks in /dev
+# for Archlinux by Tobias Powalowski <tpowa@archlinux.org>
+
+# check on cd/dvd drives and if persistant rules file is used
+if [ -d /dev/cd -a ! -e /etc/udev/rules.d/75-persistent-cd.rules ]; then
+	# remove existing device files
+	rm /dev/cdrom*
+	rm /dev/cdrw*
+	rm /dev/dvd*
+	rm /dev/dvdrw*
+	# start creating symlinks
+	for i in /dev/cd/cdrom-*; do
+		if [ -h $i ]; then
+		[ "$CD_NUMBER" = "" ] && ln -s $i /dev/cdrom
+		[ "$CD_NUMBER" = "" ] && CD_NUMBER="-1"
+		! [ "$CD_NUMBER" = "" ] && CD_NUMBER="$((CD_NUMBER+1))" && ln -s $i /dev/cdrom$CD_NUMBER
+		fi
+	done
+	
+	for i in /dev/cd/cdrw-*; do
+		if [ -h $i ]; then
+		[ "$CDRW_NUMBER" = "" ] && ln -s $i /dev/cdrw
+		[ "$CDRW_NUMBER" = "" ] && CDRW_NUMBER="-1"
+		! [ "$CDRW_NUMBER" = "" ] && CDRW_NUMBER="$((CDRW_NUMBER+1))" && ln -s $i /dev/cdrw$CDRW_NUMBER
+		fi
+	done
+
+	for i in /dev/cd/dvd-*; do
+		if [ -h $i ]; then
+		[ "$DVD_NUMBER" = "" ] && ln -s $i /dev/dvd
+		[ "$DVD_NUMBER" = "" ] && DVD_NUMBER="-1"
+		! [ "$DVD_NUMBER" = "" ] && DVD_NUMBER="$((DVD_NUMBER+1))" && ln -s $i /dev/dvd$DVD_NUMBER
+		fi
+	done
+
+	for i in /dev/cd/dvdrw-*; do
+		if [ -h $i ]; then
+		[ "$DVDRW_NUMBER" = "" ] && ln -s $i /dev/dvdrw
+		[ "$DVDRW_NUMBER" = "" ] && DVDRW_NUMBER="-1"
+		! [ "$DVDRW_NUMBER" = "" ] && DVDRW_NUMBER="$((DVDRW_NUMBER+1))" && ln -s $i /dev/dvdrw$DVDRW_NUMBER
+		fi
+	done
+fi
diff --git a/abs/core/linhes-udev-rules/rule_generator.functions b/abs/core/linhes-udev-rules/rule_generator.functions
new file mode 100644
index 0000000..ef948bd
--- /dev/null
+++ b/abs/core/linhes-udev-rules/rule_generator.functions
@@ -0,0 +1,116 @@
+# functions used by the udev rule generator
+
+# Copyright (C) 2006 Marco d'Itri <md@Linux.IT>
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+PATH='/sbin:/bin'
+#
+
+PATH='/sbin:/bin'
+
+# Read a single line from file $1 in the $DEVPATH directory.
+# The function must not return an error even if the file does not exist.
+sysread() {
+	local file="$1"
+	[ -e "/sys$DEVPATH/$file" ] || return 0
+	local value
+	read value < "/sys$DEVPATH/$file" || return 0
+	echo "$value"
+}
+
+sysreadlink() {
+	local file="$1"
+	[ -e "/sys$DEVPATH/$file" ] || return 0
+	readlink -f /sys$DEVPATH/$file 2> /dev/null || true
+}
+
+# Return true if a directory is writeable.
+writeable() {
+	if ln -s test-link $1/.is-writeable 2> /dev/null; then
+		rm -f $1/.is-writeable
+		return 0
+	else
+		return 1
+	fi
+}
+
+# Create a lock file for the current rules file.
+lock_rules_file() {
+	RUNDIR="/run/udev"
+	[ -e "$RUNDIR" ] || return 0
+
+	RULES_LOCK="$RUNDIR/.lock-${RULES_FILE##*/}"
+
+	retry=30
+	while ! mkdir $RULES_LOCK 2> /dev/null; do
+		if [ $retry -eq 0 ]; then
+			 echo "Cannot lock $RULES_FILE!" >&2
+			 exit 2
+		fi
+		sleep 1
+		retry=$(($retry - 1))
+	done
+}
+
+unlock_rules_file() {
+	[ "$RULES_LOCK" ] || return 0
+	rmdir $RULES_LOCK || true
+}
+
+# Choose the real rules file if it is writeable or a temporary file if not.
+# Both files should be checked later when looking for existing rules.
+choose_rules_file() {
+	RUNDIR="/run/udev"
+	local tmp_rules_file="$RUNDIR/tmp-rules--${RULES_FILE##*/}"
+	[ -e "$RULES_FILE" -o -e "$tmp_rules_file" ] || PRINT_HEADER=1
+
+	if writeable ${RULES_FILE%/*}; then
+		RO_RULES_FILE='/dev/null'
+	else
+		RO_RULES_FILE=$RULES_FILE
+		RULES_FILE=$tmp_rules_file
+	fi
+}
+
+# Return the name of the first free device.
+raw_find_next_available() {
+	local links="$1"
+
+	local basename=${links%%[ 0-9]*}
+	local max=-1
+	for name in $links; do
+		local num=${name#$basename}
+		[ "$num" ] || num=0
+		[ $num -gt $max ] && max=$num
+	done
+
+	local max=$(($max + 1))
+	# "name0" actually is just "name"
+	[ $max -eq 0 ] && return
+	echo "$max"
+}
+
+# Find all rules matching a key (with action) and a pattern.
+find_all_rules() {
+	local key="$1"
+	local linkre="$2"
+	local match="$3"
+
+	local search='.*[[:space:],]'"$key"'"('"$linkre"')".*'
+	echo $(sed -n -r -e 's/^#.*//' -e "${match}s/${search}/\1/p" \
+		$RO_RULES_FILE \
+		$([ -e $RULES_FILE ] && echo $RULES_FILE) \
+		2>/dev/null)
+}
diff --git a/abs/core/linhes-udev-rules/write_cd_rules b/abs/core/linhes-udev-rules/write_cd_rules
new file mode 100755
index 0000000..5377c74
--- /dev/null
+++ b/abs/core/linhes-udev-rules/write_cd_rules
@@ -0,0 +1,128 @@
+#!/bin/sh -e
+echo "out" >> /tmp/a.a.a
+set -x
+# This script is run if an optical drive lacks a rule for persistent naming.
+#
+# It adds symlinks for optical drives based on the device class determined
+# by cdrom_id and used ID_PATH to identify the device.
+
+# (C) 2006 Marco d'Itri <md@Linux.IT>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# debug, if UDEV_LOG=<debug>
+if [ -n "$UDEV_LOG" ]; then
+	if [ "$UDEV_LOG" -ge 7 ]; then
+		set -x
+	fi
+fi
+
+RULES_FILE="/etc/udev/rules.d/70-persistent-cd.rules"
+
+. /lib/udev/rule_generator.functions
+
+find_next_available() {
+	raw_find_next_available "$(find_all_rules 'SYMLINK\+=' "$1")"
+}
+
+write_rule() {
+	local match="$1"
+	local link="$2"
+	local comment="$3"
+
+	{
+	if [ "$PRINT_HEADER" ]; then
+		PRINT_HEADER=
+		echo "# This file was automatically generated by the $0"
+		echo "# program, run by the cd-aliases-generator.rules rules file."
+		echo "#"
+		echo "# You can modify it, as long as you keep each rule on a single"
+		echo "# line, and set the \$GENERATED variable."
+		echo ""
+	fi
+
+	[ "$comment" ] && echo "# $comment"
+	echo "$match, SYMLINK+=\"$link\", ENV{GENERATED}=\"1\""
+	} >> $RULES_FILE
+	SYMLINKS="$SYMLINKS $link"
+}
+
+if [ -z "$DEVPATH" ]; then
+	echo "Missing \$DEVPATH." >&2
+	exit 1
+fi
+if [ -z "$ID_CDROM" ]; then
+	echo "$DEVPATH is not a CD reader." >&2
+	exit 1
+fi
+
+if [ "$1" ]; then
+	METHOD="$1"
+else
+	METHOD='by-path'
+fi
+
+case "$METHOD" in
+	by-path)
+	if [ -z "$ID_PATH" ]; then
+		echo "$DEVPATH not supported by path_id. by-id may work." >&2
+		exit 1
+	fi
+	RULE="ENV{ID_PATH}==\"$ID_PATH\""
+	;;
+
+	by-id)
+	if [ "$ID_SERIAL" ]; then
+		RULE="ENV{ID_SERIAL}==\"$ID_SERIAL\""
+	elif [ "$ID_MODEL" -a "$ID_REVISION" ]; then
+		RULE="ENV{ID_MODEL}==\"$ID_MODEL\", ENV{ID_REVISION}==\"$ID_REVISION\""
+	else
+		echo "$DEVPATH not supported by ata_id. by-path may work." >&2
+		exit 1
+	fi
+	;;
+
+	*)
+	echo "Invalid argument (must be either by-path or by-id)." >&2
+	exit 1
+	;;
+esac
+
+# Prevent concurrent processes from modifying the file at the same time.
+lock_rules_file
+
+# Check if the rules file is writeable.
+choose_rules_file
+
+link_num=$(find_next_available 'cdrom[0-9]*')
+
+match="SUBSYSTEM==\"block\", ENV{ID_CDROM}==\"?*\", $RULE"
+
+comment="$ID_MODEL ($ID_PATH)"
+
+	write_rule "$match" "cdrom$link_num" "$comment"
+[ "$ID_CDROM_CD_R" -o "$ID_CDROM_CD_RW" ] && \
+	write_rule "$match" "cdrw$link_num"
+[ "$ID_CDROM_DVD" ] && \
+	write_rule "$match" "dvd$link_num"
+[ "$ID_CDROM_DVD_R" -o "$ID_CDROM_DVD_RW" -o "$ID_CDROM_DVD_RAM" ] && \
+	write_rule "$match" "dvdrw$link_num"
+echo >> $RULES_FILE
+
+unlock_rules_file
+
+echo $SYMLINKS
+
+exit 0
+
-- 
cgit v0.12