-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Use update-alternatives
instead of symlinks for #7500
#7501
fix: Use update-alternatives
instead of symlinks for #7500
#7501
Conversation
…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.
🦋 Changeset detectedLatest commit: ea5c970 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for car-park-attendant-cleat-11576 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
update-alternatives
instead of symlinks for #7500
update-alternatives
instead of symlinks for #7500update-alternatives
instead of symlinks for #7500
okay, I think I have included all the requirements for this to be accepted. Ready for review! |
Thank you!
You'll need to run the specific test file and update the snapshot
(Might need to run within docker image, not sure off the top of my head |
Seems like I am missing post-compiled resources? When running this command, I get errors around a missing compiled test file:
I cannot seem to find any documentation around how to compile the TypeScript stuff into test/out/helpers/*.js |
Good to note that the docs need to be updated.
|
…ithout errors about dmg-license cannot be installed. I get this error without this change: ``` npm WARN deprecated [email protected]: < 19.4.0 is no longer supported npm WARN deprecated @braintree/[email protected]: Potential XSS vulnerability patched in v6.0.0. npm WARN deprecated [email protected]: Use your platform's native performance.now() and performance.timeOrigin. npm ERR! code EBADPLATFORM npm ERR! notsup Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm ERR! notsup Valid OS: darwin npm ERR! notsup Valid Arch: any npm ERR! notsup Actual OS: linux npm ERR! notsup Actual Arch: x64 npm ERR! A complete log of this run can be found in: npm ERR! /home/user/.npm/_logs/2023-04-04T23_28_28_809Z-debug.log ``` Changing to an optionalDependency allowed me to proceed without errors.
Apologies for the sporadic work here and there on this and thanks so much for the incredible responsiveness on this, @mmaietta !!! |
7dfc2ef
to
1a45b6c
Compare
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just read this in your changeset. (My apologies for pinging back n forth on this)
If you are having issues on install or get errors about
/usr/bin/${executable}
already
exists, then simply remove the link andupdate-alternatives
will take over from there.
Do we need to update this code as follows? We can't expect all linux users to know they need to remove the link on their own during the install process
previousLink = "/usr/bin/${executable}"
# remove previously existing symlink if applicable
[ -L "${previousLink}" ] && [ -e "${previousLink}" ] && rm -f "${previousLink}"
update-alternatives --install "${previousLink}" "${executable}" "/opt/${sanitizedProductName}/${executable}" 100
Note: I didn't test this logic, just pulled resources from online and changed '
to "
. So you'd need to test this change
What are your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, it was an upstream change I wanted to propose into this project and grateful for the thoughtful discussion!
Do we need to update this code as follows? We can't expect all linux users to know they need to remove the link on their own during the install process
I think I see what you mean in the updates here, so I updated the changeset accordingly. This is very valid and for a project as core as this to so many others, it would cause a lot of heartburn.
In this corrected way, the end-user nor middleware have to take any action in consuming this update.
With the above proposed change, it might produce output durring the install about having to correct a broken link as such:
update-alternatives: warning: forcing reinstallation of alternative /opt/${sanitizedProductName}/${executable} because link group ${executable} is broken
on each update.
Single quotes are considered string literals. Double-quotes are considered interpolatable strings. Since the templates are passing through a template processor and not the bash interpreter itself, single quotes in this case would be fine since it's not in-script variables that are being used. Since those variables are "userland" variables outside of the script (interpolated by the template filter), single quotes would also be more secure in this case, so I think it might have been correct. In-script variable use might require double-quotes.
(sorry if this sounds wordy -- I am an instructor on my TikTok & YouTube channels :D )
…umption into descending projects.
rm -f "/usr/bin/${executable}" | ||
fi | ||
|
||
update-alternatives --install '/usr/bin/${executable}' '${executable}' '/opt/${sanitizedProductName}/${executable}' 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need this check, right?
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
Or is that covered by != "/etc/alternatives/${executable}"
?
ln -sf '/opt/${sanitizedProductName}/${executable}' '/usr/bin/${executable}' | ||
if type update-alternatives 2>/dev/null >&1; then | ||
# Remove previous link if it doesn't use update-alternatives | ||
if [ -L '/usr/bin/${executable}' -a -e '/usr/bin/${executable}' -a "`readlink '/usr/bin/${executable}'`" != '/etc/alternatives/${executable}' ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what this line means, but I trust 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries :)
https://ss64.com/bash/test.html
-L
- file is symlink.
EXPR -a EXPR
- AND operation between expressions.
-e
- check if file exists.
Should result in something like (pseudo code ahead):
if ( isSymLink(file) && isExist(file) && readlink(file) != "/etc/alternatives/$exec" )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kicking off CI
@mmaietta -- Thanks so much for working with me to get this into the project!! |
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.