fix: respect install directory priority as documented in README
Summary
Fixes the install script to respect the installation directory priority order as documented in the README.
Problem
The install script was hardcoding INSTALL_DIR=$HOME/.opencode/bin on line 68-69, completely ignoring the environment variables documented in the README:
-
$OPENCODE_INSTALL_DIR- Custom installation directory -
$XDG_BIN_DIR- XDG Base Directory Specification compliant path -
$HOME/bin- Standard user binary directory (if exists or can be created) -
$HOME/.opencode/bin- Default fallback
Solution
This PR implements the documented priority order with proper validation:
- Checks
$OPENCODE_INSTALL_DIRfirst (highest priority) - Falls back to
$XDG_BIN_DIRif not set - Falls back to
$HOME/binif it exists or can be created - Falls back to
$HOME/.opencode/binas final default
Additional Improvements
- Directory creation validation: Ensures the installation directory can be created, with clear error messages if it fails
- Write permission check: Verifies the directory is writable before proceeding with installation
-
Better error messages: Informs users to use
OPENCODE_INSTALL_DIRif default paths fail
Testing
- Verified bash syntax is valid (
bash -n install) - Tested priority logic with unit tests
- Tested with
--helpflag to ensure no regressions - All tests pass ✓
Impact
Users can now properly customize their installation directory as documented, and will receive clear error messages if there are permission issues.
Fixes #7675
The following comment was made by an LLM, it may be inaccurate:
No duplicate PRs found.
The searches returned only the current PR (#6993) and one unrelated PR about a TUI layout system. This indicates that:
- PR #6993 appears to be the only PR addressing the install directory priority issue
- There are no other open PRs fixing the
OPENCODE_INSTALL_DIR,XDG_BIN_DIR, or installation script environment variable handling
This PR is ready to proceed without concerns about duplicates.
I tried OPENCODE_INSTALL_DIR=$HOME/.local/bin curl -fsSL https://opencode.ai/install | env -u VERSION bash, but it still installed into $HOME/.opencode/bin/ This is nice. BTW, I really hate it when someone touches my ~/.bashrc.
Please merge this, guys! 🙏