PackageMaker v the home directory

So, it turns out that if you want to use a shell script in PackageMaker (say the post-installation ‘postflight’ script file), if you try referring to the user’s home directory using ‘~’ you wind up referring to a directory at the root level (ie /~/blah), which is invariably what you don’t want. The solution referred to on the Apple discussion boards is to create a shell script that moves everything to the home directory then execute that from the install script.

So we start by getting the username. But of course, the postflight script is running under sudo so it’s username probably isn’t the same as the logged in user.

>sudo id -p
Password:
login   testuser
uid     root
groups  wheel daemon kmem sys tty certusers operator admin staff

Looks like the ‘login’ line is the one we want, and we can get it using grep.

>sudo id -p | grep login
Password:
login        testuser

But we need the second column (ie just “testuser” rather than “login testuser”). awk lets us get at the second column using

>sudo id -p | grep login | awk '{print $2}'
testuser

In the end you could try something along the lines of the following in your PackageMaker postflight script. Note that the backticks “ evaluate the expression contained within them.

set username="blah" # otherwise bash seems to whinge that username is undefined on the next line
username="`sudo id -p | grep login | awk '{print $2}'`"
mv whatever /Users/$username/wherever/

This seems to work as long as you’re not doing the install via Apple Remote Desktop’s Install Package option. Because if you do that the user is root and the package probably can’t be meaningfully installed in root’s home directory. The only solution I could come up with is to install your files in a location that’s commonly accessible to all users.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg
  • Ma.gnolia
  • NewsVine
  • Reddit
  • RawSugar

Related posts:

  1. Mac LoJack It started with this script to use the Mac’s inbuilt...
  2. Things you can authorize in Leopard A look in /etc/authorization reveals some interesting things that can...
  3. Phone home Combining AppleScripting the Indigo home automation software with an Asterisk...
  4. How to backup your MySQL database to a GMail account So, you’ve got a MySQL database on your machine, and...
  5. Installing clamav-0.93 on Mac OS X If you’ve got the latest Apple Developer tools installed, you’ll...

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply

  • JoyOfTech

  • Recent Comments

  • Was it useful? Was it funny? Was it weird? Please tip the author!
  • airport apple apple_store apple_tv apple_university_consortium auc Australia Backup blackberry cocoa dantz emc fink Firewire flickr game iMac iPhone iphone_3g iphone_3gs iPhoto iPod ipod_nano ipod_touch iTunes java job keynote leopard Mac MacBook macbook_air macbook_pro macjob MacWorld macworld_2008 mac_os_x music retrospect safari Security steve_jobs time_capsule time_machine WWDC
  • Pages

  • Archives

  • Meta