#!/bin/sh -e
#
# update-selinux-config
#
#   Modifies the system's SELinux configuration file to point to the
#   given policy.
#
# Copyright (C) 2008 Tresys Technology <selinux@tresys.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA  02110-1301 USA.

set -e

configfile=/etc/selinux/config

if [ -z "$1" ]; then
  echo "Usage: update-selinux-config <POLICYTYPE>"
  exit 1
fi

echo "Updating $configfile."
if [ ! -e $configfile ] ; then
  /usr/bin/install -m644 -D /usr/share/selinux/config.example $configfile
fi
/bin/sed -i "s/^SELINUXTYPE=.*/SELINUXTYPE=$1/" $configfile
