mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 18:07:06 +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
180 lines
6.4 KiB
Bash
Executable File
180 lines
6.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# CA certificate installation.
|
|
#
|
|
# Sourced by raspberry_pi_nextcloud.sh; split out to keep it 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.
|
|
|
|
# =============================================================================
|
|
# Install CA Certificate on Client
|
|
# =============================================================================
|
|
|
|
phase_install_ca() {
|
|
log_info "=== Installing Nextcloud CA Certificate ==="
|
|
|
|
if [[ -z $PI_PASSWORD ]]; then
|
|
die "PI_PASSWORD not set. Run this after running install-remote or flash."
|
|
fi
|
|
|
|
local pi_ip
|
|
pi_ip=$(discover_raspberry_pi)
|
|
|
|
if [[ -z $pi_ip ]]; then
|
|
die "Failed to discover Raspberry Pi"
|
|
fi
|
|
|
|
log_info "Downloading CA certificate from Pi..."
|
|
|
|
local ca_file="/tmp/nextcloud-ca.crt"
|
|
|
|
# Use SSH with sudo to cat the file (since it's in a protected directory)
|
|
sshpass -p "$PI_PASSWORD" ssh -o StrictHostKeyChecking=no \
|
|
"${PI_USER}@${pi_ip}" "echo '$PI_PASSWORD' | sudo -S cat /etc/ssl/nextcloud/ca.crt" >"$ca_file" 2>/dev/null
|
|
|
|
if [[ ! -f $ca_file ]] || [[ ! -s $ca_file ]]; then
|
|
die "Failed to download CA certificate"
|
|
fi
|
|
|
|
log_success "CA certificate downloaded to: $ca_file"
|
|
|
|
# Detect OS and install appropriately
|
|
if [[ -f /etc/arch-release ]]; then
|
|
log_info "Detected Arch Linux - installing CA..."
|
|
sudo cp "$ca_file" /etc/ca-certificates/trust-source/anchors/nextcloud-ca.crt
|
|
sudo trust extract-compat
|
|
log_success "CA installed in system trust store"
|
|
|
|
elif [[ -f /etc/debian_version ]]; then
|
|
log_info "Detected Debian/Ubuntu - installing CA..."
|
|
sudo cp "$ca_file" /usr/local/share/ca-certificates/nextcloud-ca.crt
|
|
sudo update-ca-certificates
|
|
log_success "CA installed in system trust store"
|
|
|
|
elif [[ -f /etc/redhat-release ]]; then
|
|
log_info "Detected RHEL/Fedora - installing CA..."
|
|
sudo cp "$ca_file" /etc/pki/ca-trust/source/anchors/nextcloud-ca.crt
|
|
sudo update-ca-trust
|
|
log_success "CA installed in system trust store"
|
|
|
|
elif [[ "$(uname)" == "Darwin" ]]; then
|
|
log_info "Detected macOS - installing CA..."
|
|
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "$ca_file"
|
|
log_success "CA installed in system keychain"
|
|
|
|
else
|
|
log_warning "Unknown OS - please install CA manually from: $ca_file"
|
|
fi
|
|
|
|
# Install in browser certificate stores
|
|
log_info "Installing CA in browser certificate stores..."
|
|
|
|
# Chrome/Chromium (uses NSS)
|
|
if [[ -d ~/.pki/nssdb ]] || command -v certutil &>/dev/null; then
|
|
mkdir -p ~/.pki/nssdb
|
|
if ! certutil -d sql:~/.pki/nssdb -L 2>/dev/null | grep -q "Nextcloud"; then
|
|
# Initialize NSS db if needed
|
|
certutil -d sql:~/.pki/nssdb -N --empty-password 2>/dev/null || true
|
|
if certutil -d sql:~/.pki/nssdb -A -n "Nextcloud Home CA" -t "CT,C,C" -i "$ca_file" 2>/dev/null; then
|
|
log_success "CA installed in Chrome/Chromium"
|
|
else
|
|
log_warning "Could not install in Chrome/Chromium NSS db"
|
|
fi
|
|
else
|
|
log_info "CA already installed in Chrome/Chromium"
|
|
fi
|
|
fi
|
|
|
|
# Firefox (has its own profile NSS databases)
|
|
if [[ -d ~/.mozilla/firefox ]]; then
|
|
local installed=0
|
|
for profile_dir in ~/.mozilla/firefox/*.default* ~/.mozilla/firefox/*.esr*; do
|
|
if [[ -d $profile_dir ]]; then
|
|
if ! certutil -d sql:"$profile_dir" -L 2>/dev/null | grep -q "Nextcloud"; then
|
|
certutil -d sql:"$profile_dir" -A -n "Nextcloud Home CA" -t "CT,C,C" -i "$ca_file" 2>/dev/null &&
|
|
installed=1
|
|
else
|
|
installed=1
|
|
fi
|
|
fi
|
|
done
|
|
if [[ $installed -eq 1 ]]; then
|
|
log_success "CA installed in Firefox"
|
|
else
|
|
log_warning "Could not install in Firefox - you may need to import manually"
|
|
fi
|
|
fi
|
|
|
|
# Add hostname to /etc/hosts if not present
|
|
if ! grep -q "$PI_HOSTNAME" /etc/hosts 2>/dev/null; then
|
|
log_info "Adding $PI_HOSTNAME to /etc/hosts..."
|
|
echo "$pi_ip $PI_HOSTNAME ${PI_HOSTNAME}.local" | sudo tee -a /etc/hosts >/dev/null
|
|
log_success "Added $PI_HOSTNAME to /etc/hosts"
|
|
else
|
|
log_info "$PI_HOSTNAME already in /etc/hosts"
|
|
fi
|
|
|
|
# Verify
|
|
log_info "Verifying HTTPS connection..."
|
|
if curl -s --max-time 5 "https://$PI_HOSTNAME/status.php" 2>/dev/null | grep -q "installed"; then
|
|
log_success "HTTPS connection verified - no certificate warnings!"
|
|
else
|
|
log_warning "Could not verify HTTPS - you may need to restart your browser"
|
|
fi
|
|
|
|
log_success "========================================"
|
|
log_success "CA Certificate installed!"
|
|
log_success "========================================"
|
|
echo
|
|
log_info "Access Nextcloud at: https://$PI_HOSTNAME"
|
|
log_info "Your browser should now trust the certificate without warnings."
|
|
echo
|
|
log_info "For other devices (phones, tablets, other computers):"
|
|
log_info " Download: https://$PI_HOSTNAME/ca/nextcloud-ca.crt"
|
|
log_info " Then install the certificate in your device's trust store."
|
|
}
|
|
|
|
# =============================================================================
|
|
# Main
|
|
# =============================================================================
|
|
|
|
show_help() {
|
|
cat <<'EOF'
|
|
Nextcloud Installation Script for Raspberry Pi
|
|
|
|
Usage: ./raspberry_pi_nextcloud.sh <command>
|
|
|
|
Commands:
|
|
install-remote Install Nextcloud via SSH from your laptop (recommended)
|
|
setup-ssl-remote Setup Let's Encrypt SSL with DuckDNS (auto-trusted on all devices)
|
|
install-ca Install self-signed CA on this machine (alternative to setup-ssl)
|
|
configure Configure Pi system (run on Pi)
|
|
install-local Install Nextcloud (run on Pi)
|
|
fix Fix common Nextcloud issues (run on Pi)
|
|
setup-ssl Setup Let's Encrypt SSL (run on Pi)
|
|
help Show this help message
|
|
|
|
The script will:
|
|
1. Configure the Raspberry Pi system (SSH hardening, firewall, etc.)
|
|
2. Install Apache, PHP, MariaDB, Redis
|
|
3. Download and install Nextcloud
|
|
4. Configure caching, background jobs, and security
|
|
|
|
For HTTPS trusted on ALL devices automatically:
|
|
./raspberry_pi_nextcloud.sh install-remote
|
|
./raspberry_pi_nextcloud.sh setup-ssl-remote
|
|
|
|
This uses DuckDNS (free) + Let's Encrypt for real trusted certificates.
|
|
Go to https://www.duckdns.org/ to get your free domain first.
|
|
|
|
For self-signed certificates (requires manual CA install on each device):
|
|
./raspberry_pi_nextcloud.sh install-remote
|
|
./raspberry_pi_nextcloud.sh install-ca
|
|
|
|
For local installation (on Pi):
|
|
sudo ./raspberry_pi_nextcloud.sh configure
|
|
sudo ./raspberry_pi_nextcloud.sh install-local
|
|
sudo ./raspberry_pi_nextcloud.sh fix
|
|
sudo ./raspberry_pi_nextcloud.sh setup-ssl
|
|
EOF
|
|
}
|