#!/bin/bash

. ${TOOLKIT}-functions.sh

setcap cap_net_admin=ei /usr/bin/qemu-system-x86_64


file="/etc/security/capability.conf"

[ -f $file ] && {
	grep -q "^cap_net_admin" $file || {
		echo "  adding cap_net_admin to $file"
		echo "#[ku] net admin privs" >>$file
		echo "cap_net_admin root" >>$file
	}
}


# basic structure
#
for name in maindir $(jtconf --listvars kvm_path)
do
	dir=$(jtconf kvm_path.$name)
	create_dir $dir root:root 0770
done


dir="/etc/libvirt/storage"

pools=$(ls -d pools/*.xml /etc/kusa/files/pools/*.xml 2>/dev/null) || :

for pool in $pools
do
	file=$(basename $pool)
	[ -f $dir/$file ] && continue
	export tmp_uuid=$(uuidgen)
	installfile $pool $dir/$file root:root 660
	(cd $dir/autostart ; [ -L $file ] || ln -s ../$file .)
	name=$(basename $pool .xml)
	virsh pool-create $dir/$file
done

##$SOMETHING_CHANGED && {
	##if [ -f /etc/init.d/ku-libvirt ]
	##then
		##restart_service ku-libvirtd
	##else
		##restart_service libvirtd
	##fi
##}

exit 0
