From 923408b965482840d16c33227885162abad80045 Mon Sep 17 00:00:00 2001 From: Alberto De Bortoli Date: Fri, 24 Jul 2026 23:07:51 +0100 Subject: [PATCH 1/2] Default install to ~/.local/bin to avoid requiring sudo INSTALL_DIR previously defaulted to /usr/local/bin, which is root-owned on stock macOS, forcing every install through sudo. Default to the XDG-style ~/.local/bin instead (still overridable via INSTALL_DIR) and bootstrap PATH in the user's shell RC file when needed, mirroring existing patterns like rustup/pipx. uninstall.sh cleans up the same PATH export it adds. --- README.md | 26 ++++++++++++++++++-------- install.sh | 42 +++++++++++++++++++++++++++++++++++++++++- uninstall.sh | 26 +++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4f37e51..129c5ad 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ flowchart TB end subgraph Artifacts["đŸ“Ļ Installed Artifacts"] - EXE["/usr/local/bin/luca"] + EXE["~/.local/bin/luca
(default, overridable via INSTALL_DIR)"] HOOK["~/.luca/shell_hook.sh"] GITHOOK[".git/hooks/post-checkout"] RCFILE["~/.bashrc or ~/.zshrc"] @@ -95,9 +95,12 @@ flowchart TD CompareVersion -->|No| Download Download[đŸ“Ĩ Download ZIP from
GitHub releases] --> Extract[đŸ“Ļ Extract ZIP] - Extract --> InstallBin[🚀 Move to /usr/local/bin
chmod +x] + Extract --> InstallBin[🚀 Move to ~/.local/bin
chmod +x] - InstallBin --> SetupHook[🔧 Setup Shell Hook] + InstallBin --> SetupPath{"~/.local/bin
on PATH?"} + SetupPath -->|No| AddPath[🔧 Append PATH export
to RC file] + SetupPath -->|Yes| SetupHook + AddPath --> SetupHook[🔧 Setup Shell Hook] subgraph ShellHookSetup["Shell Hook Setup"] SetupHook --> CreateDir[Create ~/.luca/] @@ -247,7 +250,7 @@ flowchart TD GetVersion --> RemoveExe WarnNoExe --> RemoveExe - RemoveExe[đŸ—‘ī¸ Remove
/usr/local/bin/luca] + RemoveExe[đŸ—‘ī¸ Remove
~/.local/bin/luca] RemoveExe --> DetectShell{Detect shell} DetectShell -->|Bash| UseBashrc[Use ~/.bashrc] @@ -262,8 +265,15 @@ flowchart TD CheckHook -->|Yes| RemoveHook[Remove hook line
from RC file] CheckHook -->|No| InfoNoHook[â„šī¸ No hook found] - RemoveHook --> RemoveDir - InfoNoHook --> RemoveDir + RemoveHook --> CheckPathExport + InfoNoHook --> CheckPathExport + + CheckPathExport{PATH export
in RC file?} + CheckPathExport -->|Yes| RemovePathExport[Remove PATH export
from RC file] + CheckPathExport -->|No| InfoNoPathExport[â„šī¸ No PATH export found] + + RemovePathExport --> RemoveDir + InfoNoPathExport --> RemoveDir RemoveDir{~/.luca/
exists?} RemoveDir -->|Yes| DeleteDir[đŸ—‘ī¸ rm -rf ~/.luca/] @@ -282,7 +292,7 @@ flowchart TD ```mermaid flowchart LR subgraph System["System Locations"] - BIN["/usr/local/bin/"] + BIN["~/.local/bin/
(default, overridable via INSTALL_DIR)"] BIN --> LUCA["luca (executable)"] end @@ -327,7 +337,7 @@ sequenceDiagram Note over U,L: First-time Setup U->>T: curl ... | bash install.sh IS->>IS: Download luca binary - IS->>IS: Install to /usr/local/bin + IS->>IS: Install to ~/.local/bin (no sudo needed) IS->>SH: Download shell_hook.sh SH->>T: Modify ~/.zshrc IS->>PC: Install git hook (if in repo) diff --git a/install.sh b/install.sh index dd17cc1..14488e5 100755 --- a/install.sh +++ b/install.sh @@ -10,7 +10,7 @@ TOOL_NAME="Luca" BIN_NAME="luca" -INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}" +INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}" TOOL_FOLDER=".luca" VERSION_FILE="${PWD}/.luca-version" ORGANIZATION="LucaTools" @@ -248,6 +248,46 @@ sudo_if_install_dir_not_writeable "chmod +x $EXECUTABLE_FILE" echo "✅ $TOOL_NAME ($REQUIRED_EXECUTABLE_VERSION) successfully installed to $INSTALL_DIR" +# ============================================================================= +# PATH SETUP +# ============================================================================= + +# Detect the shell RC file to use for the PATH export +INSTALL_PATH_SHELL_RC="" +case "$SHELL" in +*/bash) + INSTALL_PATH_SHELL_RC="$HOME/.bashrc" + ;; +*/zsh) + INSTALL_PATH_SHELL_RC="$HOME/.zshrc" + ;; +esac + +PATH_EXPORT_LINE="export PATH=\"$INSTALL_DIR:\$PATH\"" + +# Ensure $INSTALL_DIR is on PATH, both for this session and future ones +case ":$PATH:" in +*":$INSTALL_DIR:"*) + # Already on PATH, nothing to do + ;; +*) + if [ -n "$INSTALL_PATH_SHELL_RC" ]; then + if [ ! -f "$INSTALL_PATH_SHELL_RC" ] || ! grep -Fq "$PATH_EXPORT_LINE" "$INSTALL_PATH_SHELL_RC"; then + echo "🔧 Adding $INSTALL_DIR to PATH in $INSTALL_PATH_SHELL_RC" + { + echo "" + echo "# Added by $TOOL_NAME installer to make $BIN_NAME available on PATH" + echo "$PATH_EXPORT_LINE" + } >> "$INSTALL_PATH_SHELL_RC" + fi + else + echo "âš ī¸ WARNING: Could not detect shell RC file to add $INSTALL_DIR to PATH." + echo " Please add it manually, e.g.: $PATH_EXPORT_LINE" + fi + export PATH="$INSTALL_DIR:$PATH" + ;; +esac + # ============================================================================= # SHELL HOOK SETUP # ============================================================================= diff --git a/uninstall.sh b/uninstall.sh index 7a3fa39..8485b4f 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -9,7 +9,7 @@ TOOL_NAME="Luca" BIN_NAME="luca" -INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}" +INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}" TOOL_FOLDER=".luca" TOOL_DIR="$HOME/$TOOL_FOLDER" SHELL_HOOK_SCRIPT_PATH="$TOOL_DIR/shell_hook.sh" @@ -162,6 +162,30 @@ else print_warning "Shell configuration file not found: $SHELL_RC_FILE" fi +# ============================================================================= +# REMOVE PATH EXPORT +# ============================================================================= + +print_header "REMOVING PATH EXPORT" + +PATH_EXPORT_LINE="export PATH=\"$INSTALL_DIR:\$PATH\"" + +if [ -n "$SHELL_RC_FILE" ] && [ -f "$SHELL_RC_FILE" ]; then + if grep -Fq "$PATH_EXPORT_LINE" "$SHELL_RC_FILE"; then + print_info "Found PATH export in $SHELL_RC_FILE, removing..." + + temp_file=$(mktemp) + + grep -v -F "# Added by $TOOL_NAME installer to make $BIN_NAME available on PATH" "$SHELL_RC_FILE" | grep -v -F "$PATH_EXPORT_LINE" > "$temp_file" + + mv "$temp_file" "$SHELL_RC_FILE" + + print_success "PATH export removed from $SHELL_RC_FILE" + else + print_info "No PATH export found in $SHELL_RC_FILE" + fi +fi + # ============================================================================= # REMOVE TOOL DIRECTORY # ============================================================================= From 604282cca69f28702a3728011096bfbbb4448b1f Mon Sep 17 00:00:00 2001 From: Alberto De Bortoli Date: Sun, 26 Jul 2026 09:41:41 +0100 Subject: [PATCH 2/2] Deduplicate shell RC detection in install.sh Both the PATH bootstrap step and the final "installation complete" message independently re-detected the shell RC file with the same case statement. Compute SHELL_PROFILE once and reuse it in both places. --- install.sh | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/install.sh b/install.sh index 14488e5..1e1d0c3 100755 --- a/install.sh +++ b/install.sh @@ -252,14 +252,15 @@ echo "✅ $TOOL_NAME ($REQUIRED_EXECUTABLE_VERSION) successfully installed to $I # PATH SETUP # ============================================================================= -# Detect the shell RC file to use for the PATH export -INSTALL_PATH_SHELL_RC="" +# Detect the current shell and its RC file (used here and in the +# "installation complete" summary below) +SHELL_PROFILE="" case "$SHELL" in */bash) - INSTALL_PATH_SHELL_RC="$HOME/.bashrc" + SHELL_PROFILE="$HOME/.bashrc" ;; */zsh) - INSTALL_PATH_SHELL_RC="$HOME/.zshrc" + SHELL_PROFILE="$HOME/.zshrc" ;; esac @@ -271,14 +272,14 @@ case ":$PATH:" in # Already on PATH, nothing to do ;; *) - if [ -n "$INSTALL_PATH_SHELL_RC" ]; then - if [ ! -f "$INSTALL_PATH_SHELL_RC" ] || ! grep -Fq "$PATH_EXPORT_LINE" "$INSTALL_PATH_SHELL_RC"; then - echo "🔧 Adding $INSTALL_DIR to PATH in $INSTALL_PATH_SHELL_RC" + if [ -n "$SHELL_PROFILE" ]; then + if [ ! -f "$SHELL_PROFILE" ] || ! grep -Fq "$PATH_EXPORT_LINE" "$SHELL_PROFILE"; then + echo "🔧 Adding $INSTALL_DIR to PATH in $SHELL_PROFILE" { echo "" echo "# Added by $TOOL_NAME installer to make $BIN_NAME available on PATH" echo "$PATH_EXPORT_LINE" - } >> "$INSTALL_PATH_SHELL_RC" + } >> "$SHELL_PROFILE" fi else echo "âš ī¸ WARNING: Could not detect shell RC file to add $INSTALL_DIR to PATH." @@ -409,22 +410,11 @@ fi echo "" echo "💡 To start using Luca:" -# Detect the current shell and set the appropriate RC file -SHELL_PROFILE="" - -case "$SHELL" in -*/bash) - SHELL_PROFILE="$HOME/.bashrc" - ;; -*/zsh) - SHELL_PROFILE="$HOME/.zshrc" - ;; -*) +if [ -z "$SHELL_PROFILE" ]; then echo "WARNING: Unsupported shell: $SHELL" echo "Manual setup may be required. Supported shells: bash, zsh" exit 1 - ;; -esac +fi echo " 1. Restart your terminal or run: source $SHELL_PROFILE" echo " 2. Run: $BIN_NAME --help"