mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 20:07:04 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
99 lines
3.3 KiB
Bash
Executable File
99 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# The flash phase, SSH key setup and dependency checks.
|
|
#
|
|
# Sourced by setup_nextcloud_raspberry.sh; split out to keep nc_image.sh under the
|
|
# 250-line cap. Sourced rather than run, so it inherits the caller's
|
|
# strict mode and the variables defined above the source line.
|
|
|
|
phase_flash() {
|
|
check_root
|
|
|
|
log_info "=== Phase 1: Flash Raspberry Pi OS to SD Card (Local) ==="
|
|
|
|
detect_sd_card
|
|
local image_path
|
|
image_path=$(download_raspberry_pi_os)
|
|
flash_sd_card "$image_path"
|
|
configure_headless_boot
|
|
|
|
log_success "Phase 1 complete!"
|
|
echo
|
|
log_info "Next steps:"
|
|
log_info "1. Insert the SD card into your Raspberry Pi 5"
|
|
log_info "2. Connect the Pi to power and network"
|
|
log_info "3. Wait 2-3 minutes for first boot"
|
|
log_info "4. Find the Pi's IP address and SSH: ssh ${PI_USER}@<ip-address>"
|
|
log_info "5. Copy this script to the Pi and run: sudo ./setup_nextcloud_raspberry.sh configure"
|
|
}
|
|
|
|
# =============================================================================
|
|
# PHASE 1B: Flash Raspberry Pi OS to SD Card on Remote Laptop
|
|
# =============================================================================
|
|
|
|
setup_ssh_key_to_remote() {
|
|
local remote_host="$1"
|
|
local remote_user="$2"
|
|
|
|
# Check if we already have passwordless access
|
|
if ssh -o BatchMode=yes -o ConnectTimeout=5 "${remote_user}@${remote_host}" "echo 'SSH key works'" 2>/dev/null; then
|
|
log_success "SSH key authentication to ${remote_user}@${remote_host} already configured"
|
|
return 0
|
|
fi
|
|
|
|
log_info "Setting up SSH key authentication to ${remote_user}@${remote_host}..."
|
|
|
|
# Check if SSH key exists, if not create one
|
|
if [[ ! -f "$HOME/.ssh/id_ed25519" ]] && [[ ! -f "$HOME/.ssh/id_rsa" ]]; then
|
|
log_info "No SSH key found, generating one..."
|
|
ssh-keygen -t ed25519 -f "$HOME/.ssh/id_ed25519" -N "" -C "$(whoami)@$(hostname)"
|
|
log_success "SSH key generated"
|
|
fi
|
|
|
|
# Copy SSH key to remote host using sshpass if password provided, otherwise prompt
|
|
log_info "Copying SSH key to remote laptop (you will be prompted for password)..."
|
|
ssh-copy-id -o StrictHostKeyChecking=accept-new "${remote_user}@${remote_host}"
|
|
|
|
# Verify it works
|
|
if ssh -o BatchMode=yes -o ConnectTimeout=5 "${remote_user}@${remote_host}" "echo 'SSH key works'" 2>/dev/null; then
|
|
log_success "SSH key authentication configured successfully"
|
|
return 0
|
|
else
|
|
die "Failed to set up SSH key authentication"
|
|
fi
|
|
}
|
|
|
|
ensure_dependencies() {
|
|
log_info "Ensuring required tools are installed..."
|
|
|
|
local missing_packages=()
|
|
|
|
# Check for nmap (fast network scanning)
|
|
if ! command -v nmap &>/dev/null; then
|
|
missing_packages+=("nmap")
|
|
fi
|
|
|
|
# Check for sshpass (for initial SSH key setup)
|
|
if ! command -v sshpass &>/dev/null; then
|
|
missing_packages+=("sshpass")
|
|
fi
|
|
|
|
if [[ ${#missing_packages[@]} -gt 0 ]]; then
|
|
log_info "Installing missing packages: ${missing_packages[*]}"
|
|
|
|
# Detect package manager and install
|
|
if command -v pacman &>/dev/null; then
|
|
sudo pacman -S --noconfirm "${missing_packages[@]}"
|
|
elif command -v apt-get &>/dev/null; then
|
|
sudo apt-get update && sudo apt-get install -y "${missing_packages[@]}"
|
|
elif command -v dnf &>/dev/null; then
|
|
sudo dnf install -y "${missing_packages[@]}"
|
|
elif command -v yum &>/dev/null; then
|
|
sudo yum install -y "${missing_packages[@]}"
|
|
else
|
|
die "Could not detect package manager. Please install manually: ${missing_packages[*]}"
|
|
fi
|
|
|
|
log_success "Dependencies installed"
|
|
fi
|
|
}
|