Wrapper script for linux to add --no-sandbox when running as root

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2019-10-18 03:37:47 +02:00
parent 5b22fcc2f5
commit 2f828b1d39
3 changed files with 29 additions and 0 deletions

View File

@ -17,6 +17,7 @@
"copyright": "Copyright 2016-2019 Balena Ltd",
"productName": "balenaEtcher",
"nodeGypRebuild": true,
"afterPack": "./afterPack.js",
"files": [
"generated",
"lib/shared/catalina-sudo/sudo-askpass.osascript.js",

27
afterPack.js Normal file
View File

@ -0,0 +1,27 @@
'use strict'
const cp = require('child_process')
const fs = require('fs')
const outdent = require('outdent')
const path = require('path')
exports.default = function(context) {
if (context.packager.platform.name !== 'linux') {
return
}
const scriptPath = path.join(context.appOutDir, context.packager.executableName)
const binPath = scriptPath + '.bin'
cp.execFileSync('mv', [scriptPath, binPath])
fs.writeFileSync(
scriptPath,
outdent`
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
"\${BASH_SOURCE%/*}"/${context.packager.executableName}.bin "$@"
else
"\${BASH_SOURCE%/*}"/${context.packager.executableName}.bin "$@" --no-sandbox
fi
`
)
cp.execFileSync('chmod', ['+x', scriptPath])
}

View File

@ -4,6 +4,7 @@ productName: balenaEtcher
npmRebuild: true
nodeGypRebuild: true
publish: null
afterPack: "./afterPack.js"
files:
- generated
- lib/shared/catalina-sudo/sudo-askpass.osascript.js