Copy plist file for filemakerpro

KyleEricson
Valued Contributor II

I am having an issue coping a file into the current user Library/Preferences See below I have tried replacing the cp with mv,ditto and sudo in front
I have also tried putting the file in /tmp
Are post install scripts able to run sudo commands?

!/bin/sh

postinstall

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

cp /Users/Shared/com.filemaker.client.pro12.plist /Users/$USER/Library/Preferences/com.filemaker.client.pro12.plist

chown -R $loggedInUser:staff /Users/$USER/Library/Preferences/com.filemaker.client.pro12.plist

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

stevewood
Honored Contributor II
Honored Contributor II

@kericson you are not using the loggedInUser variable to get the path. Change $USER to ${loggedInUser} in the two spots where you've used it.

donmontalvo
Esteemed Contributor III

Would be easier to vet the commands if OP uses ">_" formatting icon when posting the script. :)

Shouldn't this:

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

Be this?

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

PS, ok, OP may have used the tics, since the posted script is mangled, the ticks seem to have formatted that portion.

Don

--
https://donmontalvo.com

KyleEricson
Valued Contributor II

I changed it to this and same result.

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

cp /Users/Shared/com.filemaker.client.pro12.plist /Users/$loggedInUser/Library/Preferences/com.filemaker.client.pro12.plist

chown -R $loggedInUser:staff /Users/$loggedInUser/Library/Preferences/com.filemaker.client.pro12.plist

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

mm2270
Legendary Contributor III

@donmontalvo The OP may have had the backticks in the post, but they get translated into the script code format here unless the entire script gets surrounded in the script tags.

@kericson Please highlight your script after its pasted in and click the button directly above the posting field that looks like >_ This will surround the script in the script tags and format it so we can actually see it as a script.

As for having trouble with this process, can you be a little more detailed? Is the plist being copied into place, but FileMaker isn't recognizing it? Or is the plist not being copied at all? These would be 2 separate problems, so its important to understand what issue you're observing.

stevewood
Honored Contributor II
Honored Contributor II

@kericson first, as @donmontalvo pointed out, when posting scripts, use the script formatting icon in the "Post Response" icon bar. That icon is the ">_" icon. That will format the script properly and not drop out important pieces like the grave tick (or back tick).

Try the following script from the terminal before putting it in as a postinstall script:

#!/bin/sh

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

cp /Users/Shared/com.filemaker.client.pro12.plist /Users/${loggedInUser}/Library/Preferences/
chown ${loggedInUser}:staff /Users/${loggedInUser}/Library/Preferences/com.filemaker.pro12.plist

KyleEricson
Valued Contributor II
#!/bin/sh
cp /Users/Shared/com.filemaker.client.pro12.plist /Users/${loggedInUser}/Library/Preferences/
Auto-VM-1:~ administrator$ chown ${loggedInUser}:staff /Users/${loggedInUser}/Library/Preferences/com.filemaker.pro12.plist
chown: /Users/administrator/Library/Preferences/com.filemaker.pro12.plist: No such file or directory

It copied it but can't chown it. This only worked in terminal.

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

stevewood
Honored Contributor II
Honored Contributor II

@kericson sorry, but I made a typo in the chown line. I had the wrong file name for the plist. Edit the script to change the plist file name. Should be:

chown ${loggedInUser}:staff /Users/${loggedInUser}/Library/Preferences/com.filemaker.client.pro12.plist

Try that again in Terminal and then if that works go ahead and try as a postimage script.

KyleEricson
Valued Contributor II

I tested this in Terminal and works great. Will not work as a postinstall script. I have tried to remove the full path too /Users/$loggedInUser/Library/Preferences/com.filemaker.client.pro12.plist
to /Users/$loggedInUser/Library/Preferences/

#!/bin/sh

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

cp /Users/Shared/com.filemaker.client.pro12.plist /Users/$loggedInUser/Library/Preferences/com.filemaker.client.pro12.plist

exit 0      ## Success
exit 1      ## Failure
Read My Blog: https://www.ericsontech.com

stevewood
Honored Contributor II
Honored Contributor II

@kericson is the plist file being left in the /Users/Shared folder? Any errors in /var/log/install.log or system.log?

KyleEricson
Valued Contributor II

Yes it's being left and no i can't find any errors in the log.

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

stevewood
Honored Contributor II
Honored Contributor II

@kericson well, I would probably do some logging in the script to see what is going on. Could do that with adding something like this:

#!/bin/bash
# logging functions courtesy Dan Snelson
# Logging variables
    logFile="/Users/Shared/com.test.log"
    alias now="date '+%Y-%m-%d %H:%M:%S'"
#
# Check for / create logFile
    if [ ! -f "${logFile}" ]; then
        ### logFile not found; Create logFile
        /usr/bin/touch "${logFile}"
    fi
# Save standard output and standard error
    exec 3>&1 4>&2
# Redirect standard output to logFile
    exec 1>>"${logFile}"
# Redirect standard error to logFile
    exec 2>>"${logFile}"
set -xv; exec 1>"${logFile}" 2>&1

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

cp /Users/Shared/com.filemaker.client.pro12.plist /Users/$loggedInUser/Library/Preferences/com.filemaker.client.pro12.plist

The logging functions are courtesy of @dan.snelson but they should drop that log file into /Users/Shared for you to see what is going on in the script, assuming it is running.

You could also take the script out of the package and instead put it into the JSS and run it as an After script. That would take the package out of the mix.

KyleEricson
Valued Contributor II

The first 4 lines were not in my script added them back and it worked.

#!/bin/sh
## postinstall

pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3


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

cp /Users/Shared/com.filemaker.client.pro12.plist /Users/${loggedInUser}/Library/Preferences/

exit 0      ## Success
exit 1      ## Failure
Read My Blog: https://www.ericsontech.com