Post-Install Script Woes using defaults write

226 views
Skip to first unread message

Steve Lopez

unread,
Dec 16, 2015, 11:12:58 AM12/16/15
to munki-discuss
Forgive me if this is elementary as I'm still new to all this, especially scripting, but I have searched and searched and tried multiple things with no luck.  I am trying to add some shell scripts to the end of an install using the "defaults write" command, however I am needing the script to write to the users Library/Preferences/ folder.  From what I can gather from searching, Munki runs all the installs and scripts as root, so if I just specify defaults write, it will go to the root users folders.  Is there any way to get a post-install script to write to the current users Library folder?  If anyone wants all the specifics, I can post it all, but didn't want to post unnecessary info if it's not needed.  Thanks again.

Mr. Alan Siu

unread,
Dec 16, 2015, 11:45:29 AM12/16/15
to munki-...@googlegroups.com
I know of at least two ways to get the logged-in user:

Method #1:
actual_user=$(ls -l /dev/console | awk '{ print $3 }')

Method #2:
actual_user=$(defaults read /Library/Preferences/com.apple.loginwindow lastUserName)

And then do something like this:
defaults write /Users/"$actual_user"/Library/Preferences/com.BLAH.BLAH.plist BLAH -bool true
chown $actual_user /Library/Preferences/com.BLAH.BLAH.plist

Are you sure you have to write it directly to the user's preferences directory, and you can't use a profile instead?


Alan Siu
Client Systems Analyst
St. Ignatius College Preparatory

On Wed, Dec 16, 2015 at 7:09 AM, Steve Lopez <lop...@gmail.com> wrote:
Forgive me if this is elementary as I'm still new to all this, especially scripting, but I have searched and searched and tried multiple things with no luck.  I am trying to add some shell scripts to the end of an install using the "defaults write" command, however I am needing the script to write to the users Library/Preferences/ folder.  From what I can gather from searching, Munki runs all the installs and scripts as root, so if I just specify defaults write, it will go to the root users folders.  Is there any way to get a post-install script to write to the current users Library folder?  If anyone wants all the specifics, I can post it all, but didn't want to post unnecessary info if it's not needed.  Thanks again.

--
You received this message because you are subscribed to the Google Groups "munki-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to munki-discus...@googlegroups.com.
To post to this group, send email to munki-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/munki-discuss/a2bdab49-dba6-4073-9bd0-38cd5924ff3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Josh Malone

unread,
Dec 16, 2015, 12:01:39 PM12/16/15
to munki-...@googlegroups.com
Unless there is no logged-in user. What happens then? (Rhetorical question...)

Mr. Alan Siu

unread,
Dec 16, 2015, 12:07:15 PM12/16/15
to munki-...@googlegroups.com
Then you build in an if statement of some kind...

if [ ! -z "$actual_user" ]; then
    defaults write some stuff
else
    whatever else
fi


Alan Siu
Client Systems Analyst
St. Ignatius College Preparatory

Steve Lopez

unread,
Dec 16, 2015, 12:53:16 PM12/16/15
to munki-discuss
Thank you a thousand times Alan!  That worked!  I searched for hours yesterday trying to find something like this.  You are a godsend.

To answer your question, yes it does have to be written to the users preferences and not the global one in /Library.  I might be able to use a profile, but I haven't gotten into configuring our macs using profiles yet.  It's on my list of things to do.  Thanks again.

--Steve

Mike Solin

unread,
Dec 16, 2015, 7:29:10 PM12/16/15
to munki-...@googlegroups.com
I’d use a configuration profile (and deploy that with Munki alongside the application), or use a shell script with outset (and deploy both the shell script and outset with Munki).  That way, the command that you’re running is applied to every user on the computer, regardless if they’re logged in at the time that Munki is running the installation.
Reply all
Reply to author
Forward
0 new messages