chattr_web 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/sh
  2. ###
  3. #
  4. # Author: Stéphane HUC
  5. # mail: devs@stephane-huc.net
  6. #
  7. # License: GNU/GPL 3
  8. #
  9. # Github: https://git.framasoft.org/hucste/tools
  10. #
  11. # Date: 2016/03/01
  12. #
  13. ###
  14. ###
  15. #
  16. # Change attributes system
  17. #
  18. ###
  19. arg="$1"
  20. dirname="$(dirname $(readlink -f -- "$0"))"
  21. active() {
  22. chattr -R +i /srv/www 2> /dev/null
  23. chattr -R -i /srv/www/apt /srv/www/*/cache /srv/www/*/logs /srv/www*/tmp /srv/www/*/var 2> /dev/null
  24. printf "Chattr immutable: active\n"
  25. }
  26. disable() {
  27. chattr -R -i /srv/www 2> /dev/null
  28. printf "Chattr immutable: disable\n"
  29. }
  30. launcher() {
  31. case "$arg" in
  32. 1|on|true)
  33. active;
  34. ;;
  35. 0|off|false)
  36. disable;
  37. ;;
  38. *)
  39. clear
  40. N="service ${0##*/}"
  41. echo "Usage: $N 0|off|false to disable immutable systems..." >&2
  42. echo "Usage: $N 1|on|true to active immutable systems..." >&2
  43. exit 1
  44. ;;
  45. esac
  46. }
  47. verify_uid() {
  48. if [ $(id -u) -ne 0 ]; then
  49. printf "[ \\33[1;31m %s \\33[0;39m ] %s \n" "KO" "Need to get rights admins!"
  50. exit 1
  51. fi
  52. }
  53. verify_uid
  54. launcher
  55. #chmod 0500 "${dirname}/$0"