I have been in a few scenarios where we need to deploy a package and put a file into the home folder of each user on the target system. Of course if we are using Casper we can just create a DMG package and use the “fill existing users” option. The below script gives you a way of doing this if you don’t have Casper deploying the package.
We start off by deploying the app / software via the package as normal. In this example we put the file we want to end up in the users home folders in /tmp. We then use a while loop to copy the file into each users home folder (excluding the Shared and Guest directories):
#!/bin/sh
fileName="/tmp/yourfilename"
# Sets the file name as a variable
counter=`ls /Users | grep -v Shared | grep -v Guest | grep -v .localized | grep -v .DS_Store | grep -c "[A-z 0-9]"`
# Outputs the number of folders in the /Users directory, excluding the Shared & Guest directories
# Loop start
while [ $counter -ne 0 ]
do
targetFolder=`ls /Users | grep -v Shared | grep -v Guest | grep -v .localized | grep -v .DS_Store | grep "[A-z 0-9]" | head -$counter | tail -1`
# Gets the target folder name (there’s probably a better way to do this but it works!)
cp $fileName /Users/$targetFolder/Desktop/
# Copies the file into place
chown $targetFolder /Users/$targetFolder/Library/Preferences/ByHost/com.apple.QuickTime.$uuid.plist
# Set the correct owner on the file
counter=$(( $counter - 1 ))
# Reduces the counter by 1
done
exit 0