Post Install Script of Application Support files.

KyleEricson
Valued Contributor II

I have a application i built with Winetools. For this app to get settings it has a Application Support folder. I try to build the package and have this folder sit in /tmp. Then Postinstall sh to copy this to Current users Application Support. The app doesn't work as this folder doesn't seem to get the right permissions.
I have tried ditto and cp both seem to have the same permission issue. Is there a better folder or way of coping this to the current users Application Support folder?

Read My Blog: https://www.ericsontech.com
14 REPLIES 14

tthurman
Contributor III

Why not use chmod and chown afterwards on the folder?

Something to the extent of:

#!/bin/sh

currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

cp -r /tmp/FolderName  /Users/$currentUser/Library/Application Support/

chown $currentUser /Users/$currentUser/Library/Application Support/FolderName

KyleEricson
Valued Contributor II

Trying this now.

currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

cp -r /tmp/com.truemfg.kronos_14162498748350 Users/$currentUser/Library/Application Support/com.truemfg.kronos_14162498748350

chown $currentUser /Users/$currentUser/Library/Application Support/com.truemfg.kronos_14162498748350

Read My Blog: https://www.ericsontech.com

tthurman
Contributor III

Well, let us know how it works out.

Regards,
TJ

KyleEricson
Valued Contributor II

chown is asking for usage chown [-fhv] [-R [-H | -L | -P]] owner[:group] file ... chown [-fhv] [-R [-H | -L | -P]] :group file ...

Read My Blog: https://www.ericsontech.com

KyleEricson
Valued Contributor II

The above didn't work. Tried this and it fails too.
It works in terminal

currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

ditto /Users/Shared/com.truemfg.kronos_14162498748350 ~/Library/Application Support/com.truemfg.kronos_14162498748350

chown $currentUser ~/Library/Application Support/com.truemfg.kronos_14162498748350

Read My Blog: https://www.ericsontech.com

ega
Contributor III

Unless you need per user support, just use composer to build a dmg installer putting the folder in /Library/Application Support . Also have you tried to create an installer and use the Fill existing user home directories (FEU) option?

KyleEricson
Valued Contributor II

I need it per user. Is there a better folder to store my com.truemfg folder in than tmp/ or /Share?
Where I wouldn't need chown

Read My Blog: https://www.ericsontech.com

tthurman
Contributor III

@kericson

You may need a sudo in front of the chown command.

You're definitely going to want to copy it to /Users/$currentUser/

You might be able to use FUT and FUE with the file to make it copy to the user directory. (If you compose it to drop it in Application Support.)

Let me write up a test script.

tthurman
Contributor III

Below is the test script. I used different variables for testing (this is not actually needed.)

Test it out and see if you can get it working. I use sudo to make sure the commands work.

#!/bin/sh

############
#Test Script
############
#create temp file in /tmp
sudo touch /tmp/TestFile

#get current user logged in.
currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

#copy the file from /tmp to Application Support.
#if it's a directory that needs to be copied, add a -r
sudo cp /tmp/TestFile /Users/$currentUser/Library/Application Support/

#get first owner of the file.
firstOwner=$(ls -la /Users/$currentUser/Library/Application Support/ | grep TestFile | awk '{print $3}')
echo $firstOwner

#change owner for testing.
sudo chown root /Users/$currentUser/Library/Application Support/TestFile

#get second owner
secondOwner=$(ls -la /Users/$currentUser/Library/Application Support/ | grep TestFile | awk '{print $3}')
echo $secondOwner

#set new owner (current user)
sudo chown $currentUser /Users/$currentUser/Library/Application Support/TestFile

#get final user
owner=$(ls -la /Users/$currentUser/Library/Application Support/ | grep TestFile | awk '{print $3}')
echo $owner

KyleEricson
Valued Contributor II

This is what worked for me:

!/bin/sh

postinstall

loggedInUser=/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'

ditto /Users/Shared/com.truemfg.kronos_14162498748350 ~/Library/Application Support/com.truemfg.kronos_14162498748350

chown $loggedInUser:admin ~/Library/Application Support/com.truemfg.kronos_14162498748350

Read My Blog: https://www.ericsontech.com

KyleEricson
Valued Contributor II

Could this loggedInUser= be used to run an add dock icons at the end of a install for example.
I have Office 2016 and I want the app to be added at the end of the install. When I run my current script it does it for root not current user.

Read My Blog: https://www.ericsontech.com

tthurman
Contributor III

You could use the Dock Items feature of the policies...to add stuff to the Dock.

Regards,
TJ

KyleEricson
Valued Contributor II

I used this and it worked for the dock.

user=ls -la /dev/console | cut -d " " -f 4
and then ```
sudo -u $user <command>

sudo -u $user defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Microsoft Outlook.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'

sudo -u $user defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Microsoft Word.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'

sudo -u $user defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Microsoft PowerPoint.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'

sudo -u $user defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Microsoft Excel.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'

sudo -u $user defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Microsoft OneNote.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'

sudo -u $user defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Microsoft Lync.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'

sudo -u $user sudo killall Dock

Read My Blog: https://www.ericsontech.com

tthurman
Contributor III

That works.

For future reference, if you use three ticks ``` on both sides of a script, it will format it accordingly.

Also, single ticks ` around a word it will format it as a command.

Regards,
TJ