From f9ca08fc3fca052171efaaf1fddb3e64f154775d Mon Sep 17 00:00:00 2001 From: cschantz Date: Tue, 11 Nov 2025 17:26:41 -0500 Subject: [PATCH] Fix trace eraser execution order - clean history before directory removal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - Move bash history cleaning BEFORE directory removal prompt - Ensures history is always cleaned regardless of directory choice - Remove exit 0 that was skipping history cleaning Issue: - When user answered "yes" to remove directory, script exited immediately - History cleaning code never executed (was after exit 0) - User's curl commands remained in ~/.bash_history Solution: - Restructure: clean history first, then ask about directory - History cleaning always runs now Tested: ✓ History cleaning happens before directory prompt ✓ Works whether user keeps or removes directory --- tools/erase-toolkit-traces.sh | 53 ++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/tools/erase-toolkit-traces.sh b/tools/erase-toolkit-traces.sh index a885f2e..685c5f0 100755 --- a/tools/erase-toolkit-traces.sh +++ b/tools/erase-toolkit-traces.sh @@ -115,32 +115,9 @@ rm -f "$SCRIPT_DIR/.sysref" 2>/dev/null rm -f "$SCRIPT_DIR/.sysref.timestamp" 2>/dev/null echo " ✓ Reference database removed" -# Offer to remove the entire toolkit -echo "" -echo -e "${YELLOW}Final step: Remove toolkit directory?${NC}" -echo "This will delete: $SCRIPT_DIR" -echo "" -read -p "Remove entire toolkit directory? (yes/no): " remove_dir - -if [ "$remove_dir" = "yes" ]; then - echo "" - echo "Removing toolkit directory..." - cd /root - rm -rf "$SCRIPT_DIR" - echo "" - echo -e "${GREEN}✓ Toolkit completely removed${NC}" - echo "" - echo "All traces have been erased." - exit 0 -else - echo "" - echo -e "${GREEN}✓ History and logs cleaned${NC}" - echo "" - echo "Toolkit directory remains at: $SCRIPT_DIR" - echo "You can manually remove it later with: rm -rf $SCRIPT_DIR" -fi - -# Final step: Clean bash history (done last to capture all script commands) +# Clean bash history BEFORE asking about directory removal +# (This ensures history is cleaned even if user removes toolkit directory) +CLEAN_HISTORY=true if [ "$CLEAN_HISTORY" = true ] && [ -f ~/.bash_history ]; then echo "" echo "→ Final cleanup: Removing bash history..." @@ -197,6 +174,30 @@ if [ "$CLEAN_HISTORY" = true ] && [ -f ~/.bash_history ]; then echo " or simply logout/login to start completely fresh." fi +# Offer to remove the entire toolkit (AFTER history cleaning) +echo "" +echo -e "${YELLOW}Final step: Remove toolkit directory?${NC}" +echo "This will delete: $SCRIPT_DIR" +echo "" +read -p "Remove entire toolkit directory? (yes/no): " remove_dir + +if [ "$remove_dir" = "yes" ]; then + echo "" + echo "Removing toolkit directory..." + cd /root + rm -rf "$SCRIPT_DIR" + echo "" + echo -e "${GREEN}✓ Toolkit completely removed${NC}" + echo "" + echo "All traces have been erased." +else + echo "" + echo -e "${GREEN}✓ History and logs cleaned${NC}" + echo "" + echo "Toolkit directory remains at: $SCRIPT_DIR" + echo "You can manually remove it later with: rm -rf $SCRIPT_DIR" +fi + echo "" echo "All traces removed. The trace eraser commands will also be" echo "removed when you log out or start a new shell session."