chattr_sys 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/05/12
  12. #
  13. ###
  14. ###
  15. #
  16. # Change attributes system; plz install: heirloom-mailx
  17. #
  18. ###
  19. arg="$1"
  20. dirname="$(dirname $(readlink -f -- "$0"))"
  21. email_to="red@stephane-huc.net" # write your mail, here
  22. email_from="Siou <siou@stephane-huc.net>"
  23. mail=0 # if u wish mail, set to 1
  24. HOST="$(cat /etc/hostname)"
  25. active() {
  26. chattr -R +i /bin /boot /chroot /etc /opt /usr /root /sbin /lib* /initrd* /vmlinuz* 2> /dev/null
  27. chattr -R -i /etc/adjtime /etc/blkid.tab /etc/mtab /etc/network/run /etc/udev/rules.d /var/lib /var/run 2> /dev/null
  28. printf "Chattr immutable: active\n"
  29. }
  30. disable() {
  31. chattr -R -i /bin /boot /chroot /etc /opt /usr /root /sbin /lib* /initrd* /vmlinuz* 2> /dev/null
  32. printf "Chattr immutable: disable\n"
  33. }
  34. send_mail() {
  35. case "$1" in
  36. 1|on|true) mssg="ACTIVE" ;;
  37. 0|off|false) mssg="DISABLE" ;;
  38. esac
  39. [ "$mail" -gt 0 ] && echo "Chattr immutable: ${mssg} on $HOST" | mail -S from="${email_from}" -s "Chattr immutable ~ $HOST" "${email_to}"
  40. sleep 1
  41. unset mssg
  42. }
  43. launcher() {
  44. case "$arg" in
  45. 1|on|true)
  46. active;
  47. send_mail "$arg"
  48. ;;
  49. 0|off|false)
  50. disable;
  51. send_mail "$arg"
  52. ;;
  53. *)
  54. clear
  55. N="service ${0##*/}"
  56. echo "Usage: $N 0|off|false to disable immutable systems..." >&2
  57. echo "Usage: $N 1|on|true to active immutable systems..." >&2
  58. exit 1
  59. ;;
  60. esac
  61. }
  62. verify_uid() {
  63. if [ $(id -u) -ne 0 ]; then
  64. printf "[ \\33[1;31m %s \\33[0;39m ] %s \n" "KO" "Need to get rights admins!"
  65. exit 1
  66. fi
  67. }
  68. verify_uid
  69. launcher