Last active
February 22, 2018 22:13
-
-
Save metasoarous/a7308779837f9dcba662 to your computer and use it in GitHub Desktop.
Script and udev rule for setting group permissions on pin files for beaglebone black development
This file contains 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
# Install in: /etc/udev/rules.d/ | |
KERNEL=="gpio*", SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/usr/local/bin/set-pinuesrs-permissions.sh" |
This file contains 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/bash | |
# | |
# Place in /usr/local/bin/set-pinusers-permissions.sh | |
# | |
# This file will change the user, group and permissions in both the | |
# /sys/devices/virtual/gpio and /sys/class/gpio path directories. In particular, | |
# it will add a `pinusers` group to these files. By adding your user to this | |
# group, you will have access to those pin files. | |
# | |
# DO NOT change the order of the commands below, they are optimized so that | |
# commonly created files and directories are changed first. | |
# | |
chown -R :pinusers /sys/devices/virtual/gpio | |
chown -R :pinusers /sys/class/gpio | |
find /sys/devices/virtual/gpio -type d -exec chmod 2775 {} \; | |
find /sys/devices/virtual/gpio -name "direction" -exec chmod 0660 {} \; | |
find /sys/devices/virtual/gpio -name "edge" -exec chmod 0660 {} \; | |
find /sys/devices/virtual/gpio -name "value" -exec chmod 0660 {} \; | |
find /sys/devices/virtual/gpio -name "active_low" -exec chmod 0660 {} \; | |
chmod 0220 /sys/class/gpio/export | |
chmod 0220 /sys/class/gpio/unexport | |
find /sys/devices/virtual/gpio -name "uevent" -exec chmod 0660 {} \; | |
find /sys/devices/virtual/gpio -name "autosuspend_delay_ms" -exec chmod 0660 {} \; | |
find /sys/devices/virtual/gpio -name "control" -exec chmod 0660 {} \; | |
# Additional code for getting AIN pins set up | |
ain_activator=/sys/devices/bone_capemgr.* | |
chown -R :pinusers $ain_activator/ | |
chmod -R 2775 $ain_activator/ | |
# Uncomment to have the AIN pins activated by default on boot | |
# echo cape-bone-iio > $ain_activator/slots | |
the find command does not automatically follow symbolic links so it will not touch those files. Unfortunately just using the '-L' option to follow links also probably won't work due to filesystem reference cycles/loops.
I ended up with a for loop in a bash script to touch the direction, value, and edge files under each gpio during the 'add' event.
#!/bin/bash
GPIODIR=/sys/class/gpio
FILES="direction value edge"
for d in $(ls $GPIODIR | grep gpio[000-999])
do
d=$GPIODIR/$d #make an absolute path
for f in $FILES
do
[ -f $d/$f ] &&
chown :gpio $d/$f
chmod ug+rw $d/$f
done
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @metasoarous! I used this
udev
script and it has changed the ownership fromroot:root
to another non-root user and group. However, the individual files likedirection
are not changed despite doingchown -R
. E.g.Did you run into the same challenge?