Issue: After cleanup successfully deleted toolkit directory, shell would crash when returning to prompt. File descriptors to deleted files still open.
Solution:
- Add 0.5s delay before cleanup to let file descriptors close
- Return explicit '0' after cleanup (not $LAUNCHER_EXIT)
- Even on cleanup failure, return 0 to avoid shell state confusion
- Only use $LAUNCHER_EXIT for normal exits without cleanup
This ensures:
- Shell has time to release file descriptors
- Return code doesn't trigger shell errors
- No crash after cleanup completes
- Clean return to user prompt
CRITICAL FIXES:
- TERMINAL CRASH: Changed 'exit 1' to 'return 1' in library sourcing (lines 21-25)
Cause: When launcher.sh sourced from run.sh, 'exit' terminated the parent shell
Impact: Terminal no longer crashes when libraries fail to load
- CLEANUP FILE PATH: Simplified cleanup file creation to use consistent path
Old: Created random temp file with mktemp (never checked by run.sh)
New: Direct creation of /tmp/.cleanup_requested (checked by run.sh)
Impact: Cleanup now works correctly on exit
HIGH PRIORITY:
- DATABASE QUERY OPTIMIZATION: Replaced 4 separate grep -c calls with single awk pass
Old: 4 separate grep calls on same file (lines 666-669)
New: Single awk pass with field counting (line 671)
Impact: ~75% faster startup detection summary display
MEDIUM PRIORITY:
- CONSISTENT ERROR HANDLING: Standardized all read commands to use explicit failure checks
Pattern: if ! read ... </dev/tty 2>/dev/null; then ... fi
Applied to: startup detection prompt (line 681), main menu (line 705), cleanup prompt (line 720)
Impact: Clearer error handling throughout launcher
- DIRECTORY INITIALIZATION: Moved init_directories out of main loop
Old: Called on every main() invocation
New: Called once at startup with error handling
Impact: Fewer redundant directory creation attempts
- RUN.SH ERROR HANDLING: Added error handling for launcher.sh sourcing
Added: Check for successful launcher.sh load with helpful error message
Impact: Better failure diagnostics if launcher fails to load
VERIFICATION:
- Tested startup flow: Launcher initializes without crashes
- Verified menu displays correctly
- Confirmed cleanup file path consistency
- All error handling patterns standardized
- live-attack-monitor.sh:
* Remove snapshot loading (start fresh each session)
* Fix Apache log monitoring to use tail -n 0 -F (only new entries)
* Add IP file sync to main loop for auto-blocking to work
* Fix IP_DATA consolidation for cross-process communication
- bot-analyzer.sh:
* Implement gzip compression for large temp files (10-20x space savings)
* Update all read/write operations to use compressed files
* Fix for servers with 200+ domains and millions of log entries
- run.sh:
* Add HISTFILE fallback to prevent crashes when sourced
New workflow:
1. User runs: source run.sh (instead of bash launcher.sh)
2. Launcher runs normally
3. On exit with cleanup=yes, launcher sets flag file
4. Wrapper detects flag and does ALL cleanup automatically:
- Cleans ~/.bash_history file
- Clears current shell's in-memory history
- Removes toolkit directory
- No manual commands needed
The key: wrapper is SOURCED so it runs in parent shell and can modify history.
User experience: answer "yes" and cleanup happens instantly, automatically.