Adding all files and folders

This commit is contained in:
2026-02-01 12:08:31 +11:00
parent 892f3f2418
commit 1fb54400b4
24 changed files with 63803 additions and 0 deletions

138
scripts/01_system_recon.sh Executable file
View File

@@ -0,0 +1,138 @@
#!/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."

View File

@@ -0,0 +1,91 @@
#!/bin/bash
# ---
# Configuration ---
# ---
LOG_FILE="logs/02_file_migration.log"
DRY_RUN=""
SOURCE_HOME="/home/sam" # This should be the path where your old home is mounted
TARGET_STAGING="/mnt/ubuntu_storage_3TB/migration_staging" # As per the guide
# Check for --dry-run flag
if [ "$1" == "--dry-run" ]; then
DRY_RUN="--dry-run"
echo "---
PERFORMING DRY RUN ---" | tee -a "$LOG_FILE"
fi
# Safety check for root user
if [ "$(id -u)" -eq 0 ] && [ "$2" != "--allow-root" ]; then
echo "Running as root is not recommended. Use --allow-root to override."
exit 1
fi
# ---
# Helper Functions ---
# ---
log() {
echo "$1" | tee -a "$LOG_FILE"
}
run_rsync() {
log "------------------------------------------------------------------------"
log "Syncing $1..."
# The --info=progress2 flag gives a cleaner total progress indicator.
# The --exclude='/data' is critical to not re-copy existing data.
rsync -avh --info=progress2 $DRY_RUN --exclude='/data' "$2" "$3"
log "Finished syncing $1."
log "------------------------------------------------------------------------"
}
# ---
# Main Execution ---
# ---
# Initialize log file
echo "File Migration Log - $(date)" > "$LOG_FILE"
echo "----------------------------------------------------" >> "$LOG_FILE"
if [ -n "$DRY_RUN" ]; then
log "Dry run mode enabled. No files will be changed."
fi
log "Source directory: $SOURCE_HOME"
log "Target staging directory: $TARGET_STAGING"
# Check if source directory exists
if [ ! -d "$SOURCE_HOME" ]; then
log "ERROR: Source directory $SOURCE_HOME does not exist. Mount your old home directory and try again."
exit 1
fi
# Create target directory
log "Creating target staging directory (if it doesn\'t exist)..."
if [ -z "$DRY_RUN" ]; then
mkdir -p "$TARGET_STAGING"
fi
# ---
# Migration Commands ---
# ---
# These commands will copy your main user folders from your old Ubuntu home
# into the staging area. The structure is kept simple for later organization.
# Note the trailing slash on the source to copy the *contents* of the directory.
run_rsync "Documents" "${SOURCE_HOME}/Documents/" "${TARGET_STAGING}/Documents/"
run_rsync "Pictures" "${SOURCE_HOME}/Pictures/" "${TARGET_STAGING}/Pictures/"
run_rsync "Music" "${SOURCE_HOME}/Music/" "${TARGET_STAGING}/Music/"
run_rsync "Videos" "${SOURCE_HOME}/Videos/" "${TARGET_STAGING}/Videos/"
run_rsync "Desktop" "${SOURCE_HOME}/Desktop/" "${TARGET_STAGING}/Desktop/"
run_rsync "Downloads" "${SOURCE_HOME}/Downloads/" "${TARGET_STAGING}/Downloads/"
run_rsync "Dotfiles" "${SOURCE_HOME}/dotfiles/" "${TARGET_STAGING}/dotfiles/"
# Add any other specific project directories you know of here. For example:
# run_rsync "Arduino Projects" "${SOURCE_HOME}/Arduino/" "${TARGET_STAGING}/Arduino/"
log "\n"
log "---
File migration script finished. ---"
log "Review the output above. If everything looks correct, you can run the script"
log "again without the --dry-run flag to perform the actual file copy."
log "The log has been saved to $LOG_FILE"

View File

@@ -0,0 +1,146 @@
#!/bin/bash
# -- Configuration ---
LOG_FILE="logs/03_find_and_sync_data.log"
DRY_RUN=""
SOURCE_WIN_DRIVE="/media/sam/8294CD2994CD2111"
TARGET_DATA_DIR="/data"
# Check for --dry-run flag
if [ "$1" == "--dry-run" ]; then
DRY_RUN="--dry-run"
echo "--- PERFORMING DRY RUN ---" | tee -a "$LOG_FILE"
fi
# Helper function for logging
log() {
echo "$1" | tee -a "$LOG_FILE"
}
run_rsync_dry_run() {
local source_path="$1"
local target_path="$2"
local descriptive_name="$3"
log "------------------------------------------------------------------------"
log "Preparing to sync: $descriptive_name"
log "Source: $source_path"
log "Target: $target_path"
log "------------------------------------------------------------------------"
# Ensure target directory exists for rsync
if [ ! -d "$target_path" ]; then
log "Creating target directory: $target_path"
if [ -z "$DRY_RUN" ]; then
mkdir -p "$target_path"
fi
fi
# Use rsync -a (archive mode) for comprehensive copying, and -n for dry run.
# The trailing slash on source_path copies contents, not the directory itself.
rsync -avh --info=progress2 $DRY_RUN "${source_path}/" "${target_path}/" 2>&1 | tee -a "$LOG_FILE"
log "Finished dry run for $descriptive_name."
}
# Initialize log file
echo "Data Discovery and Sync Log - $(date)" > "$LOG_FILE"
echo "----------------------------------------------------" >> "$LOG_FILE"
if [ -n "$DRY_RUN" ]; then
log "Dry run mode enabled. No files will be changed."
fi
log "Source Windows Drive: $SOURCE_WIN_DRIVE"
log "Target Data Directory: $TARGET_DATA_DIR"
log ""
# --- Mapping Configuration (Source on Windows Drive -> Target in /data) ---
# Each entry is: "source_path" "target_subdirectory_in_data" "descriptive_name"
# Personal Documents, Pictures, Music, Videos
declare -a PERSONAL_FOLDERS=(
"Users/sam/Documents" "personal/Documents" "Personal Documents"
"Users/sam/Pictures" "personal/Pictures" "Personal Pictures"
"Users/sam/Music" "personal/Music" "Personal Music"
"Users/sam/Videos" "personal/Videos" "Personal Videos"
"Users/sam/Downloads" "personal/Downloads" "Personal Downloads"
)
# Web/Work Projects
declare -a WORK_PROJECTS=(
"xampp/htdocs" "work/htdocs" "XAMPP htdocs projects"
"frei0r" "work/frei0r" "Frei0r Projects"
# Add other common workspace/project folders here if known
# e.g., "Users/sam/workspace" "work/workspace" "General Workspaces"
)
# IoT Projects
declare -a IOT_PROJECTS=(
"Arduino" "iot/Arduino" "Arduino Projects" # Assuming there's an Arduino folder
)
# Generic project folders to search for
declare -a GENERIC_PROJECT_NAMES=(
"Projects"
"Code"
"Dev"
)
# --- Execute mappings ---
log "--- Processing Personal Folders ---"
for ((i=0; i<${#PERSONAL_FOLDERS[@]}; i+=3)); do
SOURCE="${SOURCE_WIN_DRIVE}/${PERSONAL_FOLDERS[i]}"
TARGET="${TARGET_DATA_DIR}/${PERSONAL_FOLDERS[i+1]}"
DESC="${PERSONAL_FOLDERS[i+2]}"
if [ -d "$SOURCE" ]; then
run_rsync_dry_run "$SOURCE" "$TARGET" "$DESC"
else
log "WARNING: Source directory not found: $SOURCE"
fi
done
log ""
log "--- Processing Work Projects ---"
for ((i=0; i<${#WORK_PROJECTS[@]}; i+=3)); do
SOURCE="${SOURCE_WIN_DRIVE}/${WORK_PROJECTS[i]}"
TARGET="${TARGET_DATA_DIR}/${WORK_PROJECTS[i+1]}"
DESC="${WORK_PROJECTS[i+2]}"
if [ -d "$SOURCE" ]; then
run_rsync_dry_run "$SOURCE" "$TARGET" "$DESC"
else
log "WARNING: Source directory not found: $SOURCE"
fi
done
log ""
log "--- Processing IoT Projects ---"
for ((i=0; i<${#IOT_PROJECTS[@]}; i+=3)); do
SOURCE="${SOURCE_WIN_DRIVE}/${IOT_PROJECTS[i]}"
TARGET="${TARGET_DATA_DIR}/${IOT_PROJECTS[i+1]}"
DESC="${IOT_PROJECTS[i+2]}"
if [ -d "$SOURCE" ]; then
run_rsync_dry_run "$SOURCE" "$TARGET" "$DESC"
else
log "WARNING: Source directory not found: $SOURCE"
fi
done
log ""
log "--- Searching for Generic Project Folders ---"
# This section tries to find common project-like folders directly under the Windows user profile
# and prompts the user for action. For automation, we'll try to guess.
# For now, we'll just list them to avoid making assumptions without user confirmation.
log "Searching for additional project-like folders under ${SOURCE_WIN_DRIVE}/Users/sam/ and similar paths:"
find "${SOURCE_WIN_DRIVE}/Users/sam" -maxdepth 3 -type d \( -name "Projects" -o -name "Code" -o -name "Dev" -o -name "*workspace*" -o -name "*repos*" \) 2>/dev/null | while read -r found_dir; do
log "Found potential project directory: $found_dir"
# In a real interactive session, we'd ask the user where to put this.
# For now, we just log its existence.
done
log ""
log "--- Data discovery and dry run finished. ---"
log "Please review the log file: $LOG_FILE"
log "If the output looks correct, run this script again with '--live' (or no flag) to perform the actual copy."
log "Example: scripts/03_find_and_sync_data.sh"

110
scripts/04_nixos_recon.sh Normal file
View File

@@ -0,0 +1,110 @@
#!/bin/bash
#
# Phase 2: Deep System Reconnaissance for NixOS Migration
# This script gathers detailed information about installed software, services,
# configurations, and development environments on the current Ubuntu system.
# All output is logged to a file for later analysis.
# --- Configuration ---
LOG_FILE="logs/04_nixos_recon.log"
USER_HOME=$(eval echo ~${SUDO_USER:-$USER})
# --- Helper Functions ---
log() {
echo -e "$1" | tee -a "$LOG_FILE"
}
log_header() {
log "\n"
log "========================================================================"
log "=== $1"
log "========================================================================"
}
run_and_log() {
log "--- Running command: $1 ---"
eval "$1" 2>>"$LOG_FILE" | tee -a "$LOG_FILE"
log "--- Command finished ---\n"
}
# --- Main Execution ---
# Initialize log file
echo "NixOS Migration - Deep Reconnaissance Log - $(date)" > "$LOG_FILE"
echo "----------------------------------------------------" >> "$LOG_FILE"
log "User Home Directory: $USER_HOME"
# 1. Software Inventory (APT & Snap)
log_header "SOFTWARE INVENTORY"
if command -v dpkg &> /dev/null; then
run_and_log "dpkg --get-selections | grep -v deinstall"
else
log "dpkg command not found. Skipping APT package scan."
fi
if command -v snap &> /dev/null; then
run_and_log "snap list"
else
log "snap command not found. Skipping Snap package scan."
fi
# 2. Systemd Services & Timers
log_header "SYSTEMD SERVICES & TIMERS"
log "--- Active System Services ---"
run_and_log "systemctl list-units --type=service --state=running"
log "--- All System Timers ---"
run_and_log "systemctl list-timers --all"
log "\n--- Active User Services (if any) ---"
# Check for user session bus to run user commands
if [ -n "$XDG_RUNTIME_DIR" ]; then
run_and_log "systemctl --user list-units --type=service --state=running"
log "--- All User Timers (if any) ---"
run_and_log "systemctl --user list-timers --all"
else
log "Could not connect to user session bus. Skipping user services/timers."
fi
# 3. Docker Environment
log_header "DOCKER ENVIRONMENT"
if command -v docker &> /dev/null; then
run_and_log "docker --version"
run_and_log "docker info"
run_and_log "docker ps -a --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'"
run_and_log "docker images --format 'table {{.Repository}}\t{{.Tag}}\t{{.Size}}'"
run_and_log "docker volume ls"
log "--- Searching for docker-compose files in home directory ---"
run_and_log "find \"$USER_HOME\" -name \"*docker-compose.yml\" -o -name \"*compose.yml\" 2>/dev/null"
else
log "docker command not found. Skipping Docker scan."
fi
# 4. Command-Line Environment & Scripts
log_header "COMMAND-LINE TOOLS & SCRIPTS"
log "--- Top 50 Most Used Commands from History ---"
# This gives an idea of frequently used, un-packaged CLI tools
if [ -f "$USER_HOME/.bash_history" ]; then
run_and_log "cat $USER_HOME/.bash_history | sed 's/sudo //g' | awk '{print $1}' | sort | uniq -c | sort -rn | head -n 50"
elif [ -f "$USER_HOME/.zsh_history" ]; then
run_and_log "cat $USER_HOME/.zsh_history | sed 's/sudo //g' | awk '{print $1}' | sort | uniq -c | sort -rn | head -n 50"
else
log "Shell history file not found."
fi
log "--- User Cron Jobs (crontab) ---"
run_and_log "crontab -l"
log "--- Manually Installed Scripts & Binaries ---"
log "Searching in /usr/local/bin, ~/bin, and ~/.local/bin..."
run_and_log "ls -lA /usr/local/bin"
if [ -d "$USER_HOME/bin" ]; then
run_and_log "ls -lA \"$USER_HOME/bin\""
fi
if [ -d "$USER_HOME/.local/bin" ]; then
run_and_log "ls -lA \"$USER_HOME/.local/bin\""
fi
log_header "RECONNAISSANCE COMPLETE"
log "Log file saved to: $LOG_FILE"
log "This file provides a detailed snapshot of the system's software and configuration."
log "Review it carefully to plan your configuration.nix and home-manager setup."