Skip to content
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

$HOME ends up hardcoded in shebangs #12

Open
probonopd opened this issue Jan 2, 2019 · 17 comments · May be fixed by #41
Open

$HOME ends up hardcoded in shebangs #12

probonopd opened this issue Jan 2, 2019 · 17 comments · May be fixed by #41

Comments

@probonopd
Copy link
Contributor

Using this script, and then deleting the original AppDir, I get when I try to run the AppImage:

me@host:~$ ./squashfs-root/AppRun # Without existing WINEPREFIX overlay
bash: ./squashfs-root/AppRun: /home/me/AppDir/usr/conda/bin/python: bad interpreter: No such file or directory

/home/me/AppDir/ was the location of the AppDir at creation time. It should not be hardcoded, especially not in shebangs.

@TheAssassin
Copy link
Member

TheAssassin commented Jan 2, 2019

Stuff in shebangs can't be trusted with this plugin. The best solution is to always write your own AppRun script, and hand it to linuxdeploy with --custom-apprun myscript.sh. I will probably add an example script somewhere in the repo soon.

@probonopd
Copy link
Contributor Author

This is what I am doing now, but let's also keep in mind that the main payload app might call other scripts, in which case the custom AppRun cannot do much...

@TheAssassin
Copy link
Member

You can't have "relative" paths in shebangs. The only thing we could do would be to remove all shebangs and force you to use a script anyway.

@probonopd
Copy link
Contributor Author

You can't have "relative" paths in shebangs.

Are you sure about this? Let's play around with variations of

#!/usr/bin/env readlink -f ...

@probonopd
Copy link
Contributor Author

probonopd commented Jan 2, 2019

https://stackoverflow.com/a/33225083 recommends

#!/usr/bin/awk BEGIN{a=ARGV[1];sub(/[a-z_.]+$/,"python",a);system(a"\t"ARGV[1])}

@TheAssassin
Copy link
Member

The first solution doesn't work as we don't set PATH.

The second one is super ugly, and noone really knows whether that'd work reliably... (there's different implementations of AWK)... but it might go in the right direction...

@probonopd
Copy link
Contributor Author

probonopd commented Jan 2, 2019

The awk solution works, but is relative to the called symlink rather than relative to the symlinked file, which makes a difference for AppRun.

@probonopd
Copy link
Contributor Author

probonopd commented Jan 2, 2019

noone really knows whether that'd work reliably

Which is still better than a hardcoded path which everyone knows with certainty will not work ;-)

@TheAssassin
Copy link
Member

You probably haven't tested on all X distros against all implementations of awk, did you? Also, who says awk might be installed? It's not part of a default installation.

Again: my "solution" is to remove all shebangs.

@probonopd
Copy link
Contributor Author

Again: my "solution" is to remove all shebangs.

What happens if Python script A tries to exec Python script B?

@TheAssassin
Copy link
Member

TheAssassin commented Jan 2, 2019

Why should they not do it in Python directly? You shouldn't rely on such stuff. Also, why these virtual questions? You can't auto fix this in a good way, I guess we've come to this conclusion. If you find a solution, please feel free to send a PR. But right now, I don't see any good ways.

@probonopd
Copy link
Contributor Author

The awk above is better than leaving a hardcoded string that never works, can we agree on that?

@TheAssassin
Copy link
Member

No, because that string would a) have to be generated for every file in every directory relative to the Python interpreter. It's a huge mess!

@TheAssassin
Copy link
Member

@probonopd are you willing to send a PR implementing your awk solution? I think the build runtime overhead is well invested if it can work in some scenarios.

@probonopd
Copy link
Contributor Author

probonopd commented Mar 7, 2020

Right now I cant`do it due to lack of time, maybe when I next time run into the issue... or maybe someone else does it in the meantime. How does @niess handle this type of thing in https://github.com/niess/linuxdeploy-plugin-python?

@niess
Copy link

niess commented Mar 7, 2020

@probonopd: following the install of python and extra packages (using pip), the plugin script looks for any Python script under /bin and replaces its absolute shebang with a relative one (see L179). I use the exec trick e.g. as indicated in the 1st answer of this S.O. question.

I have to say that I didn't investigate the pros and cons of the various options discussed there. I implemented the exec trick some time ago, after some googling, and didn't know about the other solutions at that time. It seems to work fine so far.

@TheAssassin
Copy link
Member

@niess mind to send us a PR? I mean, as long as only the shebang is modified, it won't break anything. The recommended way is to avoid relying on shebangs, though.

knarfS added a commit to knarfS/linuxdeploy-plugin-conda that referenced this issue Jun 11, 2021
This removes some of the wrong paths pointing to the build location of the
AppImage by using a different shebang and some environment variables.

Fixes linuxdeploy#12, linuxdeploy#25 and linuxdeploy#32
knarfS added a commit to knarfS/linuxdeploy-plugin-conda that referenced this issue Jun 11, 2021
This removes some of the wrong paths pointing to the build location of the
AppImage by using a different shebang and some environment variables.

Fixes linuxdeploy#12, linuxdeploy#25 and linuxdeploy#32
knarfS added a commit to knarfS/linuxdeploy-plugin-conda that referenced this issue Jun 11, 2021
This removes some of the wrong paths pointing to the build location of the
AppImage by using a different shebang and some environment variables.

Fixes linuxdeploy#12, linuxdeploy#25 and linuxdeploy#32
@knarfS knarfS linked a pull request Jun 11, 2021 that will close this issue
knarfS added a commit to knarfS/linuxdeploy-plugin-conda that referenced this issue Jun 11, 2021
This removes some of the wrong paths pointing to the build location of the
AppImage by using a different shebang and some environment variables.

Fixes linuxdeploy#12, linuxdeploy#25 and linuxdeploy#32
knarfS added a commit to knarfS/linuxdeploy-plugin-conda that referenced this issue Jun 11, 2021
This removes some of the wrong paths pointing to the build location of the
AppImage by using a different shebang and some environment variables.

Fixes linuxdeploy#12, linuxdeploy#25 and linuxdeploy#32
knarfS added a commit to knarfS/linuxdeploy-plugin-conda that referenced this issue Jun 12, 2021
This removes some of the wrong paths pointing to the build location of the
AppImage by using a different shebang and some environment variables.

Fixes linuxdeploy#12, linuxdeploy#25 and linuxdeploy#32
knarfS added a commit to knarfS/linuxdeploy-plugin-conda that referenced this issue Jun 12, 2021
This removes some of the wrong, absolute paths pointing to the build location
of the AppImage by using a different shebang and some environment variables,
set by the linuxdeploy-plugin-conda-hook at the AppImage start.

Fixes linuxdeploy#12, fixes linuxdeploy#25 and fixes linuxdeploy#32
knarfS added a commit to knarfS/linuxdeploy-plugin-conda that referenced this issue Jun 13, 2021
This removes some of the wrong, absolute paths pointing to the build location
of the AppImage by using a different shebang and some environment variables,
set by the linuxdeploy-plugin-conda-hook at the AppImage start.

Fixes linuxdeploy#12, fixes linuxdeploy#25 and fixes linuxdeploy#32
knarfS added a commit to knarfS/linuxdeploy-plugin-conda that referenced this issue Jun 25, 2021
This removes some of the wrong, absolute paths pointing to the build location
of the AppImage by using a different shebang and some environment variables,
set by the linuxdeploy-plugin-conda-hook at the AppImage start.

Fixes linuxdeploy#12, fixes linuxdeploy#25 and fixes linuxdeploy#32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants