Electron-builder: Post Install Script, Building .deb

Created on 9 Sep 2017  Â·  9Comments  Â·  Source: electron-userland/electron-builder

  • Version: 19.27.7
  • Target: Linux .deb

Very simple question here but, is there a possibility of running a post install script on Linux? From some quick research, it appears that the .deb package supports this but, I'm not really sure how to utilize it with electron-builder. Ref: https://askubuntu.com/questions/62534/adding-post-deb-install-scripts

I tried creating s script called 'postinst' in the build directory but, it did not appear to execute when the application was installed. (And yes, it is executable).

Is there something simple I'm missing here? Or is this just not supported directly by electron-builder.
Thanks for the help!

Related piece of 'package.json'

"linux": {
         "icon": "...",
      "category": "Utility",
      "depends": ["..."],
      "target": [
        "deb"
      ]
    },
linux question

Most helpful comment

Can we please actually have the options documented without having to read the electron-builder sources? It's been a year.

All 9 comments

https://www.electron.build/configuration/deb#DebOptions-afterInstall

afterInstall in the deb. Relative to project dir path to file like https://github.com/electron-userland/electron-builder/blob/master/packages/electron-builder/templates/linux/after-install.tpl

Sorry, it is not yet properly documented.

Thanks! Yeah, I just found that one myself, I had just put it in the incorrect place.

I had just put it in the incorrect place.

Where?

Reason why it is not documented — because we promote AppImage :) And I feel that afterInstall is too low-level. But yes — should be documented.

I had afterInstall listed under the "linux" part of package.json instead of in the "deb" section, which gave me an error.

Oook, it seems that we need to restore old behavior and allow to specify these options in the linux as before. Because applicable for any FPM target.

I am a beginner. but I just successfully implement it.

this is build section on my _base_dir/package.json

"build": {
    "appId": "org.develar.ElectronReact",
    "category": "public.app-category.tools",
    "dmg": {
      "contents": [
        {
          "x": 410,
          "y": 150,
          "type": "link",
          "path": "/Applications"
        },
        {
          "x": 130,
          "y": 150,
          "type": "file"
        }
      ]
    },
    "files": [
      "dist/",
      "node_modules/",
      "app.html",
      "main.js",
      "main.js.map",
      "package.json"
    ],
    "extraFiles": [
      "assets/"
    ],
    "extraResources": [
      "assets/"
    ],
    "win": {
      "target": "nsis",
      "icon": "build/icon.ico"
    },
    "nsis": {
      "installerIcon": "build/icon.ico"
    },
    "linux": {
      "target": [
        "deb",
        "AppImage"
      ],
      "extraResources": [
        "assets/"
      ],
      "fpm": ["--after-install=build/after-install.sh"]
    }
  },

and I put after-install.sh inside build directory.

__base_dir/build/after-install.sh

touch "/home/<ubuntu username>/log$(date +'%m%d%y-%H:%M:%S')"

after I install, there will be a new file log040818-12:12:01 which follows the installation date.

Can we please actually have the options documented without having to read the electron-builder sources? It's been a year.

I cannot access environment variables like $HOME and ~ is not expanding in the script which I have added in after-remove . is there any other way to get acesss to user directory

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NPellet picture NPellet  Â·  3Comments

AidanNichol picture AidanNichol  Â·  3Comments

mstralka picture mstralka  Â·  3Comments

noahprince22 picture noahprince22  Â·  3Comments

talarari picture talarari  Â·  3Comments