WordPress

Wordpress

1. Goal

  • After searching the upload path, appropriate permissions are granted.

    • Directory 755

    • File 644

2. Description

  • Check permissions: find "$UPLOADS_DIR" -type d ! -perm 755 Use the and find "$UPLOADS_DIR" -type f ! -perm 644commands to find directories and files with incorrect permissions.

  • Ask user: If permissions are incorrect, ask the user if they want to change them.

  • Handle user input: Change permissions if the user types yesor y, otherwise skip changing permissions.

3. Code

vi set_permissions.sh

#!/bin/bash

# wp-content 디렉토리 μ°ΎκΈ°
echo "wp-content 디렉토리λ₯Ό μ°Ύκ³  μžˆμŠ΅λ‹ˆλ‹€..."
WPCONTENT_DIRS=$(find / -type d -name "wp-content" 2>/dev/null)

# wp-content 디렉토리λ₯Ό μ°Ύμ•˜λŠ”μ§€ 확인
if [ -z "$WPCONTENT_DIRS" ]; then
  echo "wp-content 디렉토리λ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."
  exit 1
fi

# 찾은 λͺ¨λ“  wp-content 디렉토리에 λŒ€ν•΄ μž‘μ—… μˆ˜ν–‰
for WPCONTENT_DIR in $WPCONTENT_DIRS; do
  echo "wp-content 디렉토리: $WPCONTENT_DIR"
  
  # uploads 디렉토리 μ„€μ •
  UPLOADS_DIR="$WPCONTENT_DIR/uploads"

  # uploads 디렉토리 쑴재 μ—¬λΆ€ 확인
  if [ ! -d "$UPLOADS_DIR" ]; then
    echo "uploads 디렉토리가 $UPLOADS_DIR에 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."
    continue
  fi

  echo "uploads 디렉토리: $UPLOADS_DIR"

  # κΆŒν•œ 검사
  DIR_PERM=$(find "$UPLOADS_DIR" -type d ! -perm 755)
  FILE_PERM=$(find "$UPLOADS_DIR" -type f ! -perm 644)

  if [ -z "$DIR_PERM" ] && [ -z "$FILE_PERM" ]; then
    echo "디렉토리와 파일 κΆŒν•œμ΄ 이미 μ˜¬λ°”λ₯΄κ²Œ μ„€μ •λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€."
    continue
  else
    echo "디렉토리 λ˜λŠ” 파일 κΆŒν•œμ΄ μ˜¬λ°”λ₯΄μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."
    echo "λ³€κ²½ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ? (yes(y)/no(n))"
    read answer
    if [ "$answer" = "yes" ] || [ "$answer" = "y" ]; then
      # 디렉토리 κΆŒν•œ μ„€μ •
      find "$UPLOADS_DIR" -type d -exec chmod 755 {} \;
      echo "디렉토리 κΆŒν•œμ΄ 755둜 μ„€μ •λ˜μ—ˆμŠ΅λ‹ˆλ‹€."

      # 파일 κΆŒν•œ μ„€μ •
      find "$UPLOADS_DIR" -type f -exec chmod 644 {} \;
      echo "파일 κΆŒν•œμ΄ 644둜 μ„€μ •λ˜μ—ˆμŠ΅λ‹ˆλ‹€."

      echo "κΆŒν•œ 섀정이 μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€."
    else
      echo "κΆŒν•œ 섀정을 κ±΄λ„ˆλœλ‹ˆλ‹€."
      continue
    fi
  fi
done

4. Run

Last updated