From c775cd520785c6030ef7564aa1d7f3f0f4d675b3 Mon Sep 17 00:00:00 2001 From: marcelsafin <179933638+marcelsafin@users.noreply.github.com> Date: Tue, 7 Apr 2026 21:19:45 +0200 Subject: [PATCH] install: guard against duplicate PATH entries on reinstall MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running the installer twice without restarting the shell causes the PATH configuration line to be appended to the shell profile a second time, since the script only checks whether copilot is in PATH (which requires a shell restart to take effect) before prompting. Check whether the exact PATH_LINE already exists in RC_FILE before appending. This makes the write idempotent—reinstalls and upgrades skip the duplicate and report that the configuration is already present. --- install.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index b63486dd..31c85245 100755 --- a/install.sh +++ b/install.sh @@ -175,9 +175,13 @@ if ! command -v copilot >/dev/null 2>&1; then printf "Would you like to add it to %s? [y/N] " "$RC_FILE" if read -r REPLY /dev/null; then if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then - mkdir -p "$(dirname "$RC_FILE")" - echo "$PATH_LINE" >> "$RC_FILE" - echo "✓ Added PATH configuration to $RC_FILE" + if grep -qxF -- "$PATH_LINE" "$RC_FILE" 2>/dev/null; then + echo "✓ PATH configuration already in $RC_FILE" + elif mkdir -p "$(dirname "$RC_FILE")" && echo "$PATH_LINE" >> "$RC_FILE"; then + echo "✓ Added PATH configuration to $RC_FILE" + else + echo "✗ Failed to update $RC_FILE (check permissions)" >&2 + fi echo " Restart your shell or run: source $RC_FILE" fi fi