mirror of
https://github.com/usestrix/strix.git
synced 2026-11-15 09:11:26 +00:00
fix(install): symlink into ~/.local/bin and update all existing shell profiles
This commit is contained in:
parent
6b7ae2ebe4
commit
c95b9abb2e
2 changed files with 71 additions and 28 deletions
|
|
@ -110,6 +110,9 @@ check_existing_installation() {
|
|||
if [[ ! -e "$path" ]] || [[ "$path" == "$INSTALL_DIR/strix"* ]]; then
|
||||
continue
|
||||
fi
|
||||
if [[ -L "$path" && "$(readlink "$path" 2>/dev/null || true)" == "$INSTALL_DIR/strix"* ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -n "$path" ]]; then
|
||||
echo -e "${MUTED}Found existing strix at: ${NC}$path"
|
||||
|
|
@ -247,40 +250,41 @@ setup_path() {
|
|||
;;
|
||||
esac
|
||||
|
||||
config_file=""
|
||||
local found_config=false
|
||||
for file in $config_files; do
|
||||
if [[ -f $file ]]; then
|
||||
config_file=$file
|
||||
break
|
||||
found_config=true
|
||||
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
|
||||
case $current_shell in
|
||||
fish)
|
||||
add_to_path "$file" "fish_add_path $INSTALL_DIR"
|
||||
;;
|
||||
zsh|bash|ash|sh)
|
||||
add_to_path "$file" "export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
*)
|
||||
export PATH=$INSTALL_DIR:$PATH
|
||||
print_message warning "Manually add the directory to $file (or similar):"
|
||||
print_message info " export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z $config_file ]]; then
|
||||
if [[ "$found_config" == false ]]; then
|
||||
print_message warning "No config file found for $current_shell. You may need to manually add to PATH:"
|
||||
print_message info " export PATH=$INSTALL_DIR:\$PATH"
|
||||
elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
|
||||
case $current_shell in
|
||||
fish)
|
||||
add_to_path "$config_file" "fish_add_path $INSTALL_DIR"
|
||||
;;
|
||||
zsh)
|
||||
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
bash)
|
||||
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
ash)
|
||||
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
sh)
|
||||
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
*)
|
||||
export PATH=$INSTALL_DIR:$PATH
|
||||
print_message warning "Manually add the directory to $config_file (or similar):"
|
||||
print_message info " export PATH=$INSTALL_DIR:\$PATH"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ "$os" != "windows" ] && [[ -x "$INSTALL_DIR/strix" ]]; then
|
||||
local local_bin="$HOME/.local/bin"
|
||||
if [[ -d "$local_bin" || ":$PATH:" == *":$local_bin:"* ]]; then
|
||||
mkdir -p "$local_bin"
|
||||
if [[ ! -e "$local_bin/strix" || -L "$local_bin/strix" ]]; then
|
||||
ln -sf "$INSTALL_DIR/strix" "$local_bin/strix"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${GITHUB_ACTIONS-}" ] && [ "${GITHUB_ACTIONS}" == "true" ]; then
|
||||
|
|
@ -294,7 +298,7 @@ verify_installation() {
|
|||
|
||||
local which_strix=$(which strix 2>/dev/null || echo "")
|
||||
|
||||
if [[ "$which_strix" != "$INSTALL_DIR/strix" && "$which_strix" != "$INSTALL_DIR/strix.exe" ]]; then
|
||||
if [[ "$which_strix" != "$INSTALL_DIR/strix" && "$which_strix" != "$INSTALL_DIR/strix.exe" && "$(readlink "$which_strix" 2>/dev/null || true)" != "$INSTALL_DIR/strix"* ]]; then
|
||||
if [[ -n "$which_strix" ]]; then
|
||||
echo -e "${YELLOW}⚠ Found conflicting strix at: ${NC}$which_strix"
|
||||
echo -e "${MUTED}Attempting to remove...${NC}"
|
||||
|
|
|
|||
|
|
@ -152,3 +152,42 @@ def test_installer_rejects_unsupported_architecture(tmp_path: Path) -> None:
|
|||
assert "Unsupported OS/Arch: linux/riscv64" in result.stdout
|
||||
assert not curl_log_path.exists()
|
||||
assert not (home_path / ".strix").exists()
|
||||
|
||||
|
||||
def test_installer_symlinks_local_bin_and_updates_all_existing_shell_configs(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
repository_root = Path(__file__).resolve().parents[1]
|
||||
archive_path = _create_release_archive(tmp_path)
|
||||
mock_bin = _create_mock_commands(tmp_path, machine="aarch64")
|
||||
environment, home_path, _ = _create_installer_environment(
|
||||
tmp_path,
|
||||
archive_path,
|
||||
mock_bin,
|
||||
)
|
||||
|
||||
local_bin = home_path / ".local/bin"
|
||||
local_bin.mkdir(parents=True)
|
||||
environment["PATH"] = f"{local_bin}:{environment['PATH']}"
|
||||
|
||||
bashrc = home_path / ".bashrc"
|
||||
profile = home_path / ".profile"
|
||||
bashrc.write_text("# existing bashrc\n", encoding="utf-8")
|
||||
profile.write_text("# existing profile\n", encoding="utf-8")
|
||||
|
||||
result = _run_installer(repository_root, environment)
|
||||
assert result.returncode == 0, result.stderr
|
||||
|
||||
expected_path_line = f"export PATH={home_path}/.strix/bin:$PATH"
|
||||
assert expected_path_line in bashrc.read_text(encoding="utf-8")
|
||||
assert expected_path_line in profile.read_text(encoding="utf-8")
|
||||
|
||||
symlink_path = local_bin / "strix"
|
||||
assert symlink_path.is_symlink()
|
||||
assert symlink_path.resolve() == (home_path / ".strix/bin/strix").resolve()
|
||||
|
||||
rerun_result = _run_installer(repository_root, environment)
|
||||
assert rerun_result.returncode == 0, rerun_result.stderr
|
||||
assert "Removing old pipx installation" not in rerun_result.stdout
|
||||
assert symlink_path.is_symlink()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue