From d8cb8f78154910f46b70f4b2537d57169b1a0b60 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Wed, 19 Feb 2020 16:11:17 +0000 Subject: [PATCH] fix(afterPack): error on launch from deb terminal When installing balena-etcher via apt on Debian/Ubuntu, the command `balena-etcher-electron` fails with the error: line 3: /usr/bin/balena-etcher-electron.bin: No such file or directory This is because the /usr/bin/balena-etcher-electron is a symlink to /opt/balenaEtcher/balena-etcher-electron, but the script looks for balena-etcher-electron.bin in the symlink directory, not the actual script location directory. This commit uses `$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")` to find the real location of the balena-etcher-electron script without symlink, so that balena-etcher-electron.bin is correctly found. Change-Type: patch Changelog-Entry: Fix error when launching from terminal when installed via apt. Fixes: https://github.com/balena-io/etcher/issues/3074 --- afterPack.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/afterPack.js b/afterPack.js index d71613e2..eb192ee9 100644 --- a/afterPack.js +++ b/afterPack.js @@ -14,12 +14,16 @@ exports.default = function(context) { cp.execFileSync('mv', [scriptPath, binPath]) fs.writeFileSync( scriptPath, - outdent` + outdent({trimTrailingNewline: false})` #!/bin/bash + + # Resolve symlinks. Warning, readlink -f doesn't work on MacOS/BSD + script_dir="$(dirname "$(readlink -f "\${BASH_SOURCE[0]}")")" + if [[ $EUID -ne 0 ]] || [[ $ELECTRON_RUN_AS_NODE ]]; then - "\${BASH_SOURCE%/*}"/${context.packager.executableName}.bin "$@" + "\${script_dir}"/${context.packager.executableName}.bin "$@" else - "\${BASH_SOURCE%/*}"/${context.packager.executableName}.bin "$@" --no-sandbox + "\${script_dir}"/${context.packager.executableName}.bin "$@" --no-sandbox fi ` )