-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathrun
More file actions
executable file
·35 lines (33 loc) · 1.52 KB
/
run
File metadata and controls
executable file
·35 lines (33 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
FILES=$(find /dev/ttyACM* /dev/ttyUSB* -type c -print 2>/dev/null)
for i in $FILES; do
USB_GID=$(stat -c '%g' "${i}")
USB_UID=$(stat -c '%u' "${i}")
# check if user matches device
if id -u abc | grep -qw "${USB_UID}"; then
echo "**** permissions for ${i} are good ****"
else
# check if group matches and that device has group rw
if id -G abc | grep -qw "${USB_GID}" && [ $(stat -c '%A' "${i}" | cut -b 5,6) = "rw" ]; then
echo "**** permissions for ${i} are good ****"
# check if device needs to be added to USB group
elif ! id -G abc | grep -qw "${USB_GID}"; then
# check if USB group needs to be created
USB_NAME=$(getent group "${USB_GID}" | awk -F: '{print $1}')
if [ -z "${USB_NAME}" ]; then
USB_NAME="usb$(head /dev/urandom | tr -dc 'a-z0-9' | head -c4)"
groupadd "${USB_NAME}"
groupmod -g "${USB_GID}" "${USB_NAME}"
echo "**** creating USB group ${USB_NAME} with id ${USB_GID} ****"
fi
echo "**** adding ${i} to USB group ${USB_NAME} with id ${USB_GID} ****"
usermod -a -G "${USB_NAME}" abc
fi
# check if device has group rw
if [ $(stat -c '%A' "${i}" | cut -b 5,6) != "rw" ]; then
echo -e "**** The device ${i} does not have group read/write permissions, attempting to fix inside the container. ****"
chmod g+rw "${i}"
fi
fi
done