install_policy.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh
  2. if [ `id -u` -ne 0 ]; then
  3. echo "$0: must be root to install the selinux policy"
  4. exit 1
  5. fi
  6. SF=`which setfiles`
  7. if [ $? -eq 1 ]; then
  8. if [ -f /sbin/setfiles ]; then
  9. SF="/usr/setfiles"
  10. else
  11. echo "no selinux tools installed: setfiles"
  12. exit 1
  13. fi
  14. fi
  15. cd mdp
  16. CP=`which checkpolicy`
  17. VERS=`$CP -V | awk '{print $1}'`
  18. ./mdp policy.conf file_contexts
  19. $CP -o policy.$VERS policy.conf
  20. mkdir -p /etc/selinux/dummy/policy
  21. mkdir -p /etc/selinux/dummy/contexts/files
  22. cp file_contexts /etc/selinux/dummy/contexts/files
  23. cp dbus_contexts /etc/selinux/dummy/contexts
  24. cp policy.$VERS /etc/selinux/dummy/policy
  25. FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts
  26. if [ ! -d /etc/selinux ]; then
  27. mkdir -p /etc/selinux
  28. fi
  29. if [ ! -f /etc/selinux/config ]; then
  30. cat > /etc/selinux/config << EOF
  31. SELINUX=enforcing
  32. SELINUXTYPE=dummy
  33. EOF
  34. else
  35. TYPE=`cat /etc/selinux/config | grep "^SELINUXTYPE" | tail -1 | awk -F= '{ print $2 '}`
  36. if [ "eq$TYPE" != "eqdummy" ]; then
  37. selinuxenabled
  38. if [ $? -eq 0 ]; then
  39. echo "SELinux already enabled with a non-dummy policy."
  40. echo "Exiting. Please install policy by hand if that"
  41. echo "is what you REALLY want."
  42. exit 1
  43. fi
  44. mv /etc/selinux/config /etc/selinux/config.mdpbak
  45. grep -v "^SELINUXTYPE" /etc/selinux/config.mdpbak >> /etc/selinux/config
  46. echo "SELINUXTYPE=dummy" >> /etc/selinux/config
  47. fi
  48. fi
  49. cd /etc/selinux/dummy/contexts/files
  50. $SF file_contexts /
  51. mounts=`cat /proc/$$/mounts | egrep "ext2|ext3|xfs|jfs|ext4|ext4dev|gfs2" | awk '{ print $2 '}`
  52. $SF file_contexts $mounts
  53. dodev=`cat /proc/$$/mounts | grep "/dev "`
  54. if [ "eq$dodev" != "eq" ]; then
  55. mount --move /dev /mnt
  56. $SF file_contexts /dev
  57. mount --move /mnt /dev
  58. fi