Posted on 03-29-2016 06:18 AM
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?
Posted on 03-29-2016 06:21 AM
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
Posted on 03-29-2016 06:32 AM
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
Posted on 03-29-2016 06:59 AM
Well, let us know how it works out.
Regards,
TJ
Posted on 03-29-2016 07:23 AM
chown is asking for usage chown [-fhv] [-R [-H | -L | -P]] owner[:group] file ... chown [-fhv] [-R [-H | -L | -P]] :group file ...
Posted on 03-29-2016 08:01 AM
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
Posted on 03-29-2016 08:14 AM
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?
Posted on 03-29-2016 09:39 AM
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
Posted on 03-29-2016 10:31 AM
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.
Posted on 03-29-2016 10:43 AM
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
Posted on 03-29-2016 10:46 AM
This is what worked for me:
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
Posted on 03-29-2016 10:49 AM
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.
Posted on 03-29-2016 12:02 PM
You could use the Dock Items feature of the policies...to add stuff to the Dock.
Regards,
TJ
Posted on 03-29-2016 12:19 PM
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
Posted on 03-29-2016 12:23 PM
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