mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-05-15 18:03:32 +00:00
config_service.py: replace MD5 with SHA-256 for config change detection; same semantics (equality comparison), no stored hashes affected. Shell scripts — shellcheck warnings: - diagnose_web_interface.sh: remove useless cat (SC2002) - dev_plugin_setup.sh: restructure A&&B||C into if/then (SC2015) - fix_assets_permissions.sh: remove unused REAL_HOME block (SC2034) - install_web_service.sh: remove unused USER_HOME assignment (SC2034) - diagnose_web_ui.sh: remove unused SUDO assignments (SC2034) - diagnose_plugin_permissions.sh: remove unused BLUE color var (SC2034) - first_time_install.sh: remove unused CLEAR var, PACKAGE_NAME assignment, and replace loop variable with _ (SC2034) docs/PLUGIN_ARCHITECTURE_SPEC.md: fix 10 broken TOC anchor links to include section numbers matching the actual headings (MD051). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
172 lines
5.5 KiB
Bash
Executable File
172 lines
5.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Diagnostic script for plugin directory permissions
|
|
# Run this on the Raspberry Pi to check and fix plugin directory permissions
|
|
|
|
set -e
|
|
|
|
echo "=========================================="
|
|
echo "Plugin Directory Permissions Diagnostic"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Get the actual user
|
|
if [ -n "$SUDO_USER" ]; then
|
|
ACTUAL_USER="$SUDO_USER"
|
|
else
|
|
ACTUAL_USER=$(whoami)
|
|
fi
|
|
|
|
# Get project root (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: $PROJECT_ROOT_DIR"
|
|
echo "User: $ACTUAL_USER"
|
|
echo "Running as: $(whoami)"
|
|
echo ""
|
|
|
|
# Check parent directory permissions
|
|
echo "=== Parent Directory Permissions ==="
|
|
echo "Checking /home/$ACTUAL_USER:"
|
|
if [ -d "/home/$ACTUAL_USER" ]; then
|
|
PERMS=$(stat -c "%a %U:%G" "/home/$ACTUAL_USER")
|
|
echo " Permissions: $PERMS"
|
|
if [ "$(stat -c "%a" "/home/$ACTUAL_USER")" != "755" ] && [ "$(stat -c "%a" "/home/$ACTUAL_USER")" != "750" ]; then
|
|
echo -e " ${YELLOW}⚠ Warning: Home directory has restrictive permissions${NC}"
|
|
echo " Root may not be able to access subdirectories"
|
|
fi
|
|
else
|
|
echo -e " ${RED}✗ Home directory not found${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
echo "Checking $PROJECT_ROOT_DIR:"
|
|
if [ -d "$PROJECT_ROOT_DIR" ]; then
|
|
PERMS=$(stat -c "%a %U:%G" "$PROJECT_ROOT_DIR")
|
|
echo " Permissions: $PERMS"
|
|
if [ "$(stat -c "%a" "$PROJECT_ROOT_DIR")" != "755" ] && [ "$(stat -c "%a" "$PROJECT_ROOT_DIR")" != "750" ]; then
|
|
echo -e " ${YELLOW}⚠ Warning: Project directory has restrictive permissions${NC}"
|
|
fi
|
|
else
|
|
echo -e " ${RED}✗ Project directory not found${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Check plugins directory
|
|
echo "=== Plugins Directory ==="
|
|
if [ -d "$PLUGINS_DIR" ]; then
|
|
PERMS=$(stat -c "%a %U:%G" "$PLUGINS_DIR")
|
|
echo " Path: $PLUGINS_DIR"
|
|
echo " Permissions: $PERMS"
|
|
|
|
OWNER=$(stat -c "%U" "$PLUGINS_DIR")
|
|
GROUP=$(stat -c "%G" "$PLUGINS_DIR")
|
|
PERM_BITS=$(stat -c "%a" "$PLUGINS_DIR")
|
|
|
|
if [ "$OWNER" = "root" ] && [ "$GROUP" = "$ACTUAL_USER" ] && [ "$PERM_BITS" = "775" ]; then
|
|
echo -e " ${GREEN}✓ Correct permissions${NC}"
|
|
else
|
|
echo -e " ${RED}✗ Incorrect permissions${NC}"
|
|
echo " Expected: root:$ACTUAL_USER 775"
|
|
echo " Actual: $OWNER:$GROUP $PERM_BITS"
|
|
fi
|
|
|
|
# Check if root can access
|
|
if sudo -u root test -r "$PLUGINS_DIR" && sudo -u root test -w "$PLUGINS_DIR"; then
|
|
echo -e " ${GREEN}✓ Root can read/write${NC}"
|
|
else
|
|
echo -e " ${RED}✗ Root cannot access${NC}"
|
|
fi
|
|
else
|
|
echo -e " ${YELLOW}⚠ Directory does not exist${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Check plugin-repos directory
|
|
echo "=== Plugin-Repos Directory ==="
|
|
if [ -d "$PLUGIN_REPOS_DIR" ]; then
|
|
PERMS=$(stat -c "%a %U:%G" "$PLUGIN_REPOS_DIR")
|
|
echo " Path: $PLUGIN_REPOS_DIR"
|
|
echo " Permissions: $PERMS"
|
|
|
|
OWNER=$(stat -c "%U" "$PLUGIN_REPOS_DIR")
|
|
GROUP=$(stat -c "%G" "$PLUGIN_REPOS_DIR")
|
|
PERM_BITS=$(stat -c "%a" "$PLUGIN_REPOS_DIR")
|
|
|
|
if [ "$OWNER" = "root" ] && [ "$GROUP" = "$ACTUAL_USER" ] && [ "$PERM_BITS" = "775" ]; then
|
|
echo -e " ${GREEN}✓ Correct permissions${NC}"
|
|
else
|
|
echo -e " ${RED}✗ Incorrect permissions${NC}"
|
|
echo " Expected: root:$ACTUAL_USER 775"
|
|
echo " Actual: $OWNER:$GROUP $PERM_BITS"
|
|
fi
|
|
|
|
# Check if root can access
|
|
if sudo -u root test -r "$PLUGIN_REPOS_DIR" && sudo -u root test -w "$PLUGIN_REPOS_DIR"; then
|
|
echo -e " ${GREEN}✓ Root can read/write${NC}"
|
|
else
|
|
echo -e " ${RED}✗ Root cannot access${NC}"
|
|
fi
|
|
|
|
# Try to list contents as root
|
|
echo " Testing root access:"
|
|
if sudo -u root ls "$PLUGIN_REPOS_DIR" >/dev/null 2>&1; then
|
|
echo -e " ${GREEN}✓ Root can list directory${NC}"
|
|
else
|
|
echo -e " ${RED}✗ Root cannot list directory${NC}"
|
|
echo " Error: $(sudo -u root ls "$PLUGIN_REPOS_DIR" 2>&1 | head -1)"
|
|
fi
|
|
else
|
|
echo -e " ${YELLOW}⚠ Directory does not exist${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Test if root can create files
|
|
echo "=== Testing Root Write Access ==="
|
|
TEST_FILE="$PLUGIN_REPOS_DIR/.permission_test_$$"
|
|
if sudo -u root touch "$TEST_FILE" 2>/dev/null; then
|
|
echo -e " ${GREEN}✓ Root can create files${NC}"
|
|
sudo -u root rm -f "$TEST_FILE"
|
|
else
|
|
echo -e " ${RED}✗ Root cannot create files${NC}"
|
|
echo " Error: $(sudo -u root touch "$TEST_FILE" 2>&1)"
|
|
fi
|
|
echo ""
|
|
|
|
# Summary and fix recommendations
|
|
echo "=== Summary ==="
|
|
NEEDS_FIX=false
|
|
|
|
if [ ! -d "$PLUGIN_REPOS_DIR" ]; then
|
|
echo -e "${YELLOW}⚠ plugin-repos directory does not exist${NC}"
|
|
NEEDS_FIX=true
|
|
elif [ "$(stat -c "%U:%G" "$PLUGIN_REPOS_DIR" 2>/dev/null)" != "root:$ACTUAL_USER" ] || [ "$(stat -c "%a" "$PLUGIN_REPOS_DIR" 2>/dev/null)" != "775" ]; then
|
|
echo -e "${RED}✗ plugin-repos has incorrect permissions${NC}"
|
|
NEEDS_FIX=true
|
|
fi
|
|
|
|
if [ "$NEEDS_FIX" = true ]; then
|
|
echo ""
|
|
echo "=== Fix Commands ==="
|
|
echo "Run these commands to fix permissions:"
|
|
echo ""
|
|
echo "sudo mkdir -p $PLUGIN_REPOS_DIR"
|
|
echo "sudo chown root:$ACTUAL_USER $PLUGIN_REPOS_DIR"
|
|
echo "sudo chmod 775 $PLUGIN_REPOS_DIR"
|
|
echo ""
|
|
echo "Or run the fix script:"
|
|
echo "sudo bash $PROJECT_ROOT_DIR/scripts/fix_perms/fix_plugin_permissions.sh"
|
|
else
|
|
echo -e "${GREEN}✓ All permissions look correct${NC}"
|
|
fi
|
|
echo ""
|
|
|