Skip to content

Commit

Permalink
Issue electron-userland#7500: Use update-alternatives instead of syml…
Browse files Browse the repository at this point in the history
…inks to executable if available.

Where possible, use `update-alternatives` instead to avoid hardcoding links in Linux.
This will allow for downstream users to specify paths to their own executables
with higher priority if they wish.

Backwards compatibility is preserved by still using the symlinking route if
the command `update-alternatives` is not available.
  • Loading branch information
markizano committed Mar 25, 2023
1 parent a0e09c3 commit 93f81a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/app-builder-lib/templates/linux/after-install.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash

# Link to the binary
ln -sf '/opt/${sanitizedProductName}/${executable}' '/usr/bin/${executable}'
if type update-alternatives 2>/dev/null >&1; then
update-alternatives --install '/usr/bin/${executable}' '${executable}' '/opt/${sanitizedProductName}/${executable}' 100
else
ln -sf '/opt/${sanitizedProductName}/${executable}' '/usr/bin/${executable}'
fi

# SUID chrome-sandbox for Electron 5+
chmod 4755 '/opt/${sanitizedProductName}/chrome-sandbox' || true
Expand Down
6 changes: 5 additions & 1 deletion packages/app-builder-lib/templates/linux/after-remove.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash

# Delete the link to the binary
rm -f '/usr/bin/${executable}'
if type update-alternatives >/dev/null 2>&1; then
update-alternatives --remove '${executable}' '/usr/bin/${executable}'
else
rm -f '/usr/bin/${executable}'
fi

0 comments on commit 93f81a1

Please sign in to comment.