install_policy.sh 1.7 KB

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