#!/bin/sh
set -e

if [ "$1" != "" ]; then
  SELINUXTYPE="$1"
else
  . /etc/selinux/config
fi

cd /usr/share/selinux/${SELINUXTYPE}

echo "Updating \"${SELINUXTYPE}\" policy"

# remove obsolete modules
for n in procmail tmpreaper ; do
  semodule -l |grep -q $n && semodule -r $n
done

semodule -b $(test -e base.pp && echo base.pp || echo base.pp.bz2) $(for n in $(semodule -s ${SELINUXTYPE} -l | cut -f1); do
  if [ -e $n.pp ]; then
    echo -n " -i $n.pp"
  else
      if [ -e $n.pp.bz2 ]; then
	  echo -n " -i $n.pp.bz2"
      fi
  fi
done
)
