#!/bin/bash

if [ $# != 1 ]; then
	echo "usage: $0 /file_path"
	exit 3
fi

FC=$1

if ! [ -f $FC ]; then
	echo "Error: $FC doesn't exist (not a file)"
	exit 4
fi

echo "*** Copying $FC to all chroots..."

chrdirs=`find /chroot/ -mindepth 1 -maxdepth 1 -type d`

for chrdir in $chrdirs; do

	dn=`dirname $FC`
	if [ -d ${chrdir}/${dn} ]; then
		echo "*** Target: $chrdir"
		cp $FC ${chrdir}/${dn}/
	else
		echo "WARN: $chrdir/$dn doesn't exist, not copying"
	fi

done

exit 0
