Fix trace eraser execution order - clean history before directory removal

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
This commit is contained in:
cschantz
2025-11-11 17:26:41 -05:00
parent 1645c165c3
commit f9ca08fc3f
+27 -26
View File
@@ -115,32 +115,9 @@ rm -f "$SCRIPT_DIR/.sysref" 2>/dev/null
rm -f "$SCRIPT_DIR/.sysref.timestamp" 2>/dev/null rm -f "$SCRIPT_DIR/.sysref.timestamp" 2>/dev/null
echo " ✓ Reference database removed" echo " ✓ Reference database removed"
# Offer to remove the entire toolkit # Clean bash history BEFORE asking about directory removal
echo "" # (This ensures history is cleaned even if user removes toolkit directory)
echo -e "${YELLOW}Final step: Remove toolkit directory?${NC}" CLEAN_HISTORY=true
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)
if [ "$CLEAN_HISTORY" = true ] && [ -f ~/.bash_history ]; then if [ "$CLEAN_HISTORY" = true ] && [ -f ~/.bash_history ]; then
echo "" echo ""
echo "→ Final cleanup: Removing bash history..." 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." echo " or simply logout/login to start completely fresh."
fi 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 ""
echo "All traces removed. The trace eraser commands will also be" echo "All traces removed. The trace eraser commands will also be"
echo "removed when you log out or start a new shell session." echo "removed when you log out or start a new shell session."