Files
LEDMatrix/fix_assets_permissions.sh
Chuck fc06493990 Fix/logo download permission error (#70)
* fix: Resolve permission errors when downloading sports logos

- Fix fix_assets_permissions.sh to use correct directory name 'ncaa_logos' instead of 'ncaa_fbs_logos'
- Add comprehensive permission checking in logo downloader
- Improve error handling with specific permission error messages
- Add write access testing before attempting logo downloads
- Provide clear instructions to run permission fix script when errors occur

Fixes: [Errno 13] Permission denied errors when downloading team logos like SELA.png

* fix: Update first_time_install.sh to use correct ncaa_logos directory

- Fix manual permission setting section to use 'ncaa_logos' instead of 'ncaa_fbs_logos'
- Ensures consistency across all installation scripts
- Prevents permission issues during first-time installation

* fix: Update all remaining references from ncaa_fbs_logos to ncaa_logos

- Fix README.md directory reference
- Update wiki documentation files (MANAGER_GUIDE_COMPREHENSIVE.md, TEAM_ABBREVIATIONS_AND_LEAGUE_SLUGS.md)
- Fix test files (save_missing_teams.py, test_ranking_toggle.py, test_leaderboard_simple.py)
- Update missing_team_logos.txt with correct directory paths

Ensures complete consistency across the entire project for NCAA logo directory naming.
2025-09-25 19:21:26 -04:00

128 lines
4.1 KiB
Bash

#!/bin/bash
# LEDMatrix Assets Permissions Fix Script
# This script fixes permissions on the assets directory so the application can download and save team logos
echo "Fixing LEDMatrix assets directory permissions..."
# Get the real user (not root when running with sudo)
REAL_USER=${SUDO_USER:-$USER}
# Resolve the home directory of the real user robustly
if command -v getent >/dev/null 2>&1; then
REAL_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6)
else
REAL_HOME=$(eval echo ~"$REAL_USER")
fi
REAL_GROUP=$(id -gn "$REAL_USER")
# Get the project directory
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ASSETS_DIR="$PROJECT_DIR/assets"
echo "Project directory: $PROJECT_DIR"
echo "Assets directory: $ASSETS_DIR"
echo "Real user: $REAL_USER"
echo "Real group: $REAL_GROUP"
# Check if assets directory exists
if [ ! -d "$ASSETS_DIR" ]; then
echo "Error: Assets directory does not exist at $ASSETS_DIR"
exit 1
fi
echo ""
echo "Fixing permissions for assets directory and subdirectories..."
# Set ownership of the entire assets directory to the real user
echo "Setting ownership of assets directory..."
if sudo chown -R "$REAL_USER:$REAL_GROUP" "$ASSETS_DIR"; then
echo "✓ Set assets directory ownership to $REAL_USER:$REAL_GROUP"
else
echo "✗ Failed to set assets directory ownership"
exit 1
fi
# Set permissions to allow read/write for owner and group, read for others
echo "Setting permissions for assets directory..."
if sudo chmod -R 775 "$ASSETS_DIR"; then
echo "✓ Set assets directory permissions to 775"
else
echo "✗ Failed to set assets directory permissions"
exit 1
fi
# Specifically ensure the sports logos directories are writable
SPORTS_DIRS=(
"sports/ncaa_logos"
"sports/nfl_logos"
"sports/nba_logos"
"sports/nhl_logos"
"sports/mlb_logos"
"sports/milb_logos"
"sports/soccer_logos"
)
echo ""
echo "Ensuring sports logo directories are writable..."
for SPORTS_DIR in "${SPORTS_DIRS[@]}"; do
FULL_PATH="$ASSETS_DIR/$SPORTS_DIR"
echo ""
echo "Checking directory: $FULL_PATH"
if [ -d "$FULL_PATH" ]; then
echo " - Directory exists"
echo " - Current permissions:"
ls -ld "$FULL_PATH"
# Ensure the directory is writable
sudo chmod 775 "$FULL_PATH"
sudo chown "$REAL_USER:$REAL_GROUP" "$FULL_PATH"
echo " - Updated permissions:"
ls -ld "$FULL_PATH"
# Test write access
echo " - Testing write access as $REAL_USER..."
if sudo -u "$REAL_USER" test -w "$FULL_PATH"; then
echo "$FULL_PATH is writable by $REAL_USER"
else
echo "$FULL_PATH is not writable by $REAL_USER"
fi
else
echo " - Directory does not exist, creating it..."
sudo mkdir -p "$FULL_PATH"
sudo chown "$REAL_USER:$REAL_GROUP" "$FULL_PATH"
sudo chmod 775 "$FULL_PATH"
echo " - Created directory with proper permissions"
fi
done
echo ""
echo "Testing write access to ncaa_logos directory specifically..."
NCAA_DIR="$ASSETS_DIR/sports/ncaa_logos"
if [ -d "$NCAA_DIR" ]; then
# Create a test file to verify write access
TEST_FILE="$NCAA_DIR/.permission_test"
if sudo -u "$REAL_USER" touch "$TEST_FILE" 2>/dev/null; then
echo "✓ Successfully created test file in ncaa_logos directory"
sudo -u "$REAL_USER" rm -f "$TEST_FILE"
echo "✓ Successfully removed test file"
else
echo "✗ Failed to create test file in ncaa_logos directory"
echo " This indicates the permission fix did not work properly"
fi
else
echo "✗ ncaa_logos directory does not exist"
fi
echo ""
echo "Assets permissions fix completed!"
echo ""
echo "The application should now be able to download and save team logos."
echo "If you still see permission errors, check which user is running the LEDMatrix service"
echo "and ensure it matches the owner above ($REAL_USER)."
echo ""
echo "You may need to restart the LEDMatrix service for the changes to take effect:"
echo " sudo systemctl restart ledmatrix.service"