Fix history cleaning to work from parent shell
The fundamental issue: launcher.sh runs in a subprocess, so it cannot modify the parent shell's history where the curl command was executed. Solution: Create a temporary cleanup script that the parent shell must source after launcher exits. This allows the history cleaning to run in the correct shell context. User workflow: 1. Run launcher.sh and select exit with cleanup 2. Source the generated /tmp/.cleanup_history_$$.sh script 3. History is cleaned in the parent shell 4. Exit and restart shell to verify The cleanup script removes toolkit traces from ~/.bash_history and disables history recording for the current session.
This commit is contained in:
+35
-20
@@ -1507,33 +1507,48 @@ main() {
|
|||||||
read -p "Clean history and remove traces? (yes/no): " clean_hist
|
read -p "Clean history and remove traces? (yes/no): " clean_hist
|
||||||
|
|
||||||
if [ "$clean_hist" = "yes" ]; then
|
if [ "$clean_hist" = "yes" ]; then
|
||||||
# Clean history in current shell FIRST (before subprocess)
|
# Create a cleanup script for the parent shell to source
|
||||||
# This ensures the parent shell's history is cleaned
|
cat > /tmp/.cleanup_history_$$.sh << 'CLEANUP_EOF'
|
||||||
GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces"
|
# Disable history recording
|
||||||
|
set +o history
|
||||||
|
shopt -u histappend 2>/dev/null || true
|
||||||
|
|
||||||
# Clean the history file (same logic as trace eraser)
|
# Clean the history file
|
||||||
if [ -f ~/.bash_history ]; then
|
GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces"
|
||||||
cp ~/.bash_history ~/.bash_history.bak.$$
|
if [ -f ~/.bash_history ]; then
|
||||||
grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history 2>/dev/null || true
|
cp ~/.bash_history ~/.bash_history.bak.$$
|
||||||
rm -f ~/.bash_history.bak.$$
|
grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history 2>/dev/null || true
|
||||||
fi
|
rm -f ~/.bash_history.bak.$$
|
||||||
|
fi
|
||||||
|
|
||||||
# Clear current shell's in-memory history
|
# Clear and reload history
|
||||||
history -c
|
history -c
|
||||||
|
history -r ~/.bash_history
|
||||||
|
unset HISTFILE
|
||||||
|
|
||||||
# Reload cleaned history
|
# Clean up this temp script
|
||||||
history -r ~/.bash_history
|
rm -f /tmp/.cleanup_history_*.sh 2>/dev/null
|
||||||
|
|
||||||
# Unset HISTFILE to prevent re-writing on exit
|
echo ""
|
||||||
unset HISTFILE
|
echo "✓ History cleaned. Exit and start new shell to verify."
|
||||||
|
echo ""
|
||||||
|
CLEANUP_EOF
|
||||||
|
|
||||||
# Now run trace eraser for logs/files/directory cleanup
|
# Run trace eraser for logs/files/directory cleanup
|
||||||
TRACE_ERASER_AUTO=yes bash "$BASE_DIR/tools/erase-toolkit-traces.sh" 2>&1 | grep -E "^✓|^$" || true
|
TRACE_ERASER_AUTO=yes bash "$BASE_DIR/tools/erase-toolkit-traces.sh" 2>&1 | grep -E "^✓|^$" || true
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${GREEN}Thanks for using Server Management Toolkit!${NC}"
|
echo -e "${GREEN}✓ All traces removed${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e "${YELLOW}IMPORTANT: Run this command now to clean your shell's history:${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "source /tmp/.cleanup_history_$$.sh"
|
||||||
|
echo ""
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}Thanks for using Server Management Toolkit!${NC}"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|||||||
Reference in New Issue
Block a user