Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in postinstall scripts #8166

Open
MaximKalinin opened this issue Apr 4, 2024 · 11 comments
Open

Regression in postinstall scripts #8166

MaximKalinin opened this issue Apr 4, 2024 · 11 comments

Comments

@MaximKalinin
Copy link

  • Electron-Builder Version: 24.13.3
  • Node Version: 20.10.0
  • Electron Version: 29.1.0
  • Electron Type (current, beta, nightly): current
  • Target: pkg

Postinstall script in pkg target receives wrong $2 argument.

There is a regression in electron-builder or one of its dependencies that was not documented. It first appeared in 24.13.2 version and is still present in the latest version (24.13.3). Specifically, I believe it is related to this modification.

Here is a minimal repository that reproduces the issue: https://github.com/MaximKalinin/electron-builder-test

Steps to reproduce:

# clone the repo

npm install
npm run package

# install the packaged app from dist folder

cat /var/log/test.log

Expected result: the output of the file is /Applications

Actual result: the output of the file is /Applications/electron-builder-test.app

@mmaietta
Copy link
Collaborator

mmaietta commented Apr 4, 2024

Hmmm the post install script never changed, the only change was adding BundlePostInstallScriptPath and BundlePreInstallScriptPath keys and script names to the Info.plist. I'm not familiar with pkg and was only provided guidance on the expected behavior, it shouldn't have changed the $2 arg though AFAICT. What is the impact of the $2 argument not working as it previously was?

If a postinstall script was open -a $2 to autolauch the app, wouldn't /Applications/electron-builder-test.app be the correct arg?

@MaximKalinin
Copy link
Author

What is the impact of the $2 argument not working as it previously was?

I am trying to access files that are placed inside the installed app folder. For that I access "${2}/electron-builder-test.app/resources/". It used to evaluate to "/Applications/electron-builder-test.app/resources/", but now it evaluates to "/Applications/electron-builder-test.app/electron-builder-test.app/resources/" which does not exist.

If a postinstall script was open -a $2 to autolauch the app, wouldn't /Applications/electron-builder-test.app be the correct arg?

The thing is, it used to be open -a "${2}/electron-builder-test.app".

@mmaietta
Copy link
Collaborator

mmaietta commented Apr 5, 2024

I still think it's expected behavior from my quick research
https://stackoverflow.com/a/11636246/3498974

$0 - Script path
$1 - Package path
$2 - Target location
$3 - Target volume`

My guess is that adding BundlePostInstallScriptPath added the proper configuration for the postinstall script to properly run

@MaximKalinin
Copy link
Author

I still think it's expected behavior from my quick research

Does it mean that all the previous versions were working incorrectly, passing /Applications as a second argument?

@mmaietta
Copy link
Collaborator

mmaietta commented Apr 8, 2024

That's my current hypothesis. If you look through the PR code diff, there's nothing setting the path or changing the executable script itself. Rather, it's simply scanning the install scripts directory, identifying any that are preinstall/postinstall and adding that file entry into the Info.plist. It doesn't modify the pkg scripts' arguments itself.

@MaximKalinin
Copy link
Author

What is the manual step for generating .pkg file? If I try pkgbuild --root --scripts --component-plist I will get the expected /Applications as a second argument.

If you look through the PR code diff, there's nothing setting the path or changing the executable script itself.

The bug is not necessarily introduced by this PR, it could just be revealed now.

@MaximKalinin
Copy link
Author

Ok, I think I found the real issue. It actually runs the postinstall script twice. Once for the application and once for the component specified in plist file. This seems like a bug to me.

@mmaietta
Copy link
Collaborator

mmaietta commented Apr 9, 2024

Excellent debugging, thank you! I'll take a look when I have a chance, potentially this week if I can find time after work.

@KaminoRyo
Copy link
Contributor

KaminoRyo commented Apr 18, 2024

@MaximKalinin
@mmaietta
I knew about this problem from a Japanese technical memo.
To summarize,

  • The behavior changes depending on the presence or absence of the file extension of the script (for some reason it runs twice if there is no .sh).
  • If there is no extension, it is determined to be a `top-level postinstall script.'' Isn't this the cause

@KaminoRyo
Copy link
Contributor

related issue: #7299 #8063

@MaximKalinin
There was a problem with the scripts option not working in the first place, and this commit came in.
How did you get postinstall to work until now? Did you create a .app file with electron-builder and create an installer using pkgbuild or productbuild in your own shell?
(Since it wasn't working originally) I would like to know what comparison made it decide that "electron-builder is wrong".
I don't want to criticize you. but I rarely meet people who create pkg installers for Mac, so I'd like to deepen my knowledge.

@MaximKalinin
Copy link
Author

Scripts were working fine for me, you can see it in the test repository: https://github.com/MaximKalinin/electron-builder-test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants