Script partially not working

Hello, this is driving me mad. I have a simple script:

#!/bin/bash
mkdir /Library/folder
cp file.plist /Library/Folder

“folder” is created but file.plist is not copied inside.
No matter when I tell to execute the script.
I put file.plist in the script folder together with the .sh

MDS 3.6
Big Sur

Thanks

try with a trailing slash:

cp file.plist /Library/Folder/

Tried, no luck.
I checked in /var/log/install.log and I found the following:

package_script_service[330]: ./postinstall: cp: file.plist: No such file or directory

It seems the script is not finding the file. It’s in the scripts folder together with the sh.
I tried also ./file.plist but it does not work either.

I also struggled with this until I had a look at the sample scripts. They find the current directory (where the scripts are) and save it as a variable.

BASENAME=${0##*/}
SCRIPTDIR=${0%$BASENAME}

Your cp command should then look like this

cp "${SCRIPTDIR}/file.plist" "/Library/Folder/"

After using this method I never had any problem with copying or file paths in general on my MDS drive.

#!/bin/bash
BASENAME=${0##*/}
SCRIPTDIR=${0%$BASENAME}
mkdir /Library/folder
cp "${SCRIPTDIR}/file.plist" "/Library/folder/"

/var/log/install.log says:

cp> .//file.plist: No such file or directory
(please notice the double slash this time)

it seems those variables are empty

I found this https://bitbucket.org/twocanoes/macdeploystick/issues/541/sample-scripts-relative-path-issue-for
can it be related somehow?

This is a shot in the dark, but assuming I am understanding the behavior described in Issue #541 correctly, and the working directory is the script directory when running, you could try cp ../*/file.plist "/Library/folder/"

This means go up one directory (../) and then within any of those subdirectories (*), copy any files named file.plist to the specified location.

There are other unknowns here though. Does MDS delete the script files immediately after they have been executed? If so, file.plist may no longer exist by the time your script runs. If the files are not deleted immediately, you would also need to be sure that your file.plist “script” is set to run before the script that is expecting that file to exist, which I believe can be done by setting the order in the Scripts popover in MDS.

Seems like it may be valuable for MDS to add an option to copy resources to a defined location that scripts can reference with a variable set by MDS.

Also, I am making guesses and assumptions here without any testing or certainty of how MDS is copying these files. Sorry if I’m way off here.

Thanks for your try, but it still does not work. Tried putting the script file before and after the plist file, tried during the workflow, before the packages and after the packages… nothing to do. The fact is that I have a .dmg built by my former colleague with the same version of MDS, but with Catalina, and it was working like a charm! So my questions would be

  1. is there a way from the working .dmg to understand how the file copy has been configured? I guess I cannot access the script nor the configuration, right?
  2. isn’t there another way with MDS to copy a file in a certain location? I find it a quite common need…

Thanks

I found the answer in one of the videos in the Twocanoes channel on Youtube.
I created a folder “Resources” inside the “Scripts” folder and placed the file to be copied there.

Awesome! Thank sounds perfect.

Would you mind sharing the link to that video?