#!/bin/sh

# This script must be called from a udev rule and assumes the udev environment
# variables.

# Do not touch the device if it is already labelled is libvirt image. It will
# probably be a fixed_disk_t or it may have no selinux label.
if /usr/bin/ls -Z "$DEVNAME" | \
    /usr/bin/grep -q -E ":svirt_content_t:|:svirt_image_t:"; then
    exit 0
fi

echo "Changing selinux type to svirt_image_t on $DEVNAME" >&2
/usr/bin/chcon -t svirt_image_t "$DEVNAME"
