access-permissions.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/sh
  2. # Apply access permissions
  3. if [ ! -f './constants.php' ] || [ ! -d './cli/' ]; then
  4. echo >&2 '⛔ It does not look like a FreshRSS directory; exiting!'
  5. exit 2
  6. fi
  7. if [ "$(id -u)" -ne 0 ]; then
  8. echo >&2 '⛔ Applying access permissions require running as root or sudo!'
  9. exit 3
  10. fi
  11. # Always fix permissions on the data and extensions directories
  12. # If specified, only fix the data and extensions directories
  13. data_path="${DATA_PATH:-./data}"
  14. if [ "${1:-}" = "--only-userdirs" ]; then
  15. to_update="./extensions"
  16. else
  17. to_update="."
  18. fi
  19. mkdir -p "${data_path}/users/_/"
  20. if getent group www-data >/dev/null; then
  21. www_group="www-data" # Debian, Alpine
  22. elif getent group apache >/dev/null; then
  23. www_group="apache" # Alpine
  24. elif getent group http >/dev/null; then
  25. www_group="http" # Arch Linux
  26. else
  27. echo >&2 '⛔ No Apache group {www-data, apache, http} found!'
  28. exit 4
  29. fi
  30. # Based on group access
  31. chown -R :$www_group "$data_path" "$to_update"
  32. # Read files, and directory traversal
  33. chmod -R g+rX "$data_path" "$to_update"
  34. # Write access to data
  35. chmod -R g+w "$data_path"