Skip to content

Commit 727ebc1

Browse files
Add docker-helper from Karl Fessel to Repository
1 parent 1ea4e88 commit 727ebc1

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Docker Helper
2+
3+
This contains udev-rules and shell-scripts that aid in creating device nodes inside docker-containers using udev. (`docker-chardev` and `docker-usbdev` rules and scripts)
4+
5+
The `write_env`-rule and script are there for development purposes. The scrcipt writes its env to a /var/log/write_env.log the rule runs it on a udev event.
6+
7+
Copy them to the appropriate location udev-rules typicaliy go to `/etc/udev/` scripts might go to `/opt/bin/`
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
for c in $( docker container ls -q ); do
3+
4+
5+
if [ "$ACTION" = "add" ]; then
6+
docker exec -u root -i $c sh <<EOF
7+
8+
mknod $DEVNAME c $MAJOR $MINOR
9+
chmod 0666 $DEVNAME
10+
chown :dialout $DEVNAME
11+
12+
EOF
13+
elif [ "$ACTION" = "remove" ]; then
14+
15+
docker exec -u root -i $c sh <<EOF
16+
17+
rm $DEVNAME
18+
19+
EOF
20+
fi
21+
22+
done
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
if [ "$DEVTYPE" = "usb_device" ]; then
3+
for c in $( docker container ls -q ); do
4+
5+
if [ "$ACTION" = "add" ]; then
6+
docker exec -u root -i $c sh <<EOF
7+
8+
mkdir -p $(dirname $DEVNAME)
9+
mknod $DEVNAME c $MAJOR $MINOR
10+
chmod 0666 $DEVNAME
11+
chown :dialout $DEVNAME
12+
13+
EOF
14+
elif [ "$ACTION" = "remove" ]; then
15+
16+
docker exec -u root -i $c sh <<EOF
17+
18+
rm $DEVNAME
19+
rmdir -p --ignore-fail-on-non-empty $(dirname $DEVNAME)
20+
21+
EOF
22+
fi
23+
24+
done
25+
fi
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
echo -n =============================== >> /var/log/write_env.log
4+
date >> /var/log/write_env.log
5+
env >> /var/log/write_env.log
6+
cat >> /var/log/write_env.log << EOF
7+
$MINOR
8+
EOF
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# for USB devices
2+
3+
KERNEL!="ttyUSB[0-9]*|ttyACM[0-9]*", GOTO="docker-chardev_end"
4+
5+
ACTION=="remove", SUBSYSTEM=="tty", RUN+="/opt/bin/docker-chardev.sh"
6+
ACTION=="add", SUBSYSTEM=="tty", RUN+="/opt/bin/docker-chardev.sh"
7+
8+
#SUBSYSTEMS=="usb-serial", ENV{.ID_PORT}="$attr{port_number}"
9+
10+
LABEL="docker-chardev_end"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# for USB devices
2+
3+
TAG!="uaccess", GOTO="docker-usbdev_end"
4+
5+
ACTION=="remove", SUBSYSTEM=="usb", RUN+="/opt/bin/docker-usbdev.sh"
6+
ACTION=="add", SUBSYSTEM=="usb", RUN+="/opt/bin/docker-usbdev.sh"
7+
8+
LABEL="docker-usbdev_end"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# only for USB devices
3+
4+
KERNEL!="ttyUSB[0-9]*|ttyACM[0-9]*", GOTO="write_log_end"
5+
6+
ACTION=="remove", SUBSYSTEM=="tty", RUN+="/opt/bin/write_env.sh"
7+
ACTION=="add", SUBSYSTEM=="tty", RUN+="/opt/bin/write_env.sh"
8+
9+
#SUBSYSTEMS=="usb-serial", ENV{.ID_PORT}="$attr{port_number}"
10+
11+
LABEL="write_log_end"

0 commit comments

Comments
 (0)