Created
January 18, 2023 01:10
-
-
Save tai/8b143180035fe9e236c8b3f1c2c9f629 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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