locking/atomic: Correct (cmp)xchg() instrumentation
[linux-block.git] / scripts / selinux / install_policy.sh
CommitLineData
93c06cbb 1#!/bin/sh
b2441318 2# SPDX-License-Identifier: GPL-2.0
e37c1877 3set -e
93c06cbb
SH
4if [ `id -u` -ne 0 ]; then
5 echo "$0: must be root to install the selinux policy"
6 exit 1
7fi
e37c1877 8
93c06cbb
SH
9SF=`which setfiles`
10if [ $? -eq 1 ]; then
e37c1877
SS
11 echo "Could not find setfiles"
12 echo "Do you have policycoreutils installed?"
13 exit 1
93c06cbb
SH
14fi
15
93c06cbb 16CP=`which checkpolicy`
e37c1877
SS
17if [ $? -eq 1 ]; then
18 echo "Could not find checkpolicy"
19 echo "Do you have checkpolicy installed?"
20 exit 1
21fi
93c06cbb
SH
22VERS=`$CP -V | awk '{print $1}'`
23
e37c1877
SS
24ENABLED=`which selinuxenabled`
25if [ $? -eq 1 ]; then
26 echo "Could not find selinuxenabled"
27 echo "Do you have libselinux-utils installed?"
28 exit 1
29fi
30
31if selinuxenabled; then
32 echo "SELinux is already enabled"
33 echo "This prevents safely relabeling all files."
2fe2fb4c 34 echo "Boot with selinux=0 on the kernel command-line."
e37c1877
SS
35 exit 1
36fi
37
38cd mdp
39./mdp -m policy.conf file_contexts
40$CP -U allow -M -o policy.$VERS policy.conf
93c06cbb
SH
41
42mkdir -p /etc/selinux/dummy/policy
43mkdir -p /etc/selinux/dummy/contexts/files
44
e37c1877
SS
45echo "__default__:user_u:s0" > /etc/selinux/dummy/seusers
46echo "base_r:base_t:s0" > /etc/selinux/dummy/contexts/failsafe_context
47echo "base_r:base_t:s0 base_r:base_t:s0" > /etc/selinux/dummy/default_contexts
48cat > /etc/selinux/dummy/contexts/x_contexts <<EOF
49client * user_u:base_r:base_t:s0
50property * user_u:object_r:base_t:s0
51extension * user_u:object_r:base_t:s0
52selection * user_u:object_r:base_t:s0
53event * user_u:object_r:base_t:s0
54EOF
55touch /etc/selinux/dummy/contexts/virtual_domain_context
56touch /etc/selinux/dummy/contexts/virtual_image_context
57
93c06cbb
SH
58cp file_contexts /etc/selinux/dummy/contexts/files
59cp dbus_contexts /etc/selinux/dummy/contexts
60cp policy.$VERS /etc/selinux/dummy/policy
61FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts
62
63if [ ! -d /etc/selinux ]; then
64 mkdir -p /etc/selinux
65fi
e37c1877
SS
66if [ -f /etc/selinux/config ]; then
67 echo "/etc/selinux/config exists, moving to /etc/selinux/config.bak."
68 mv /etc/selinux/config /etc/selinux/config.bak
69fi
70echo "Creating new /etc/selinux/config for dummy policy."
71cat > /etc/selinux/config << EOF
72SELINUX=permissive
93c06cbb
SH
73SELINUXTYPE=dummy
74EOF
93c06cbb
SH
75
76cd /etc/selinux/dummy/contexts/files
e37c1877 77$SF -F file_contexts /
93c06cbb 78
e37c1877 79mounts=`cat /proc/$$/mounts | \
c969bb8d 80 grep -E "ext[234]|jfs|xfs|reiserfs|jffs2|gfs2|btrfs|f2fs|ocfs2" | \
e37c1877
SS
81 awk '{ print $2 '}`
82$SF -F file_contexts $mounts
93c06cbb 83
e37c1877 84echo "-F" > /.autorelabel