#!/bin/ksh
#
# cpprofile.sh
#
# Shell script to replace all .profiles found in /home with a named file.
#
# John Roebuck - 15/02/2000

if [ $# -ne 1 ]
   then echo " "
        echo "Usage:\t$0  new-profile-file"
        exit 1
fi

tempfile1=/tmp/cpprofile$$$$

find /home -name ".profile" > $tempfile1

while read PROFILES
do

	# Find out owner and group of .profile
	pown=` ls -l $PROFILES | awk '{ print $3 }'`
	pgrp=` ls -l $PROFILES | awk '{ print $4 }'`

	echo "Processing $PROFILES \t\c"
	echo "owner = $pown \t\c"
	echo "group = $pgrp"

	# Copy existing .profile to .profile.saved
	cp $PROFILES $PROFILES.saved

	# Copy new profile-file to .profile
	cp $1 $PROFILES

	# Set permissions on new .profile to those on old .profile
	chmod 740 $PROFILES
	chown $pown $PROFILES
	chgrp $pgrp $PROFILES

done < $tempfile1

rm $tempfile1

