Thursday, September 24, 2009

Install files into user directories

The new LANrev Install Ease application has the ability to create packages that automatically adds files to all current users on your system.

Lets look at doing it the ol' fashioned way....

Using Iceberg makes this easy.  Either install files somewhere on your HD (like the user template located at /System/Library/User Template/English.lproj and inside there is the template of what gets copied to all new users. Lets say you want to install prefs for an application you are pushing out.  Install the pref file at /System/Library/User Template/English.lproj/Library/Preferences then create a text file script that will copy that to all your users.  Lets say the pref file is myapp.plist.

____ 8< snip ________

#!/bin/sh

# get listing of /Users Directory
# and set template locaton

dirs=`ls /Users`
template="/System/Library/User Template/English.lprog"

# now do something for each entry

for dir in $dirs
do
     # exclude /Users/Shared
     if [ "$dirs" != "Shared" ]; then
     cp "$template/Library/Preferences/myapp.plist" "/Users/$dir/Library/Preferences"
     chown $dir:$dir "/Users/$dir/Library/Preferences/myapp.plist"
     chmod 700 "/Users/$dir/Library/Preferences/myapp.plist"
     fi
done

______ 8< snip _______

Take this script and make it a postflight script.  Iceberg will take care of naming it correctly and such for you.

Now, if you simply want to make a quick package to copy stuff you can do this....Make a new dummy package and put the item  you want to copy in the "Resources" section of Iceberg (Iceberg will add it to the Resources folder of your package for you).  Then do a postflight script  which is something like above...


____ 8< snip ________

#!/bin/sh

# get listing of /Users Directory

dirs=`ls /Users`

# now do something for each entry

for dir in $dirs
do
     # exclude /Users/Shared
     if [ "$dirs" != "Shared" ]; then
     cp "$1/Contents/Resources/myapp.plist" "/Users/$dir/Library/Preferences"
     chown $dir:$dir "/Users/$dir/Library/Preferences/myapp.plist"
     chmod 700 "/Users/$dir/Library/Preferences/myapp.plist"
     fi
done
______ 8< snip _______


the $1 indicates the path to the script and then follow the path to the Resources folder.

The chown and chmod commands make sure the file has the correct owner and permissions.

   -Mike