Posted on 02-14-2020 10:57 AM
I need to package and deploy a file to all users on a system.
lets call the file 'Awesome.txt'.
I need to send that out as a package file and then have 'Awesome.txt' copied to every local users ~/Library directory (to be clear /Users/USERNAME/Library/Awesome.txt)
I also need it to overwrite the file if its already there.
What is the best way to achieve this result?
Thanks in advance to all!
Solved! Go to Solution.
Posted on 02-17-2020 12:59 PM
I would create a .dmg in composer and use the Fill Existing Users (FEU) option when you deploy it.
So with this method if you create a file in the filepath /Users/USERNAME/Library/Awesome.txt then FEU will drop it into ever user account in the /Users/ directory.
I use this method with a few .plists for our new user setup.
Posted on 02-17-2020 07:56 AM
This depends a bit on what Awesome.txt really is, and how often you want to update it. Also the resources you have available will make a difference too.
For me, if it is something I will want to change often, I would store the file on a Sharepoint that I can auto mount via script. I have one of these and a script that runs at regular intervals, that I use for this very thing to update scripts and Apps that may need to be updated often. I would just add in a line to copy the file into place. This will just get the file to a location for access by a script.
Without a Sharepoint, I would set up a safe store point location on the Mac, put the file in there and run a post install script to put it in place in all existing accounts, and set permissions for the file to be correct. Use Composer for this.
Now comes your problem, how to sort out new accounts that don’t yet exist. You have a couple of options here…
1. Add the file to the UserTemplate - not recommended by Apple, and possibly will run into a SIP issue It might work for now if you try it, but may stop working at some point.
2. Create a LaunchAgent to copy the file across at login for each user. Put in a simple check for the copy of the file existing already. The Agent runs a script which will check for the file and then copy it across if required. This is my preferred method and I run a LaunchAgent at log in for for all accounts.
Posted on 02-17-2020 12:59 PM
I would create a .dmg in composer and use the Fill Existing Users (FEU) option when you deploy it.
So with this method if you create a file in the filepath /Users/USERNAME/Library/Awesome.txt then FEU will drop it into ever user account in the /Users/ directory.
I use this method with a few .plists for our new user setup.
Posted on 02-17-2020 04:42 PM
Just a note. If using composer for FEU, make sure you use .dmg. You could use .pkg but would need to utilize an installer script to get the file into the user library.
All of the above answers can be reasonable for different uses. Like anything, it all depends.
Posted on 03-04-2020 08:26 AM
Thanks @strayer
Posted on 02-14-2022 10:11 PM
Besides DMG package deployment, another option to deploy a text file is to use a script.
#!/bin/bash
# Find the loggedInUser
LOGGED_IN_USER=$(stat -f %Su /dev/console)
cat << EOF > "/Users/${LOGGED_IN_USER}/Library/Awesome.txt"
your-awesome-txt-file-content-here
EOF
#Fix permissions
chown "$LOGGED_IN_USER" /Users/${LOGGED_IN_USER}/Library/Awesome.txt