Skip to content

Instantly share code, notes, and snippets.

@jefferymiller
Created June 14, 2017 21:14
Show Gist options
  • Save jefferymiller/9d8cae7363ee584a930b3fc5798e6592 to your computer and use it in GitHub Desktop.
Save jefferymiller/9d8cae7363ee584a930b3fc5798e6592 to your computer and use it in GitHub Desktop.
displaylink 1.3.52 udev rule and helper script
#!/bin/sh
# Copyright (c) 2016 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
}
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
device_id=$2
unlink $root/displaylink/by-id/$device_id 2> /dev/null
(cd $root; rmdir -p --ignore-fail-on-non-empty displaylink/by-id)
}
main()
{
action=$1
root=$2
device_id=$3
devnode=$4
if [ "$action" = "add" ]; then
create_displaylink_symlink $root $device_id $devnode
start_displaylink
elif [ "$action" = "remove" ]; then
unlink_displaylink_symlink "$root" "$device_id"
stop_displaylink "$root"
fi
}
start_service()
{
start dlm
}
stop_service()
{
stop dlm
}
main $ACTION $1 $2 $3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment