Fix for cross-platform installation issues (macOS/Linux)#28
Fix for cross-platform installation issues (macOS/Linux)#280x3xplt1 wants to merge 1 commit intotarunkant:masterfrom
Conversation
…of the gopherus.py
There was a problem hiding this comment.
Pull request overview
This PR aims to make installation work across macOS/Linux by avoiding a hardcoded Python 2 path, updating install.sh to rewrite gopherus.py’s shebang based on the user’s environment.
Changes:
- Dynamically rewrites the first line (shebang) of
gopherus.pyduring installation to point at the resolvedpython2executable.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,4 +1,5 @@ | |||
| #!/bin/bash | |||
| sed "1s|.*|#!$(which python2)|" gopherus.py > tmp && mv tmp gopherus.py | |||
There was a problem hiding this comment.
This shebang rewrite can silently produce an invalid #! line when python2 is not on PATH (common on macOS where it may be python2.7 or not installed). It also relies on which (not POSIX) and uses a fixed temporary filename (tmp) that can collide with an existing file or be clobbered on reruns. Consider: (1) resolve the interpreter with command -v and fail fast with a clear error if not found (before modifying gopherus.py), optionally trying common fallbacks like python2.7; (2) use mktemp (and a trap/cleanup) for the temporary file; and (3) quote paths/variables to handle spaces safely.
| python2 -m pip install argparse | ||
| python2 -m pip install requests |
There was a problem hiding this comment.
The python2 -m pip install argparse and python2 -m pip install requests commands fetch and execute third-party packages from PyPI without pinning versions or verifying integrity, which creates a supply-chain risk: if those packages (or the index) are compromised, arbitrary code can run during installation with the install user's privileges. To mitigate this, pin dependencies to specific versions (e.g., via a requirements.txt) and, where possible, enable hash-based verification so the installer only accepts known-good artifacts.
On some systems (like macOS and certain Linux distributions), python2 is not located at the hardcoded path, which causes the tool to fail.
This pull request updates install.sh to dynamically locate the user's python2 environment and update the shebang in gopherus.py during installation. This makes the setup process completely cross-platform without needing to change the core Python code in the repository.