diff --git a/Makefile b/Makefile index 7528e12f..175e7e6d 100644 --- a/Makefile +++ b/Makefile @@ -102,37 +102,58 @@ install: build ## Build and install the kubectl plugin to ~/.local/bin (no sudo cp $$binary_name $(INSTALL_PATH)/ @echo "โœ… Installed to $(INSTALL_PATH)" @echo "" - @PATH_UPDATED=false; \ + @echo "๐Ÿ” Checking PATH configuration..." + @PATH_NEEDS_UPDATE=false; \ + PATH_UPDATED=false; \ PATH_IN_CONFIG=false; \ + CURRENT_SESSION_NEEDS_UPDATE=false; \ + \ if [[ ":$$PATH:" != *":$(INSTALL_PATH):"* ]]; then \ + PATH_NEEDS_UPDATE=true; \ + CURRENT_SESSION_NEEDS_UPDATE=true; \ + echo "โš ๏ธ $(INSTALL_PATH) is not in your current PATH"; \ + \ if [[ "$$SHELL" == */zsh* ]] && [[ -f "$$HOME/.zshrc" ]]; then \ - if ! grep -q "/.local/bin" "$$HOME/.zshrc" 2>/dev/null; then \ + if ! grep -q '^[[:space:]]*export[[:space:]]*PATH.*\.local/bin' "$$HOME/.zshrc" 2>/dev/null; then \ echo 'export PATH="$$HOME/.local/bin:$$PATH"' >> "$$HOME/.zshrc"; \ - echo "โœ… Added to ~/.zshrc"; \ + echo "โœ… Added PATH export to ~/.zshrc"; \ PATH_UPDATED=true; \ else \ - echo "โ„น๏ธ Already configured in ~/.zshrc"; \ + echo "โ„น๏ธ PATH export already exists in ~/.zshrc"; \ PATH_IN_CONFIG=true; \ fi; \ elif [[ "$$SHELL" == */bash* ]] && [[ -f "$$HOME/.bashrc" ]]; then \ - if ! grep -q "/.local/bin" "$$HOME/.bashrc" 2>/dev/null; then \ + if ! grep -q '^[[:space:]]*export[[:space:]]*PATH.*\.local/bin' "$$HOME/.bashrc" 2>/dev/null; then \ echo 'export PATH="$$HOME/.local/bin:$$PATH"' >> "$$HOME/.bashrc"; \ - echo "โœ… Added to ~/.bashrc"; \ + echo "โœ… Added PATH export to ~/.bashrc"; \ PATH_UPDATED=true; \ else \ - echo "โ„น๏ธ Already configured in ~/.bashrc"; \ + echo "โ„น๏ธ PATH export already exists in ~/.bashrc"; \ PATH_IN_CONFIG=true; \ fi; \ else \ - echo "โš ๏ธ Add to your shell config: export PATH=\"$(INSTALL_PATH):$$PATH\""; \ + echo "โš ๏ธ Unsupported shell or config file not found"; \ + echo " Manually add to your shell config: export PATH=\"$(INSTALL_PATH):$$PATH\""; \ PATH_UPDATED=true; \ fi; \ else \ - echo "โœ… PATH already configured"; \ + echo "โœ… $(INSTALL_PATH) is already in PATH"; \ fi; \ + \ echo ""; \ - if [[ "$$PATH_UPDATED" == "true" ]] || [[ "$$PATH_IN_CONFIG" == "true" ]]; then \ - echo "๐Ÿ”„ Restart terminal or run: source ~/.zshrc"; \ + if [[ "$$CURRENT_SESSION_NEEDS_UPDATE" == "true" ]]; then \ + echo "๐Ÿ”ง To use kubectl oadp in this terminal session:"; \ + echo " export PATH=\"$(INSTALL_PATH):$$PATH\""; \ + echo ""; \ + echo "๐Ÿ”„ For future sessions:"; \ + if [[ "$$PATH_UPDATED" == "true" ]]; then \ + echo " Restart your terminal or run: source ~/.zshrc"; \ + elif [[ "$$PATH_IN_CONFIG" == "true" ]]; then \ + echo " Restart your terminal or run: source ~/.zshrc"; \ + echo " (PATH export exists but may need shell restart)"; \ + else \ + echo " Add the PATH export to your shell configuration file"; \ + fi; \ fi; \ echo ""; \ echo "๐Ÿ“‹ Configuration:"; \ @@ -189,6 +210,35 @@ install: build ## Build and install the kubectl plugin to ~/.local/bin (no sudo $(INSTALL_PATH)/$$binary_name client config set namespace=$$NAMESPACE 2>/dev/null || true; \ echo "โœ… Client config initialized"; \ echo ""; \ + echo "๐Ÿงช Verifying installation..."; \ + if [[ "$$CURRENT_SESSION_NEEDS_UPDATE" == "true" ]]; then \ + echo " Temporarily updating PATH for verification"; \ + if PATH="$(INSTALL_PATH):$$PATH" command -v kubectl >/dev/null 2>&1; then \ + if PATH="$(INSTALL_PATH):$$PATH" kubectl plugin list 2>/dev/null | grep -q "kubectl-oadp"; then \ + echo "โœ… Installation verified: kubectl oadp plugin is accessible"; \ + PATH="$(INSTALL_PATH):$$PATH" kubectl oadp version 2>/dev/null || echo " (Note: version command requires cluster access)"; \ + else \ + echo "โŒ Installation verification failed: kubectl oadp plugin not found"; \ + echo " Try running: export PATH=\"$(INSTALL_PATH):$$PATH\""; \ + fi; \ + else \ + echo "โš ๏ธ kubectl not found - cannot verify plugin accessibility"; \ + echo " Plugin installed to: $(INSTALL_PATH)/$$binary_name"; \ + fi; \ + else \ + if command -v kubectl >/dev/null 2>&1; then \ + if kubectl plugin list 2>/dev/null | grep -q "kubectl-oadp"; then \ + echo "โœ… Installation verified: kubectl oadp plugin is accessible"; \ + kubectl oadp version 2>/dev/null || echo " (Note: version command requires cluster access)"; \ + else \ + echo "โŒ Installation verification failed: kubectl oadp plugin not found"; \ + fi; \ + else \ + echo "โš ๏ธ kubectl not found - cannot verify plugin accessibility"; \ + echo " Plugin installed to: $(INSTALL_PATH)/$$binary_name"; \ + fi; \ + fi; \ + echo ""; \ echo "๐Ÿ“‹ Next steps:"; \ echo " 1. Test admin commands: kubectl oadp backup get"; \ echo " 2. Test non-admin commands: kubectl oadp nonadmin backup get"; \ diff --git a/README.md b/README.md index 78f86c17..b0dbfb91 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ make install ASSUME_DEFAULT=true # Use default namespace (no detection) make install VELERO_NAMESPACE=custom # Use specific namespace (no detection) ``` -**๐Ÿ’ก Important:** After installation, you may need to refresh your terminal or run `source ~/.zshrc` (or `~/.bashrc`) for the `kubectl oadp` command to work. +**๐Ÿ’ก Path Setup:** The installer will automatically check your PATH and guide you through any necessary setup. If `kubectl oadp` doesn't work immediately after installation, follow the on-screen instructions to update your PATH for the current session or restart your terminal. You can set the velero namespace afterwards using the oadp client command