fe4247
#!/bin/bash
fe4247
#===============================================================================
fe4247
#
fe4247
#          FILE: selinux-policy-migrate-local-changes.sh
fe4247
# 
fe4247
#         USAGE: ./selinux-policy-migrate-local-changes.sh <POLICYTYPE>
fe4247
# 
fe4247
#   DESCRIPTION: This script migrates local changes from pre-2.4 SELinux modules
fe4247
#                store structure to the new structure
fe4247
# 
fe4247
#        AUTHOR: Petr Lautrbach <plautrba@redhat.com>
fe4247
#===============================================================================
fe4247
fe4247
if [ ! -f /etc/selinux/config ]; then
fe4247
    SELINUXTYPE=none
fe4247
else
fe4247
    source /etc/selinux/config
fe4247
fi
fe4247
fe4247
REBUILD=0
fe4247
MIGRATE_SELINUXTYPE=$1
fe4247
fe4247
for local in booleans.local file_contexts.local ports.local users_extra.local users.local; do
fe4247
    if [ -e /etc/selinux/$MIGRATE_SELINUXTYPE/modules/active/$local ]; then
fe4247
        REBUILD=1
fe4247
        cp -v --preserve=mode,ownership,timestamps,links /etc/selinux/$MIGRATE_SELINUXTYPE/modules/active/$local /etc/selinux/$MIGRATE_SELINUXTYPE/active/$local
fe4247
    fi
fe4247
done
fe4247
if [ -e /etc/selinux/$MIGRATE_SELINUXTYPE/modules/active/seusers ]; then
fe4247
    REBUILD=1
fe4247
    cp -v --preserve=mode,ownership,timestamps,links /etc/selinux/$MIGRATE_SELINUXTYPE/modules/active/seusers /etc/selinux/$MIGRATE_SELINUXTYPE/active/seusers.local
fe4247
fi
fe4247
fe4247
INSTALL_MODULES=""
fe4247
for i in `find /etc/selinux/$MIGRATE_SELINUXTYPE/modules/active/modules/ -name \*disabled 2> /dev/null`; do
fe4247
    module=`basename $i | sed 's/\.pp\.disabled$//'`
fe4247
    if [ $module == "pkcsslotd" ] || [ $module == "vbetool" ] || [ $module == "ctdbd" ] || [ $module == "docker" ] || [ $module == "gear" ]; then
fe4247
        continue
fe4247
    fi
fe4247
    if [ -d /etc/selinux/$MIGRATE_SELINUXTYPE/active/modules/100/$module ]; then
fe4247
        touch /etc/selinux/$MIGRATE_SELINUXTYPE/active/modules/disabled/$module
fe4247
    fi
fe4247
done
fe4247
for i in `find /etc/selinux/$MIGRATE_SELINUXTYPE/modules/active/modules/ -name \*.pp 2> /dev/null`; do
fe4247
    module=`basename $i | sed 's/\.pp$//'`
fe4247
    if [ $module == "pkcsslotd" ] || [ $module == "vbetool" ] || [ $module == "ctdbd" ] || [ $module == "docker" ] || [ $module == "gear" ]; then
fe4247
        continue
fe4247
    fi
fe4247
    if [ ! -d /etc/selinux/$MIGRATE_SELINUXTYPE/active/modules/100/$module ]; then
fe4247
        INSTALL_MODULES="${INSTALL_MODULES} $i"
fe4247
    fi
fe4247
done
fe4247
if [ -n "$INSTALL_MODULES" ]; then
fe4247
    semodule -s $MIGRATE_SELINUXTYPE -n -X 400 -i $INSTALL_MODULES
fe4247
    REBUILD=1
fe4247
fi
fe4247
fe4247
cat > /etc/selinux/$MIGRATE_SELINUXTYPE/modules/active/README.migrated <
fe4247
Your old modules store and local changes were migrated to the new structure in
fe4247
in the following directory:
fe4247
fe4247
/etc/selinux/$MIGRATE_SELINUXTYPE/active
fe4247
fe4247
WARNING: Do not remove this file or remove /etc/selinux/$MIGRATE_SELINUXTYPE/modules
fe4247
completely if you are confident that you don't need old files anymore.
fe4247
EOF
fe4247
fe4247
if [ ${DONT_REBUILD:-0} = 0 -a $REBUILD = 1 ]; then
fe4247
    semodule -B -n -s $MIGRATE_SELINUXTYPE
fe4247
    if [ "$MIGRATE_SELINUXTYPE" = "$SELINUXTYPE" ] && selinuxenabled; then
fe4247
        load_policy
fe4247
        if [ -x /usr/sbin/semanage ]; then
fe4247
            /usr/sbin/semanage export | /usr/sbin/semanage import
fe4247
        fi
fe4247
    fi
fe4247
fi