electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.57k stars 1.73k forks source link

Linux deb auto updater doesn't update due wrong install command #8395

Closed Ryan432 closed 1 month ago

Ryan432 commented 1 month ago

The auto updater is not updating correctly on Linux, Ubuntu 22.04.

So, in fact what happening is that when the update is finished to download, I open a dialog, after confirm I am executing the function autoUpdate.quitAndInstall();, then it's requesting for the password for the privilege, quitting the app and reopening but the update didn't happen.

After long investigation, I have found that the install command in electron-updater is wrong and the bash cannot execute it.

Relevant logs:

Executing: /usr/bin/pkexec --disable-internal-agent with args: /bin/bash,-c,dpkg -i /home/username/.cache/app-updater/pending/app-1.0.30-arm64.deb || apt-get install -f -y
Update installer has already been triggered. Quitting application.

Now, if you take the Executing command, you will see that it's not really can be executed as can seen here:

Screenshot 2024-08-04 at 02 47 13

Relevant code: My auto updater implementation.

const showUpdateVersionModal = async ({ version }) => {
    // INFO: MacOS specific, show bouncing app in dock.
    if (process.platform === 'darwin') app.dock.bounce('informational');

    await dialog.showMessageBox(mainWindow, {
        type: 'info',
        title: 'Application Update',
        message: `${version}`,
        detail: 'A new version is available. Restart the application now to apply the updates.',
        buttons: ['Restart']
    });

    autoUpdater.quitAndInstall();
};

const startAutoUpdater = async () => {
    autoUpdater.autoRunAppAfterInstall = true;
    autoUpdater.autoDownload = true;
    autoUpdater.autoInstallOnAppQuit = true;

    setTimeout(() => {
        autoUpdater.checkForUpdatesAndNotify();
    }, 2000);

    const checkUpdatesInterval = setInterval(() => {
        autoUpdater.checkForUpdatesAndNotify();
    }, 10000);

    autoUpdater.on('update-available', async () => {
        clearInterval(checkUpdatesInterval);
    });

    autoUpdater.on('update-downloaded', ({ version, downloadedFile }) => {
        showUpdateVersionModal({ version, downloadedFile });
    });

    autoUpdater.on('error', (_error, message) => {
        autoUpdater.logger.error(message);
    });
};

I found the problem in packages/electron-updater/src/DebUpdater.ts at doInstall function, I fixed it locally, it works, and I am ready to PR, just couldn't find way to open branch & PR.

Here is the function scope after a fix:

  protected doInstall(options: InstallOptions): boolean {
    const sudo = this.wrapSudo()
    const installCommand = `'dpkg -i ${options.installerPath} || apt-get install -f -y'`
    this.spawnSyncLog(sudo, ["/bin/bash", "-c", installCommand])
    if (options.isForceRunAfter) {
      this.app.relaunch()
    }
    return true
  }

After that fix, the auto-updater works correctly with no issues. Would love if will allow me to contribute and push that update asap.

Thank you.

Bug-Reaper commented 1 month ago

@Ryan432 you should be able to:

  1. Fork this repo
  2. Clone your fork
  3. Create a new branch > commit your change > push to your forked repo
  4. PR from the branch on your fork to the main-repo

Lmk if that works for you

Ryan432 commented 1 month ago

@Bug-Reaper Thanks for explaining, I have just opened PR, you can find it here: https://github.com/electron-userland/electron-builder/pull/8400

Is there any ETA to when you will be able to release that update? Or can you suggest a way where I can already have a "beta" release of my fix so I can use that right now?

Thank you,

xyloflake commented 1 month ago

@Bug-Reaper Thanks for explaining, I have just opened PR, you can find it here: #8400

Is there any ETA to when you will be able to release that update? Or can you suggest a way where I can already have a "beta" release of my fix so I can use that right now?

Thank you,

@mmaietta is the maintainer, not @Bug-Reaper. You can take a look at the existing PRs to figure out when it will be merged. If you ask me, it's about 3 to 4 days.

Ryan432 commented 1 month ago

@xyloflake Thanks.

@mmaietta Would love if you can look into it :)

xyloflake commented 1 month ago

@xyloflake Thanks.

@mmaietta Would love if you can look into it :)

I think he's on a vacation. Btw, autoupdates work fine for the .deb target in the app I work on. You can verify through the betas. Please note that the betas don't have an UI rn for the the autoupdates. You'll have to open muffon through the terminal to have a look at the log.

None of our users have a problem with the autoupdates.

xyloflake commented 1 month ago

@Bug-Reaper Thanks for explaining, I have just opened PR, you can find it here: https://github.com/electron-userland/electron-builder/pull/8400

Is there any ETA to when you will be able to release that update? Or can you suggest a way where I can already have a "beta" release of my fix so I can use that right now?

Thank you,

If you want this to immediately work for your app, create a patch. I'd recommend using pnpm patches. v25s are in alphas rn.

Ryan432 commented 1 month ago

Weird that it works on your app, I have tried in multiple linux pcs and it never worked.

I will wait for the publish and build with a local package for now.

xyloflake commented 1 month ago

Now, if you take the Executing command, you will see that it's not really can be executed as can seen here: Screenshot 2024-08-04 at 02 47 13

@Ryan432 that's because you're running the command with no quotes after /usr/bin/pkexec.

Ryan432 commented 1 month ago

That command was made by DebUpdater.js, not me, I copied that command to present the issue.

Of course with single quote it works and that exactly my fix.

xyloflake commented 1 month ago

@Ryan432 how are you determining that what you're executing was exactly what electron-updater was running?

I simulated a similar environment and it generates those quotes for me.

Ryan432 commented 1 month ago

I determine it by application logs when running the app through the terminal. The function spawnSyncLog prints before executing.

xyloflake commented 1 month ago

I determine it by application logs when running the app through the terminal. The function spawnSyncLog prints before executing.

The logs don't show the single quotes either for me, but patching with a console.log prints the entire command with the single quotes.

xyloflake commented 1 month ago

@Ryan432 congratulations on getting the PR merged! I think you can close this now 😄

Once again, nice work, thank you for your contribution!!

Ryan432 commented 1 month ago

@Ryan432 congratulations on getting the PR merged! I think you can close this now 😄

Once again, nice work, thank you for your contribution!!

Issue is closed, thank you :)