Files
nixos-4screen/scripts/01_system_recon.sh

139 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
#
# Phase 1: System Reconnaissance Script
# This script gathers information about the system's hardware, software, and user files.
# It is designed to be non-destructive. All output is logged to a file.
# ---
# Configuration ---
# ---
LOG_FILE="logs/01_system_recon.log"
USER_HOME=$(eval echo ~${SUDO_USER:-$USER})
# ---
# Helper Functions ---
# ---
log() {
echo "$1" | tee -a "$LOG_FILE"
}
log_header() {
log "\n"
log "========================================================================"
log "=== $1"
log "========================================================================"
}
run_and_log() {
log "---
Running command: $1 ---"
eval "$1" 2>&1 | tee -a "$LOG_FILE"
log "---
Command finished ---"
}
# ---
# Main Execution ---
# ---
# Initialize log file
echo "System Reconnaissance Log - $(date)" > "$LOG_FILE"
echo "----------------------------------------------------" >> "$LOG_FILE"
# 1. Disk and Filesystem Information
log_header "DISK & FILESYSTEM INFORMATION"
run_and_log "lsblk -f"
run_and_log "df -hT"
# 2. Top-level User File Assessment
log_header "USER FILE ASSESSMENT"
log "Analyzing major directories in user home: $USER_HOME"
log "This will show the total size of each main user folder."
run_and_log "du -sh ${USER_HOME}/{Documents,Downloads,Music,Pictures,Videos,Desktop,dotfiles} 2>/dev/null"
# Note for the operator about deeper scans
log "\n"
log "NOTE: A full file listing is a long-running process."
log "The following command can be used for a more detailed scan."
log "It is recommended to run this in the background and review the output later."
log "Example for a deeper scan (creates a separate log file):"
log "# find ${USER_HOME}/Documents -type f > logs/documents_file_list.txt"
log "\n"
# 3. Software Inventory
log_header "SOFTWARE INVENTORY"
# APT Packages
log "---
Checking for APT packages... ---"
if command -v dpkg &> /dev/null; then
run_and_log "dpkg --get-selections"
else
log "dpkg command not found. Skipping APT package scan."
fi
# Snap Packages
log "---
Checking for Snap packages... ---"
if command -v snap &> /dev/null; then
run_and_log "snap list"
else
log "snap command not found. Skipping Snap package scan."
fi
# Docker Information
log_header "DOCKER INFORMATION"
if command -v docker &> /dev/null; then
log "---
Docker Version ---"
run_and_log "docker --version"
log "---
Docker Info (Configuration and Storage) ---"
run_and_log "docker info"
log "---
Docker Containers (Running and Stopped) ---"
run_and_log "docker ps -a"
log "---
Docker Images ---"
run_and_log "docker images"
log "---
Docker Volumes ---"
run_and_log "docker volume ls"
else
log "docker command not found. Skipping Docker scan."
fi
# 4. Development Environment & Servers
log_header "DEV ENVIRONMENTS & SERVERS"
# Common Languages
run_and_log "command -v rustc && rustc --version"
run_and_log "command -v node && node --version"
run_and_log "command -v python3 && python3 --version"
run_and_log "command -v go && go version"
run_and_log "command -v java && java --version"
# Common Servers
log "---
Checking for common server processes... ---"
run_and_log "ps aux | grep -E 'apache2|nginx|httpd|snapcast' | grep -v grep"
log "---
Checking for server config files... ---"
run_and_log "ls -ld /etc/apache2 /etc/nginx /etc/snapserver.conf 2>/dev/null"
# Eclipse and Arduino/ESP-IDF
log "---
Searching for Eclipse Workspaces and Arduino/ESP-IDF projects... ---"
log "This may take a moment..."
# This find command is scoped to the user's home and looks for common markers of these dev environments.
run_and_log "find ${USER_HOME} -maxdepth 4 \( -name '.project' -o -name 'platformio.ini' -o -name '*.ino' \) -print 2>/dev/null"
log_header "RECONNAISSANCE COMPLETE"
log "Log file saved to: $LOG_FILE"
log "Please review the log file to plan the next phase of the migration."
log "Remember to complete and verify your backups before proceeding."