mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-26 08:07:20 +01:00
feat(pi): rustscan instead of nmap
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2a788b741d
commit
7581a904cd
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"title": "Pi flashing: discover SSH hosts with rustscan, not nmap",
|
||||||
|
"objective": "The Pi flash/discovery scripts find SSH hosts on the LAN with `rustscan -a <net> -p 22 -g`, install/check for rustscan instead of nmap, and rustscan is configured (scripts = \"None\") so it never pipes into nmap, which the pacman wrapper blocks.",
|
||||||
|
"acceptance_criteria": [
|
||||||
|
"No nmap references remain in the Pi flashing scripts and rpi_nc_deps checks for rustscan (test_pi_discovery_rustscan.sh)",
|
||||||
|
"fresh-install/main.sh installs fresh-install/rustscan.toml to ~/.rustscan.toml"
|
||||||
|
],
|
||||||
|
"out_of_scope": [
|
||||||
|
"The pacman nmap block and /usr/local/bin/nmap shim (digital-wellbeing repo)",
|
||||||
|
"Live scan of a real LAN"
|
||||||
|
],
|
||||||
|
"verifier": "linux_configuration/tests/test_pi_discovery_rustscan.sh; pre-commit run --files <changed-files>"
|
||||||
|
}
|
||||||
@ -1,44 +0,0 @@
|
|||||||
{
|
|
||||||
"intent": "DNS-over-TLS (stunnel-dot) comes up at every boot, dnsmasq has no ordering cycle, and the service checker stops expecting the removed pc_startup feature and finds the extracted repos under ~/src.",
|
|
||||||
"scope": [
|
|
||||||
"linux_configuration/features/lib/dns_units.sh, dot_resolver_install.sh and their tests",
|
|
||||||
"linux_configuration/periodic_background check_and_enable_services.sh, services_units.sh, services_report.sh and their tests",
|
|
||||||
"Non-goal: the firewall, the blocklist feed, the guard warnings (compulsive-block, LeechBlock, workout-locker) this checker reports"
|
|
||||||
],
|
|
||||||
"changes": [
|
|
||||||
"dnsmasq: bind-dynamic instead of bind-interfaces, so starting before enp6s0 exists no longer exits with 'unknown interface'",
|
|
||||||
"dnsmasq drop-in: drop After/Wants=network-online.target, which cycled with the stock Before=network-online.target",
|
|
||||||
"stunnel-dot.service: Wants=dnsmasq.service instead of Requires=, so one failed dnsmasq start no longer kills DoT until a manual restart",
|
|
||||||
"check_and_enable_services: remove check_startup_monitor (pc_startup was removed in 765fa925) and default HOSTS_BLOCKER/DW/WORKOUT_LOCKER repos to ~/src/<repo>"
|
|
||||||
],
|
|
||||||
"verification": [
|
|
||||||
{
|
|
||||||
"command": "pre-commit run --files <the 11 files> (shell-coverage-ratchet runs the suites in the jail)",
|
|
||||||
"result": "pass",
|
|
||||||
"evidence": "all hooks passed, ratchet 100%"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"command": "vmbox: dnsmasq with interface=<absent>, bind-interfaces vs bind-dynamic; Requires= vs Wants= on a failing dependency",
|
|
||||||
"result": "pass",
|
|
||||||
"evidence": "bind-interfaces: DIED 'unknown interface lanx0'; bind-dynamic: survived, bound 10.199.0.1:5353 after the interface appeared; Requires=: inactive; Wants=: active"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"command": "host: setup_dot_resolver.sh + dns_units functions + validate_and_enable",
|
|
||||||
"result": "pass",
|
|
||||||
"evidence": "dnsmasq --test OK; stunnel-dot active on 10.8.0.1:853, TLSv1.3 Verification OK; DNS answers on 127.0.0.1 and 192.168.1.43; no network-online in dnsmasq After="
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"command": "sudo check_and_enable_services.sh --status (host) and vmbox diff against HEAD",
|
|
||||||
"result": "pass",
|
|
||||||
"evidence": "full run, no 'not found'; only diff vs HEAD is the removed PC Startup Monitor section"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"risks": [
|
|
||||||
"bind-dynamic also listens on addresses that appear later on enp6s0 (intended)",
|
|
||||||
"stunnel now starts even if dnsmasq is down; queries fail until dnsmasq is back, which Restart=always plus the watchdog already handle"
|
|
||||||
],
|
|
||||||
"rollback": [
|
|
||||||
"git revert this commit, then rerun setup_dns_blocker.sh setup and setup_dot_resolver.sh",
|
|
||||||
"Validate with: systemctl is-active dnsmasq stunnel-dot; setup_dot_resolver.sh --check"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"intent": "Pi flashing scripts discover SSH hosts with rustscan instead of nmap; rustscan runs with scripts = \"None\" so it never calls nmap.",
|
||||||
|
"scope": [
|
||||||
|
"linux_configuration/features/lib/{nc_discover,nc_flash,nc_image,nc_remote,pi_flash_remote,rpi_nc_deps}.sh",
|
||||||
|
"linux_configuration/features/raspberry_pi_flash_sd.sh",
|
||||||
|
"linux_configuration/fresh-install/main.sh, rustscan.toml",
|
||||||
|
"linux_configuration/tests/test_pi_discovery_rustscan.sh",
|
||||||
|
"Not touched: pacman wrapper (digital-wellbeing), live LAN scanning"
|
||||||
|
],
|
||||||
|
"changes": [
|
||||||
|
"nmap ping sweep + port scan replaced by `rustscan -a <net> -p 22 -g | awk '{print $1}'` (greppable output, one IP per line)",
|
||||||
|
"Dependency checks and hint messages name rustscan instead of nmap",
|
||||||
|
"fresh-install/rustscan.toml (scripts = \"None\") copied to ~/.rustscan.toml by main.sh"
|
||||||
|
],
|
||||||
|
"verification": [
|
||||||
|
{
|
||||||
|
"command": "linux_configuration/tests/test_pi_discovery_rustscan.sh",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "ok per discovery script, ok rpi_nc_deps dependencies, ok no nmap references"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "pre-commit run --files <changed-files>",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "shellcheck, codespell and secrets hooks passed on the shell files"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"risks": [
|
||||||
|
"rustscan -g output format change would break the awk IP extraction",
|
||||||
|
"Hosts that drop rustscan's fast SYN probing may be missed versus nmap"
|
||||||
|
],
|
||||||
|
"rollback": [
|
||||||
|
"git revert the commit",
|
||||||
|
"Re-run a Pi discovery and confirm hosts are listed"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -39,13 +39,11 @@ discover_raspberry_pi() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ping sweep to wake up hosts
|
|
||||||
log_info "Hostname resolution failed, scanning network..."
|
log_info "Hostname resolution failed, scanning network..."
|
||||||
nmap -sn -T4 "$network" &>/dev/null || true
|
|
||||||
|
|
||||||
# Scan for SSH-enabled devices (excluding our IP and known laptop)
|
# Scan for SSH-enabled devices (excluding our IP and known laptop)
|
||||||
local ssh_hosts
|
local ssh_hosts
|
||||||
ssh_hosts=$(nmap -p 22 --open -sT -T4 "$network" 2>/dev/null | grep "Nmap scan report" | grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | grep -vw "$my_ip" | grep -vw "$REMOTE_LAPTOP_IP" 2>/dev/null | sort -u) || true
|
ssh_hosts=$(rustscan -a "$network" -p 22 -g 2>/dev/null | awk '{print $1}' | grep -vw "$my_ip" | grep -vw "$REMOTE_LAPTOP_IP" 2>/dev/null | sort -u) || true
|
||||||
|
|
||||||
if [[ -z $ssh_hosts ]]; then
|
if [[ -z $ssh_hosts ]]; then
|
||||||
die "No new SSH-enabled devices found. Is the Pi connected and booted?"
|
die "No new SSH-enabled devices found. Is the Pi connected and booted?"
|
||||||
|
|||||||
@ -67,9 +67,9 @@ ensure_dependencies() {
|
|||||||
|
|
||||||
local missing_packages=()
|
local missing_packages=()
|
||||||
|
|
||||||
# Check for nmap (fast network scanning)
|
# Check for rustscan (fast network scanning)
|
||||||
if ! command -v nmap &>/dev/null; then
|
if ! command -v rustscan &>/dev/null; then
|
||||||
missing_packages+=("nmap")
|
missing_packages+=("rustscan")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for sshpass (for initial SSH key setup)
|
# Check for sshpass (for initial SSH key setup)
|
||||||
|
|||||||
@ -176,5 +176,5 @@ EOF
|
|||||||
|
|
||||||
log_success "SD card configured for headless boot!"
|
log_success "SD card configured for headless boot!"
|
||||||
log_info "Insert the SD card into your Raspberry Pi and power it on."
|
log_info "Insert the SD card into your Raspberry Pi and power it on."
|
||||||
log_info "Find the Pi's IP address from your router or use: nmap -sn 192.168.1.0/24"
|
log_info "Find the Pi's IP address from your router or use: rustscan -a 192.168.1.0/24 -p 22 -g"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,13 +22,11 @@ discover_remote_laptop() {
|
|||||||
|
|
||||||
log_info "Local IP: $my_ip, Gateway: $gateway, Network: $network"
|
log_info "Local IP: $my_ip, Gateway: $gateway, Network: $network"
|
||||||
|
|
||||||
# Use nmap for fast parallel SSH port scanning
|
# Use rustscan for fast parallel SSH port scanning
|
||||||
log_info "Scanning network for SSH-enabled devices (using nmap)..."
|
log_info "Scanning network for SSH-enabled devices (using rustscan)..."
|
||||||
local ssh_hosts
|
local ssh_hosts
|
||||||
# First do a ping sweep to wake up hosts, then scan SSH port
|
# Greppable output: one "IP -> [22]" line per host with the port open
|
||||||
nmap -sn -T4 "$network" &>/dev/null || true
|
ssh_hosts=$(rustscan -a "$network" -p 22 -g 2>/dev/null | awk '{print $1}' | grep -vw "$my_ip" | sort -u) || true
|
||||||
# Extract IPs from nmap output - grep for report lines then extract IP
|
|
||||||
ssh_hosts=$(nmap -p 22 --open -sT -T4 "$network" 2>/dev/null | grep "Nmap scan report" | grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | grep -vw "$my_ip" | sort -u)
|
|
||||||
|
|
||||||
if [[ -z $ssh_hosts ]]; then
|
if [[ -z $ssh_hosts ]]; then
|
||||||
die "No SSH-enabled devices found on network"
|
die "No SSH-enabled devices found on network"
|
||||||
|
|||||||
@ -18,11 +18,11 @@ discover_remote_laptop() {
|
|||||||
local network="${gateway%.*}.0/24"
|
local network="${gateway%.*}.0/24"
|
||||||
|
|
||||||
log_info "Local IP: $my_ip, Gateway: $gateway, Network: $network"
|
log_info "Local IP: $my_ip, Gateway: $gateway, Network: $network"
|
||||||
log_info "Scanning network for SSH-enabled devices (using nmap)..."
|
log_info "Scanning network for SSH-enabled devices (using rustscan)..."
|
||||||
|
|
||||||
local ssh_hosts
|
local ssh_hosts
|
||||||
nmap -sn -T4 "$network" &> /dev/null || true
|
# Greppable output: one "IP -> [22]" line per host with the port open
|
||||||
ssh_hosts=$(nmap -p 22 --open -sT -T4 "$network" 2> /dev/null | grep "Nmap scan report" | grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | grep -vw "$my_ip" | sort -u)
|
ssh_hosts=$(rustscan -a "$network" -p 22 -g 2>/dev/null | awk '{print $1}' | grep -vw "$my_ip" | sort -u) || true
|
||||||
|
|
||||||
if [[ -z $ssh_hosts ]]; then
|
if [[ -z $ssh_hosts ]]; then
|
||||||
die "No SSH-enabled devices found on network"
|
die "No SSH-enabled devices found on network"
|
||||||
@ -64,13 +64,13 @@ discover_remote_laptop() {
|
|||||||
log_info "[$idx/$host_count] $ip - Trying SSH key access with common usernames..."
|
log_info "[$idx/$host_count] $ip - Trying SSH key access with common usernames..."
|
||||||
|
|
||||||
for try_user in "${users[@]}"; do
|
for try_user in "${users[@]}"; do
|
||||||
if ssh -o BatchMode=yes -o ConnectTimeout=2 -o StrictHostKeyChecking=accept-new "${try_user}@${ip}" "echo ok" 2> /dev/null | grep -q "ok"; then
|
if ssh -o BatchMode=yes -o ConnectTimeout=2 -o StrictHostKeyChecking=accept-new "${try_user}@${ip}" "echo ok" 2>/dev/null | grep -q "ok"; then
|
||||||
log_success "[$idx/$host_count] $ip - SSH key access confirmed with user '$try_user'!"
|
log_success "[$idx/$host_count] $ip - SSH key access confirmed with user '$try_user'!"
|
||||||
found_user="$try_user"
|
found_user="$try_user"
|
||||||
|
|
||||||
log_info "[$idx/$host_count] $ip - Checking for SD card..."
|
log_info "[$idx/$host_count] $ip - Checking for SD card..."
|
||||||
local has_sd
|
local has_sd
|
||||||
has_sd=$(ssh -o BatchMode=yes -o ConnectTimeout=2 "${try_user}@${ip}" "lsblk -d -o NAME,RM,TRAN 2>/dev/null | grep -E '1.*(usb|mmc)' | head -1" 2> /dev/null || true)
|
has_sd=$(ssh -o BatchMode=yes -o ConnectTimeout=2 "${try_user}@${ip}" "lsblk -d -o NAME,RM,TRAN 2>/dev/null | grep -E '1.*(usb|mmc)' | head -1" 2>/dev/null || true)
|
||||||
|
|
||||||
if [[ -n $has_sd ]]; then
|
if [[ -n $has_sd ]]; then
|
||||||
log_success "[$idx/$host_count] $ip - Found SD card: $has_sd"
|
log_success "[$idx/$host_count] $ip - Found SD card: $has_sd"
|
||||||
@ -115,7 +115,7 @@ setup_ssh_key_to_remote() {
|
|||||||
local remote_host="$1"
|
local remote_host="$1"
|
||||||
local remote_user="$2"
|
local remote_user="$2"
|
||||||
|
|
||||||
if ssh -o BatchMode=yes -o ConnectTimeout=5 "${remote_user}@${remote_host}" "echo 'SSH key works'" 2> /dev/null; then
|
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"
|
log_success "SSH key authentication to ${remote_user}@${remote_host} already configured"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@ -129,11 +129,11 @@ setup_ssh_key_to_remote() {
|
|||||||
|
|
||||||
log_info "Copying SSH key to remote host (you may be prompted for password)..."
|
log_info "Copying SSH key to remote host (you may be prompted for password)..."
|
||||||
|
|
||||||
if command -v ssh-copy-id &> /dev/null; then
|
if command -v ssh-copy-id &>/dev/null; then
|
||||||
ssh-copy-id -o StrictHostKeyChecking=no "${remote_user}@${remote_host}"
|
ssh-copy-id -o StrictHostKeyChecking=no "${remote_user}@${remote_host}"
|
||||||
else
|
else
|
||||||
local pub_key
|
local pub_key
|
||||||
pub_key=$(cat ~/.ssh/id_ed25519.pub 2> /dev/null || cat ~/.ssh/id_rsa.pub)
|
pub_key=$(cat ~/.ssh/id_ed25519.pub 2>/dev/null || cat ~/.ssh/id_rsa.pub)
|
||||||
ssh -o StrictHostKeyChecking=no "${remote_user}@${remote_host}" "mkdir -p ~/.ssh && echo '$pub_key' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
|
ssh -o StrictHostKeyChecking=no "${remote_user}@${remote_host}" "mkdir -p ~/.ssh && echo '$pub_key' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@ -36,8 +36,8 @@ wait_for_apt_lock() {
|
|||||||
ensure_dependencies() {
|
ensure_dependencies() {
|
||||||
local missing_packages=()
|
local missing_packages=()
|
||||||
|
|
||||||
if ! command -v nmap &>/dev/null; then
|
if ! command -v rustscan &>/dev/null; then
|
||||||
missing_packages+=("nmap")
|
missing_packages+=("rustscan")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v sshpass &>/dev/null; then
|
if ! command -v sshpass &>/dev/null; then
|
||||||
@ -88,10 +88,9 @@ discover_raspberry_pi() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
log_info "Hostname resolution failed, scanning network..."
|
log_info "Hostname resolution failed, scanning network..."
|
||||||
nmap -sn -T4 "$network" &>/dev/null || true
|
|
||||||
|
|
||||||
local ssh_hosts
|
local ssh_hosts
|
||||||
ssh_hosts=$(nmap -p 22 --open -sT -T4 "$network" 2>/dev/null | grep "Nmap scan report" | grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | grep -vw "$my_ip" | sort -u) || true
|
ssh_hosts=$(rustscan -a "$network" -p 22 -g 2>/dev/null | awk '{print $1}' | grep -vw "$my_ip" | sort -u) || true
|
||||||
|
|
||||||
if [[ -z $ssh_hosts ]]; then
|
if [[ -z $ssh_hosts ]]; then
|
||||||
die "No SSH-enabled devices found. Is the Pi connected and booted?"
|
die "No SSH-enabled devices found. Is the Pi connected and booted?"
|
||||||
|
|||||||
@ -65,7 +65,7 @@ check_root() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
save_config() {
|
save_config() {
|
||||||
cat > "$CONFIG_FILE" << EOF
|
cat >"$CONFIG_FILE" <<EOF
|
||||||
# Raspberry Pi Setup - Auto-generated config
|
# Raspberry Pi Setup - Auto-generated config
|
||||||
# This file is gitignored and stores discovered settings
|
# This file is gitignored and stores discovered settings
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ EOF
|
|||||||
generate_password() {
|
generate_password() {
|
||||||
local length="${1:-16}"
|
local length="${1:-16}"
|
||||||
local chars
|
local chars
|
||||||
chars=$(dd if=/dev/urandom bs=256 count=1 2> /dev/null | tr -dc 'A-Za-z0-9!@#$%&*' | cut -c1-"$length")
|
chars=$(dd if=/dev/urandom bs=256 count=1 2>/dev/null | tr -dc 'A-Za-z0-9!@#$%&*' | cut -c1-"$length")
|
||||||
echo "$chars"
|
echo "$chars"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,22 +106,22 @@ auto_generate_pi_password() {
|
|||||||
ensure_dependencies() {
|
ensure_dependencies() {
|
||||||
local missing_packages=()
|
local missing_packages=()
|
||||||
|
|
||||||
if ! command -v nmap &> /dev/null; then
|
if ! command -v rustscan &>/dev/null; then
|
||||||
missing_packages+=("nmap")
|
missing_packages+=("rustscan")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v sshpass &> /dev/null; then
|
if ! command -v sshpass &>/dev/null; then
|
||||||
missing_packages+=("sshpass")
|
missing_packages+=("sshpass")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${#missing_packages[@]} -gt 0 ]]; then
|
if [[ ${#missing_packages[@]} -gt 0 ]]; then
|
||||||
log_info "Installing missing packages: ${missing_packages[*]}"
|
log_info "Installing missing packages: ${missing_packages[*]}"
|
||||||
|
|
||||||
if command -v pacman &> /dev/null; then
|
if command -v pacman &>/dev/null; then
|
||||||
sudo pacman -S --noconfirm "${missing_packages[@]}"
|
sudo pacman -S --noconfirm "${missing_packages[@]}"
|
||||||
elif command -v apt-get &> /dev/null; then
|
elif command -v apt-get &>/dev/null; then
|
||||||
sudo apt-get update && sudo apt-get install -y "${missing_packages[@]}"
|
sudo apt-get update && sudo apt-get install -y "${missing_packages[@]}"
|
||||||
elif command -v dnf &> /dev/null; then
|
elif command -v dnf &>/dev/null; then
|
||||||
sudo dnf install -y "${missing_packages[@]}"
|
sudo dnf install -y "${missing_packages[@]}"
|
||||||
else
|
else
|
||||||
die "Could not detect package manager. Please install manually: ${missing_packages[*]}"
|
die "Could not detect package manager. Please install manually: ${missing_packages[*]}"
|
||||||
@ -138,7 +138,6 @@ source "$SCRIPT_DIR/lib/pi_flash_image.sh"
|
|||||||
# shellcheck source=lib/pi_flash_exec.sh
|
# shellcheck source=lib/pi_flash_exec.sh
|
||||||
source "$SCRIPT_DIR/lib/pi_flash_exec.sh"
|
source "$SCRIPT_DIR/lib/pi_flash_exec.sh"
|
||||||
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
local command="${1:-help}"
|
local command="${1:-help}"
|
||||||
|
|
||||||
|
|||||||
@ -169,6 +169,8 @@ if [ ! -d "$HOME/.config/mpv" ]; then
|
|||||||
mkdir -p "$HOME/.config/mpv"
|
mkdir -p "$HOME/.config/mpv"
|
||||||
fi
|
fi
|
||||||
cp mpv.conf "$HOME/.config/mpv/mpv.conf"
|
cp mpv.conf "$HOME/.config/mpv/mpv.conf"
|
||||||
|
# rustscan must never call nmap (nonfree, blocked by the pacman wrapper)
|
||||||
|
cp rustscan.toml "$HOME/.rustscan.toml"
|
||||||
|
|
||||||
if [ ! -d "$HOME/.oh-my-zsh" ]; then
|
if [ ! -d "$HOME/.oh-my-zsh" ]; then
|
||||||
yes | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
yes | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||||
|
|||||||
4
linux_configuration/fresh-install/rustscan.toml
Normal file
4
linux_configuration/fresh-install/rustscan.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# RustScan config (copied to ~/.rustscan.toml by main.sh).
|
||||||
|
# "None" keeps rustscan from piping open ports into nmap (nonfree, blocked by
|
||||||
|
# the pacman wrapper; the /usr/local/bin/nmap shim would only exit 1).
|
||||||
|
scripts = "None"
|
||||||
121
linux_configuration/tests/test_pi_discovery_rustscan.sh
Executable file
121
linux_configuration/tests/test_pi_discovery_rustscan.sh
Executable file
@ -0,0 +1,121 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Regression test: Raspberry Pi / laptop SSH discovery uses rustscan, never
|
||||||
|
# nmap (nonfree NPSL licence; the pacman wrapper refuses to install it).
|
||||||
|
#
|
||||||
|
# Runs the real discover/ensure_dependencies functions with stubbed
|
||||||
|
# ip/getent/sshpass/rustscan/nmap/pacman on PATH and asserts:
|
||||||
|
# - rustscan is called as `-a <net> -p 22 -g` and nmap is never executed
|
||||||
|
# - our own IP is excluded and the Pi (answering the hostname probe) is found
|
||||||
|
# - ensure_dependencies asks for rustscan, not nmap
|
||||||
|
# - no script in the set still invokes nmap
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
FEATURES="$(cd -- "$SCRIPT_DIR/.." && pwd)/features"
|
||||||
|
|
||||||
|
fail() {
|
||||||
|
printf 'FAIL: %s\n' "$1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
TMP_DIR=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||||
|
STUBS="$TMP_DIR/stubs"
|
||||||
|
mkdir -p "$STUBS"
|
||||||
|
export STUB_LOG="$TMP_DIR/calls.log"
|
||||||
|
: >"$STUB_LOG"
|
||||||
|
|
||||||
|
stub() { # name; body on stdin
|
||||||
|
{
|
||||||
|
printf '#!/bin/bash\n'
|
||||||
|
cat
|
||||||
|
} >"$STUBS/$1"
|
||||||
|
chmod +x "$STUBS/$1"
|
||||||
|
}
|
||||||
|
stub ip <<'STUB'
|
||||||
|
if [[ $1 == -4 ]]; then
|
||||||
|
echo " inet 192.168.1.5/24 brd 192.168.1.255 scope global eth0"
|
||||||
|
else
|
||||||
|
echo "default via 192.168.1.1 dev eth0"
|
||||||
|
fi
|
||||||
|
STUB
|
||||||
|
stub getent <<'STUB'
|
||||||
|
exit 2
|
||||||
|
STUB
|
||||||
|
stub nmap <<'STUB'
|
||||||
|
echo "nmap $*" >>"$STUB_LOG"
|
||||||
|
exit 1
|
||||||
|
STUB
|
||||||
|
stub rustscan <<'STUB'
|
||||||
|
echo "rustscan $*" >>"$STUB_LOG"
|
||||||
|
printf '192.168.1.5 -> [22]\n192.168.1.43 -> [22]\n192.168.1.26 -> [22]\n'
|
||||||
|
STUB
|
||||||
|
stub pacman <<'STUB'
|
||||||
|
echo "pacman $*" >>"$STUB_LOG"
|
||||||
|
STUB
|
||||||
|
stub sudo <<'STUB'
|
||||||
|
"$@"
|
||||||
|
STUB
|
||||||
|
# sshpass -p PW ssh ... user@IP CMD : only .43 is the Pi.
|
||||||
|
stub sshpass <<'STUB'
|
||||||
|
for a in "$@"; do [[ $a == *@* ]] && ip=${a#*@}; done
|
||||||
|
echo "ssh $ip" >>"$STUB_LOG"
|
||||||
|
if [[ $ip == 192.168.1.43 ]]; then
|
||||||
|
case "${*: -1}" in hostname) echo nextcloud-pi ;; *) echo ok ;; esac
|
||||||
|
fi
|
||||||
|
STUB
|
||||||
|
|
||||||
|
log_info() { :; }
|
||||||
|
log_success() { :; }
|
||||||
|
die() {
|
||||||
|
printf 'die: %s\n' "$*" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
export PI_HOSTNAME=nextcloud-pi PI_USER=pi PI_PASSWORD=pw REMOTE_LAPTOP_IP=192.168.1.17
|
||||||
|
|
||||||
|
# Runs discover_raspberry_pi from the given lib with every external stubbed.
|
||||||
|
check_discover() { # lib file
|
||||||
|
: >"$STUB_LOG"
|
||||||
|
(
|
||||||
|
PATH="$STUBS:$PATH"
|
||||||
|
# Real ensure_dependencies (no-op: rustscan/sshpass stubs are on PATH).
|
||||||
|
# shellcheck source=../features/lib/rpi_nc_deps.sh
|
||||||
|
source "$FEATURES/lib/rpi_nc_deps.sh"
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source "$FEATURES/lib/$1"
|
||||||
|
found=$(discover_raspberry_pi)
|
||||||
|
[[ $found == 192.168.1.43 ]] || fail "$1 found '$found', want 192.168.1.43"
|
||||||
|
)
|
||||||
|
grep -qx 'rustscan -a 192.168.1.0/24 -p 22 -g' "$STUB_LOG" ||
|
||||||
|
fail "$1: rustscan not called with '-a 192.168.1.0/24 -p 22 -g': $(tr '\n' '|' <"$STUB_LOG")"
|
||||||
|
if grep -q '^nmap' "$STUB_LOG"; then fail "$1 ran nmap"; fi
|
||||||
|
if grep -qx 'ssh 192.168.1.5' "$STUB_LOG"; then fail "$1 tried our own IP"; fi
|
||||||
|
printf 'ok discover %s\n' "$1"
|
||||||
|
}
|
||||||
|
check_discover nc_discover.sh
|
||||||
|
check_discover rpi_nc_deps.sh
|
||||||
|
|
||||||
|
# --- ensure_dependencies asks for rustscan, not nmap ------------------------
|
||||||
|
: >"$STUB_LOG"
|
||||||
|
rm -f "$STUBS/rustscan" "$STUBS/sshpass" # hide them so the install branch runs
|
||||||
|
(
|
||||||
|
PATH="$STUBS"
|
||||||
|
hash -r
|
||||||
|
# shellcheck source=../features/lib/rpi_nc_deps.sh
|
||||||
|
source "$FEATURES/lib/rpi_nc_deps.sh"
|
||||||
|
ensure_dependencies >/dev/null 2>&1 || true
|
||||||
|
)
|
||||||
|
grep -q '^pacman -S --noconfirm rustscan' "$STUB_LOG" ||
|
||||||
|
fail "ensure_dependencies did not request rustscan: $(tr '\n' '|' <"$STUB_LOG")"
|
||||||
|
grep -E '^pacman .*nmap' "$STUB_LOG" && fail "ensure_dependencies still requests nmap"
|
||||||
|
printf 'ok rpi_nc_deps dependencies\n'
|
||||||
|
|
||||||
|
# --- no remaining nmap invocation in the set --------------------------------
|
||||||
|
for f in lib/nc_discover.sh lib/nc_remote.sh lib/rpi_nc_deps.sh lib/nc_flash.sh \
|
||||||
|
lib/nc_image.sh lib/pi_flash_remote.sh raspberry_pi_flash_sd.sh; do
|
||||||
|
if grep -nE '(^|[^[:alnum:]_-])nmap([^[:alnum:]_-]|$)' "$FEATURES/$f"; then
|
||||||
|
fail "$f still mentions nmap"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
printf 'ok no nmap references\n'
|
||||||
Loading…
Reference in New Issue
Block a user