Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
VDEV_MOUNTPOINT="/dev"
guess_subsystem() {
local devtype=$1
local devname=$2
if [ "$devname" = "snd/seq" ]; then
echo "sound"
fi
}
feed_static_nodes_kmod() {
[ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
[ -x /bin/kmod ] || return 0
/bin/kmod static-nodes --format=tmpfiles --output=/proc/self/fd/1 | \
while read type name mode uid gid age arg; do
# strip /dev/ from $name
name=${name#/dev/}
echo "name=$name"
# strip bang from $type
type=${type%%\!}
echo "type=$type"
# [ -e "$VDEV_MOUNTPOINT/$name" ] && { echo "exists in dev"; continue; }
# skip directories--vdevd can make them
if [ "$type" = "d" ]; then
echo "type is d directory"
continue
fi
# only process character and block devices
if [ "$type" != "c" -a "$type" != "b" ]; then
echo "Invalid device type $type" >/proc/self/fd/2
continue
fi
# look up major/minor
major=$(echo $arg | /bin/sed 's/^\([^:]\+\):.*/\1/g')
minor=$(echo $arg | /bin/sed 's/^[^:]\+:\(.*\)/\1/g')
echo "major=$major"
echo "minor=$minor"
# look up devpath and subsystem
sys_link=
devpath=
params=
case "$type" in
"c")
sys_link="/sys/dev/char/$major:$minor"
;;
"b")
sys_link="/sys/dev/block/$major:$minor"
;;
esac
echo "syslink=$sys_link"
# is there a sysfs entry for this device? there might not be...
if ! [ -L $sys_link ]; then
subsystem=$(guess_subsystem $type $name)
else
devpath=$(/bin/readlink "$sys_link" | /bin/sed 's/\.\.\///g')
devpath="/$devpath"
echo "devpath=$devpath"
subsystem=$(/bin/readlink "/sys/$devpath/subsystem" | /bin/sed "s/[^/]*\///g")
fi
echo "subsystem=$subsystem"
# build up params list
if [ -n "$devpath" ]; then
params="$params DEVPATH=$devpath"
fi
if [ -n "$subsystem" ]; then
params="$params SUBSYSTEM=$subsystem"
fi
#name="$(echo $name | sed 's/\//_/')"
# feed into vdevd via stdout
echo "$type $name $major $minor $params"
# keep SELinux happy
if [ -x /sbin/restorecon ]; then
/sbin/restorecon "$VDEV_MOUNTPOINT/$name"
fi
done
}
feed_static_nodes_kmod_obarun() {
[ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
[ -x /bin/kmod ] || return 0
kmod=$(kmod static-nodes --format=devname --output=/proc/self/fd/1 | tr " " ".")
for strip in $kmod; do
uid="" #need or not?
gid="" #need or not?
mode="" #need or not?
age="" #need or not?
arg="" #need or not?
name=$(echo ${strip} | awk -F "." '{print $1}')
type=$(echo ${strip} | awk -F "." '{print $3}' | cut -c1)
echo
echo
echo "name=$name"
echo "type=$type"
# [ -e "$VDEV_MOUNTPOINT/$name" ] && continue
#not needed anymore due of the output format
#if [ "$type" = "d" ]; then
# continue
#fi
# only process character and block devices
if [ "$type" != "c" -a "$type" != "b" ]; then
echo "Invalid device type $type" >/proc/self/fd/2
continue
fi
# look up major/minor
major=$(echo ${strip} | awk -F "." '{print $3}' | awk -F"[a-z]*:" '{print $1}' | sed 's/[a-z]//g')
minor=$(echo ${strip} | awk -F "." '{print $3}' | awk -F"[0-9]*:" '{print $2}')
echo "major=$major"
echo "minor=$minor"
# look up devpath and subsystem
sys_link=
devpath=
params=
case "$type" in
"c")
sys_link="/sys/dev/char/$major:$minor"
;;
"b")
sys_link="/sys/dev/block/$major:$minor"
;;
esac
echo "sys_link=$sys_link"
# is there a sysfs entry for this device? there might not be...
if ! [ -L $sys_link ]; then
echo guess_subsystem $type $name
subsystem=$(guess_subsystem $type $name)
else
devpath=$(/bin/readlink "$sys_link" | /bin/sed 's/\.\.\///g')
devpath="/$devpath"
echo "devpath=$devpath"
subsystem=$(/bin/readlink "/sys/$devpath/subsystem" | /bin/sed "s/[^/]*\///g")
fi
echo "subsystem=$subsystem"
# build up params list
if [ -n "$devpath" ]; then
params="$params DEVPATH=$devpath"
fi
if [ -n "$subsystem" ]; then
params="$params SUBSYSTEM=$subsystem"
fi
# feed into vdevd via stdout
echo "$type $name $major $minor $params"
# keep SELinux happy
if [ -x /sbin/restorecon ]; then
/sbin/restorecon "$VDEV_MOUNTPOINT/$name"
fi
#finaly load the modules
#modprobe -b -q -- "$name"
#unset variable
unset s
done
}
feed_static_nodes_kmod_scooby() {
[ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
[ -x /bin/kmod ] || return 0
/bin/kmod static-nodes --format=devname --output=/proc/self/fd/1 | \
while read name path arg; do
echo "name=$name"
# strip major:minor from $arg
type=${arg:0:1}
echo "type=$type"
# [ -e "$VDEV_MOUNTPOINT/$name" ] && { echo "exists in dev"; continue; }
# only process character and block devices
if [ "$type" != "c" -a "$type" != "b" ]; then
echo "Invalid device type $type" >/proc/self/fd/2
continue
fi
# look up major/minor
major=$(echo ${arg:1} | /bin/sed 's/^\([^:]\+\):.*/\1/g')
minor=$(echo ${arg:1} | /bin/sed 's/^[^:]\+:\(.*\)/\1/g')
echo "major=$major"
echo "minor=$minor"
# look up devpath and subsystem
sys_link=
devpath=
params=
case "$type" in
"c")
sys_link="/sys/dev/char/$major:$minor"
;;
"b")
sys_link="/sys/dev/block/$major:$minor"
;;
esac
echo "syslink=$sys_link"
# is there a sysfs entry for this device? there might not be...
if ! [ -L $sys_link ]; then
subsystem=$(guess_subsystem $type $path)
else
devpath=$(/bin/readlink "$sys_link" | /bin/sed 's/\.\.\///g')
devpath="/$devpath"
echo "devpath=$devpath"
subsystem=$(/bin/readlink "/sys/$devpath/subsystem" | /bin/sed "s/[^/]*\///g")
fi
echo "subsystem=$subsystem"
# build up params list
if [ -n "$devpath" ]; then
params="$params DEVPATH=$devpath"
fi
if [ -n "$subsystem" ]; then
params="$params SUBSYSTEM=$subsystem"
fi
# feed into vdevd via stdout
echo "$type $name $major $minor $params"
# keep SELinux happy
if [ -x /sbin/restorecon ]; then
/sbin/restorecon "$VDEV_MOUNTPOINT/$name"
fi
done
}
echo "JCNELSON"
echo
feed_static_nodes_kmod
echo
echo
echo
echo "OBARUN"
echo
feed_static_nodes_kmod_obarun
echo
echo
echo
echo "Scooby"
echo
feed_static_nodes_kmod_scooby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment