Skip to content

Instantly share code, notes, and snippets.

@tai
Created January 18, 2023 01:10
Show Gist options
  • Save tai/8b143180035fe9e236c8b3f1c2c9f629 to your computer and use it in GitHub Desktop.
Save tai/8b143180035fe9e236c8b3f1c2c9f629 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Quick hack to export a device into container
#
# NOTE:
# - systemd-run cannot be used as capability is dropped from udev service
#
exec > /dev/null 2>&1
run() {
local node=hc
# assign device to node
case "$DEVNAME" in
/dev/*/*) exit 0;;
/dev/*) node=hc;;
*) exit 0;;
esac
# skip unless target node is alive
machinectl status "$node" || exit 0
case "$ACTION" in
add)
machinectl -q bind --mkdir $node $DEVNAME
;;
remove)
machinectl -q shell $node /bin/umount -qlf $DEVNAME
;;
change)
machinectl -q shell $node /bin/umount -qlf $DEVNAME
machinectl -q bind --mkdir $node $DEVNAME
;;
esac
exit 0
}
run "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment