fix: respect --install-dir argument throughout installation process

- Add get_install_path() helper to convert registry paths to installation paths
- Fix collision detection to check files in custom install directory
- Fix file installation to use custom directory instead of hardcoded .opencode
- Fix env.example path check in post-install message
- Tested with .test-install-dir and .openffff directories - all files now install to correct location
This commit is contained in:
darrenhinde 2025-11-19 01:22:21 +00:00
parent 8b75f128d3
commit 9692d3a752

View file

@ -275,6 +275,17 @@ get_registry_key() {
esac esac
} }
# Helper function to convert registry path to installation path
# Registry paths are like ".opencode/agent/foo.md"
# We need to replace ".opencode" with the actual INSTALL_DIR
get_install_path() {
local registry_path=$1
# Strip leading .opencode/ if present
local relative_path="${registry_path#.opencode/}"
# Return INSTALL_DIR + relative path
echo "${INSTALL_DIR}/${relative_path}"
}
resolve_dependencies() { resolve_dependencies() {
local component=$1 local component=$1
local type="${component%%:*}" local type="${component%%:*}"
@ -809,8 +820,11 @@ perform_installation() {
local registry_key=$(get_registry_key "$type") local registry_key=$(get_registry_key "$type")
local path=$(jq -r ".components.${registry_key}[] | select(.id == \"${id}\") | .path" "$TEMP_DIR/registry.json") local path=$(jq -r ".components.${registry_key}[] | select(.id == \"${id}\") | .path" "$TEMP_DIR/registry.json")
if [ -n "$path" ] && [ "$path" != "null" ] && [ -f "$path" ]; then if [ -n "$path" ] && [ "$path" != "null" ]; then
collisions+=("$path") local install_path=$(get_install_path "$path")
if [ -f "$install_path" ]; then
collisions+=("$install_path")
fi
fi fi
done done
@ -878,9 +892,12 @@ perform_installation() {
continue continue
fi fi
# Convert registry path to installation path
local dest=$(get_install_path "$path")
# Check if file exists before we install (for proper messaging) # Check if file exists before we install (for proper messaging)
local file_existed=false local file_existed=false
if [ -f "$path" ]; then if [ -f "$dest" ]; then
file_existed=true file_existed=true
fi fi
@ -893,7 +910,6 @@ perform_installation() {
# Download component # Download component
local url="${RAW_URL}/${path}" local url="${RAW_URL}/${path}"
local dest="${path}"
# Create parent directory if needed # Create parent directory if needed
mkdir -p "$(dirname "$dest")" mkdir -p "$(dirname "$dest")"
@ -945,7 +961,7 @@ show_post_install() {
echo "1. Review the installed components in ${CYAN}${INSTALL_DIR}/${NC}" echo "1. Review the installed components in ${CYAN}${INSTALL_DIR}/${NC}"
# Check if env.example was installed # Check if env.example was installed
if [ -f "${INSTALL_DIR}/../env.example" ] || [ -f "env.example" ]; then if [ -f "${INSTALL_DIR}/env.example" ] || [ -f "env.example" ]; then
echo "2. Copy env.example to .env and configure:" echo "2. Copy env.example to .env and configure:"
echo " ${CYAN}cp env.example .env${NC}" echo " ${CYAN}cp env.example .env${NC}"
echo "3. Start using OpenCode agents:" echo "3. Start using OpenCode agents:"