Add wrapper script for automatic cleanup with zero manual steps
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.
This commit is contained in:
@@ -75,14 +75,14 @@ server-toolkit/
|
|||||||
### Installation & Running
|
### Installation & Running
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -sL https://git.mull.lol/cschantz/Linux-Server-Management-Toolkit/archive/main.tar.gz | tar xz && cd linux-server-management-toolkit && bash launcher.sh
|
curl -sL https://git.mull.lol/cschantz/Linux-Server-Management-Toolkit/archive/main.tar.gz | tar xz && cd linux-server-management-toolkit && source run.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
**Privacy:** When exiting (option 0), answer "yes" to cleanup and run the source command shown to remove all traces.
|
**Privacy:** When exiting (option 0), answer "yes" - cleanup happens automatically with no extra steps.
|
||||||
|
|
||||||
Or if already downloaded:
|
Or if already downloaded:
|
||||||
```bash
|
```bash
|
||||||
bash /root/server-toolkit/launcher.sh
|
source /root/server-toolkit/run.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
## ✨ Key Features
|
## ✨ Key Features
|
||||||
|
|||||||
+3
-41
@@ -1507,48 +1507,10 @@ 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 .bash_history file
|
# Signal wrapper script to do cleanup
|
||||||
|
touch /tmp/.cleanup_requested
|
||||||
echo ""
|
echo ""
|
||||||
echo "→ Cleaning bash history..."
|
echo "Cleanup will happen automatically..."
|
||||||
GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces"
|
|
||||||
|
|
||||||
if [ -f ~/.bash_history ]; then
|
|
||||||
cp ~/.bash_history ~/.bash_history.bak.$$
|
|
||||||
grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history 2>/dev/null || true
|
|
||||||
rm -f ~/.bash_history.bak.$$
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Verify curl command is gone from file
|
|
||||||
if grep -q "git\.mull\.lol.*toolkit" ~/.bash_history 2>/dev/null; then
|
|
||||||
echo -e "${RED}✗ Warning: curl command still in history file${NC}"
|
|
||||||
else
|
|
||||||
echo -e "${GREEN}✓ Verified: No curl download commands in history file${NC}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Remove logs and temp files
|
|
||||||
echo "→ Removing logs and temp files..."
|
|
||||||
rm -f "$BASE_DIR/logs/"*.log 2>/dev/null
|
|
||||||
rm -f "$BASE_DIR/"*_report_*.txt 2>/dev/null
|
|
||||||
rm -rf /tmp/live-monitor-* /tmp/server-toolkit-* 2>/dev/null
|
|
||||||
|
|
||||||
# Remove toolkit directory
|
|
||||||
echo "→ Removing toolkit directory..."
|
|
||||||
cd /root 2>/dev/null
|
|
||||||
TOOLKIT_DIR="$BASE_DIR"
|
|
||||||
rm -rf "$TOOLKIT_DIR" 2>/dev/null
|
|
||||||
|
|
||||||
clear
|
|
||||||
echo ""
|
|
||||||
echo -e "${GREEN}✓ All traces removed from files${NC}"
|
|
||||||
echo ""
|
|
||||||
echo -e "${YELLOW}IMPORTANT: Your current shell still has history in memory.${NC}"
|
|
||||||
echo -e "${YELLOW}Run these commands to finish:${NC}"
|
|
||||||
echo ""
|
|
||||||
echo "history -c"
|
|
||||||
echo "unset HISTFILE"
|
|
||||||
echo "exit"
|
|
||||||
echo ""
|
|
||||||
echo "Then start a new shell."
|
|
||||||
echo ""
|
echo ""
|
||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Wrapper script for Server Toolkit
|
||||||
|
################################################################################
|
||||||
|
# This wrapper allows proper history cleanup by running in the current shell
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
# Check if being sourced or executed
|
||||||
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
|
echo "ERROR: This script must be sourced, not executed."
|
||||||
|
echo ""
|
||||||
|
echo "Run it like this:"
|
||||||
|
echo " source $0"
|
||||||
|
echo ""
|
||||||
|
echo "Or use the alias:"
|
||||||
|
echo " . $0"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the launcher
|
||||||
|
bash "$SCRIPT_DIR/launcher.sh"
|
||||||
|
|
||||||
|
# Check if cleanup is requested
|
||||||
|
if [ -f /tmp/.cleanup_requested ]; then
|
||||||
|
rm -f /tmp/.cleanup_requested
|
||||||
|
|
||||||
|
# Clean history in current shell
|
||||||
|
GREP_PATTERN="git\.mull\.lol|linux-server-management-toolkit|server-toolkit|launcher\.sh|erase-toolkit-traces|run\.sh"
|
||||||
|
|
||||||
|
if [ -f ~/.bash_history ]; then
|
||||||
|
cp ~/.bash_history ~/.bash_history.bak.$$
|
||||||
|
grep -Ev "$GREP_PATTERN" ~/.bash_history.bak.$$ > ~/.bash_history 2>/dev/null || true
|
||||||
|
rm -f ~/.bash_history.bak.$$
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clear current shell's history
|
||||||
|
history -c
|
||||||
|
history -r ~/.bash_history
|
||||||
|
unset HISTFILE
|
||||||
|
set +o history
|
||||||
|
|
||||||
|
# Remove toolkit directory
|
||||||
|
cd /root 2>/dev/null
|
||||||
|
rm -rf "$SCRIPT_DIR" 2>/dev/null
|
||||||
|
|
||||||
|
clear
|
||||||
|
echo ""
|
||||||
|
echo "✓ All traces removed"
|
||||||
|
echo ""
|
||||||
|
echo "Type 'exit' and start a new shell."
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user