Files
LEDMatrix/scripts/fix_perms/fix_plugin_permissions.sh
T
Claude b428ae3eae fix: address CodeRabbit review findings
Verified each finding against the code; fixes for the valid ones:

- install_dependencies_apt.py: the installer listed 'freetype', but the
  declared dependency is freetype-py — an apt miss would pip-install the
  wrong PyPI package. Now installs freetype-py with an import-name
  mapping (pre-existing bug, surfaced by the review).
- api_v3.py: pixel_mapper_config is validated as a string before being
  saved to display.hardware (JSON callers could previously store an
  object/list the matrix library can't use).
- .cursorrules: the Plugin Loading Process and File Organization
  sections still said discovery scans plugins/ — now consistent with the
  corrected overview (configured directory, default plugin-repos/).
- README.md: removed the stale '(except the core calendar)' claim — no
  core calendar exists in src/ — and qualified the plugin inventory
  (official plugins in the monorepo; third-party from their own repos).
- CONFIG_REFERENCE.md: hardware_mapping now shows the code fallback
  (adafruit-hat-pwm) alongside the template value.
- PLUGIN_REGISTRY_SETUP_GUIDE.md: check_plugin.py takes --plugin, not a
  positional id.
- scripts/fix_perms/fix_*.sh: exec bits set so the documented
  'sudo ./...' invocations work.
- Guard tests hardened: template guard now catches multi-line
  render_template() calls; widget guard parses actual <script> src
  values and fails if the widgets dir goes missing; type hints and
  docstrings added per repo coding guidelines.

Skipped with reasons (noted on the PR): limit_refresh_rate_hz 100-vs-90
is documented as intentional in CONFIG_REFERENCE.md; the psutil comment
already names the enforcing manifest; docs/archive/ findings are out of
scope per the docs policy (archive may rot).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXb4mKcAkVaxkeTb3YnAdr
2026-08-06 01:32:23 +00:00

94 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Fix permissions for the plugins directory
# This script sets up proper permissions for both root service and web service access
echo "Fixing permissions for plugins directory..."
# Get the actual user who invoked sudo
if [ -n "$SUDO_USER" ]; then
ACTUAL_USER="$SUDO_USER"
else
ACTUAL_USER=$(whoami)
fi
# Get the project root directory (parent of scripts directory)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT_DIR="$( cd "$SCRIPT_DIR/../.." && pwd )"
PLUGINS_DIR="$PROJECT_ROOT_DIR/plugins"
PLUGIN_REPOS_DIR="$PROJECT_ROOT_DIR/plugin-repos"
echo "Project root directory: $PROJECT_ROOT_DIR"
echo "Plugins directory: $PLUGINS_DIR"
echo "Plugin-repos directory: $PLUGIN_REPOS_DIR"
echo "Actual user: $ACTUAL_USER"
echo ""
# Check and fix home directory permissions if needed
# Home directory needs at least 755 (or 750) so root can traverse it
USER_HOME=$(eval echo ~$ACTUAL_USER)
if [ -d "$USER_HOME" ]; then
HOME_PERMS=$(stat -c "%a" "$USER_HOME")
if [ "$HOME_PERMS" = "700" ]; then
echo "⚠ Home directory has restrictive permissions (700)"
echo " Root cannot traverse /home/$ACTUAL_USER to access subdirectories"
echo " Fixing home directory permissions to 755..."
chmod 755 "$USER_HOME"
echo "✓ Home directory permissions fixed"
else
echo "✓ Home directory permissions OK ($HOME_PERMS)"
fi
fi
echo ""
# Ensure plugins directory exists
if [ ! -d "$PLUGINS_DIR" ]; then
echo "Creating plugins directory..."
mkdir -p "$PLUGINS_DIR"
fi
# Set ownership to root:ACTUAL_USER for mixed access
# Root service can read/write, web service (ACTUAL_USER) can read/write
echo "Setting ownership to root:$ACTUAL_USER..."
sudo chown -R root:"$ACTUAL_USER" "$PLUGINS_DIR"
# Set directory permissions (775: rwxrwxr-x)
# Root: read/write/execute, Group (ACTUAL_USER): read/write/execute, Others: read/execute
echo "Setting directory permissions to 2775 (rwxrwxr-x + sticky bit)..."
find "$PLUGINS_DIR" -type d -exec sudo chmod 2775 {} \;
# Set file permissions (664: rw-rw-r--)
# Root: read/write, Group (ACTUAL_USER): read/write, Others: read
echo "Setting file permissions to 664..."
find "$PLUGINS_DIR" -type f -exec sudo chmod 664 {} \;
# Also ensure plugin-repos directory exists with proper permissions
# This is where plugins installed via the plugin store are stored
if [ ! -d "$PLUGIN_REPOS_DIR" ]; then
echo "Creating plugin-repos directory..."
mkdir -p "$PLUGIN_REPOS_DIR"
fi
echo "Setting ownership of plugin-repos to root:$ACTUAL_USER..."
sudo chown -R root:"$ACTUAL_USER" "$PLUGIN_REPOS_DIR"
echo "Setting plugin-repos directory permissions to 2775 (rwxrwxr-x + sticky bit)..."
find "$PLUGIN_REPOS_DIR" -type d -exec sudo chmod 2775 {} \;
echo "Setting plugin-repos file permissions to 664..."
find "$PLUGIN_REPOS_DIR" -type f -exec sudo chmod 664 {} \;
echo "Plugin permissions fixed successfully!"
echo ""
echo "Directory structure:"
echo "plugins/:"
ls -la "$PLUGINS_DIR" 2>/dev/null || echo " (empty or not accessible)"
echo ""
echo "plugin-repos/:"
ls -la "$PLUGIN_REPOS_DIR" 2>/dev/null || echo " (empty or not accessible)"
echo ""
echo "Permissions summary:"
echo "- Root service: Can read/write plugins (for PWM hardware access)"
echo "- Web service ($ACTUAL_USER): Can read/write plugins (for installation)"
echo "- Others: Can read plugins"