Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ services:
- /dev:/dev:rw # Full /dev access improves hotplug handling
- /run/udev:/run/udev:ro # Access to udev events
environment:

# - SKIP_PERMCHECK # Skip USB permission change for rootless implementations
- SECRET_KEY=test1234567890 # for password encryption and decryption in the database
- UDEV=1 # Improve USB detection
ports:
Expand Down
40 changes: 25 additions & 15 deletions src/filesystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,31 @@ detect_usb_devices() {

# Function to fix USB permissions if applicable
fix_usb_permissions() {
if [ -d "/dev/bus/usb" ]; then
# First set ownership to root:nut for good measure
chown -R root:nut /dev/bus/usb
# Now grant read-write to all users (old method that worked better)
chmod -R o+rw /dev/bus/usb 2>/dev/null
startup_log "USB device permissions updated (all users access granted)"
else
startup_log "WARNING: Directory /dev/bus/usb not found!"
fi

# Set the suid bit on the nut commands
chmod u+s /usr/bin/upsc /usr/bin/upscmd /usr/bin/upsrw 2>/dev/null
if [ "$ENABLE_LOG_STARTUP" = "Y" ]; then
startup_log "Set suid permissions for NUT commands"
fi
case "${SKIP_PERMCHECK,,}" in
true|1|yes)
startup_log "Skipping USB permission updates (SKIP_PERMCHECK=${SKIP_PERMCHECK})"
if [ "$ENABLE_LOG_STARTUP" = "Y" ]; then
startup_log "Skipping SUID permissions for NUT commands (SKIP_PERMCHECK=${SKIP_PERMCHECK})"
fi
;;
*)
if [ -d "/dev/bus/usb" ]; then
# First set ownership to root:nut for good measure
chown -R root:nut /dev/bus/usb
# Now grant read-write to all users (old method that worked better)
chmod -R o+rw /dev/bus/usb 2>/dev/null
startup_log "USB device permissions updated (all users access granted)"
else
startup_log "WARNING: Directory /dev/bus/usb not found!"
fi

# Set the suid bit on the nut commands
chmod u+s /usr/bin/upsc /usr/bin/upscmd /usr/bin/upsrw 2>/dev/null
if [ "$ENABLE_LOG_STARTUP" = "Y" ]; then
startup_log "Set suid permissions for NUT commands"
fi
;;
esac
}

# Clean up existing PID files to prevent conflicts
Expand Down