Overlay/x11-drivers/displaylink-driver/files/udev.sh

96 lines
1.7 KiB
Bash
Raw Normal View History

#!/bin/sh
# Copyright (c) 2016 - 2020 DisplayLink (UK) Ltd.
# File autogenerated by udev-installer.sh script
get_displaylink_dev_count()
{
cat /sys/bus/usb/devices/*/idVendor | grep 17e9 | wc -l
}
get_displaylink_symlink_count()
{
root=$1
if [ ! -d "$root/displaylink/by-id" ]; then
echo "0"
return
fi
for f in $(find $root/displaylink/by-id -type l -exec realpath {} \; 2> /dev/null); do
test -c $f && echo $f;
done | wc -l
}
start_displaylink()
{
if [ "$(get_displaylink_dev_count)" != "0" ]; then
start_service
fi
}
stop_displaylink()
{
root=$1
if [ "$(get_displaylink_symlink_count $root)" = "0" ]; then
stop_service
fi
}
remove_dldir_if_empty()
{
root=$1
(cd $root; rmdir -p --ignore-fail-on-non-empty displaylink/by-id)
}
create_displaylink_symlink()
{
root=$1
device_id=$2
devnode=$3
mkdir -p $root/displaylink/by-id
ln -sf $devnode $root/displaylink/by-id/$device_id
}
unlink_displaylink_symlink()
{
root=$1
devname=$2
for f in $root/displaylink/by-id/*; do
if [ ! -e "$f" ] || ([ -L "$f" ] && [ "$f" -ef "$devname" ]); then
unlink "$f"
fi
done
(cd $root; rmdir -p --ignore-fail-on-non-empty displaylink/by-id)
}
prune_broken_links()
{
root=$1
dir="$root/displaylink/by-id"
find -L "$dir" -name "$dir" -o type d -prune -o -type -l -exec rm {} +
remove_dldir_if_empty $root
}
main()
{
action=$1
root=$2
devnode=$4
if [ "$action" = "add" ]; then
device_id=$3
create_displaylink_symlink $root $device_id $devnode
start_displaylink
elif [ "$action" = "remove" ]; then
devname=$3
unlink_displaylink_symlink "$root" "$devname"
stop_displaylink "$root"
elif [ "$action" = "START" ]; then
start_displaylink
fi
}