dual-gpu hardening & wireless robustness

- Protected apt repository writes across modules/repos.sh by adding `|| return 1` to `_write_deb822()` and `_write_classic()`, ensuring script continuation on failure instead of aborting under set -e.
- Added idempotent backup restoration in restore_previous_repos() with `sudo cp ... || true` and `sudo rm ... || true` to prevent fatal errors during repository recovery operations.
- Implemented rollback mechanism in migrate_to_branch() by wrapping _write_branch_sources() in a conditional check, restoring backup on failure and returning error code 1.
- Hardened firmware installation flow in modules/firmware.sh with `|| true` guards on all apt commands (broadcom-sta-dkms, network firmware packages, backports/stable paths), preventing set -e aborts during package management.
- Secured modprobe operations by adding `|| true` to wl module loading and blacklist file writes, ensuring wireless driver installation proceeds even if kernel module operations fail.
- Added GPU tools installation protection in _helpers.sh with `|| true` guard on vainfo command execution after nvtop installation completes successfully.
- Fixed NVIDIA Wayland configuration in modules/gpu/nvidia.sh by adding `|| return 1` to nvidia-wayland.conf tee operation, preventing silent failures when writing modprobe configuration files.
- Implemented network warning notification before Broadcom wireless module removal to alert users of potential SSH disconnection during WiFi driver transitions.
- Added broadcom blacklist file protection with `|| true` guard on modprobe.d/blacklist-broadcom.conf writes to prevent script termination on filesystem errors.
- Standardized error handling patterns across all firmware and GPU modules, replacing direct command execution with conditional wrappers that maintain script continuity under failure conditions.
This commit is contained in:
stornic56
2026-09-12 15:15:01 -05:00
committed by GitHub
parent 8c922ee424
commit 1fc395c188
5 changed files with 42 additions and 34 deletions
+9 -8
View File
@@ -207,7 +207,7 @@ _install_detected_firmware() {
done done
if [ ${#to_install[@]} -gt 0 ]; then if [ ${#to_install[@]} -gt 0 ]; then
_run_cmd "Firmware" "sudo DEBIAN_FRONTEND=noninteractive apt install -y ${to_install[*]}" \ _run_cmd "Firmware" "sudo DEBIAN_FRONTEND=noninteractive apt install -y ${to_install[*]}" \
"Installing network firmware packages..." "Installing network firmware packages..." || true
fi fi
} }
@@ -247,7 +247,7 @@ _handle_wireless() {
# --- Persist blacklist of conflicting modules --- # --- Persist blacklist of conflicting modules ---
local blacklist_conf="/etc/modprobe.d/blacklist-broadcom.conf" local blacklist_conf="/etc/modprobe.d/blacklist-broadcom.conf"
local blacklist_content="blacklist b43\nblacklist b43legacy\nblacklist brcmsmac\nblacklist bcma\nblacklist ssb" local blacklist_content="blacklist b43\nblacklist b43legacy\nblacklist brcmsmac\nblacklist bcma\nblacklist ssb"
echo -e "$blacklist_content" | sudo tee "$blacklist_conf" >/dev/null echo -e "$blacklist_content" | sudo tee "$blacklist_conf" >/dev/null || true
# --- Update initramfs and load module --- # --- Update initramfs and load module ---
_run_cmd "Initramfs" "sudo update-initramfs -u" || true _run_cmd "Initramfs" "sudo update-initramfs -u" || true
@@ -266,7 +266,7 @@ _handle_wireless() {
if $has_broadcom_bt; then if $has_broadcom_bt; then
echo -e "${YELLOW}[+] Broadcom WiFi+BT combo card detected.${NC}" echo -e "${YELLOW}[+] Broadcom WiFi+BT combo card detected.${NC}"
sudo mkdir -p /etc/modprobe.d sudo mkdir -p /etc/modprobe.d
printf 'softdep wl post: btusb\n' | sudo tee /etc/modprobe.d/broadcom-combo.conf >/dev/null printf 'softdep wl post: btusb\n' | sudo tee /etc/modprobe.d/broadcom-combo.conf >/dev/null || true
echo -e "${YELLOW} A reboot may be required for Bluetooth support.${NC}" echo -e "${YELLOW} A reboot may be required for Bluetooth support.${NC}"
fi fi
@@ -291,8 +291,9 @@ _handle_wireless() {
fi fi
fi fi
_msg "Network Warning" "The script is about to unload current WiFi kernel modules to load the Broadcom driver.\n\nIf you are connected via SSH over WiFi, YOUR CONNECTION WILL DROP. Please reconnect after a few seconds."
sudo modprobe -r b43 b43legacy b44 bcma brcmsmac brcmfmac ssb wl 2>/dev/null || true sudo modprobe -r b43 b43legacy b44 bcma brcmsmac brcmfmac ssb wl 2>/dev/null || true
sudo modprobe wl 2>/dev/null sudo modprobe wl 2>/dev/null || true
# --- Verificación de carga --- # --- Verificación de carga ---
if lsmod | grep -q '^wl '; then if lsmod | grep -q '^wl '; then
@@ -440,7 +441,7 @@ install_firmware() {
local current_ver local current_ver
current_ver=$(dpkg -l "$fw_pkg" 2>/dev/null | awk '/^ii/{print $3}') current_ver=$(dpkg -l "$fw_pkg" 2>/dev/null | awk '/^ii/{print $3}')
if _confirm "Firmware" "firmware-linux-nonfree ${current_ver} already installed.\n\nUpgrade to backports version ${fw_bpo}?\n\nBackports often includes newer hardware support."; then if _confirm "Firmware" "firmware-linux-nonfree ${current_ver} already installed.\n\nUpgrade to backports version ${fw_bpo}?\n\nBackports often includes newer hardware support."; then
_run_cmd "Firmware" "sudo apt install -y -t ${DEBIAN_CODENAME}-backports $fw_pkg" "Upgrading firmware..." _run_cmd "Firmware" "sudo apt install -y -t ${DEBIAN_CODENAME}-backports $fw_pkg" "Upgrading firmware..." || true
fi fi
else else
echo "$fw_pkg already installed." echo "$fw_pkg already installed."
@@ -457,15 +458,15 @@ install_firmware() {
msg+=" 2025/2026: recent GPUs, processors, WiFi.\n\n" msg+=" 2025/2026: recent GPUs, processors, WiFi.\n\n"
msg+="Choose version:" msg+="Choose version:"
if _confirm_custom "Firmware" "$msg" "Backports" "Stable"; then if _confirm_custom "Firmware" "$msg" "Backports" "Stable"; then
_run_cmd "Firmware" "sudo apt install -y -t ${DEBIAN_CODENAME}-backports $fw_pkg" "Installing firmware from backports..." _run_cmd "Firmware" "sudo apt install -y -t ${DEBIAN_CODENAME}-backports $fw_pkg" "Installing firmware from backports..." || true
else else
_run_cmd "Firmware" "sudo apt install -y $fw_pkg" "Installing firmware from stable..." _run_cmd "Firmware" "sudo apt install -y $fw_pkg" "Installing firmware from stable..." || true
fi fi
else else
msg+=" Version: ${fw_stable}\n\n" msg+=" Version: ${fw_stable}\n\n"
msg+="Install it?" msg+="Install it?"
if _confirm "Firmware" "$msg"; then if _confirm "Firmware" "$msg"; then
_run_cmd "Firmware" "sudo apt install -y $fw_pkg" "Installing firmware..." _run_cmd "Firmware" "sudo apt install -y $fw_pkg" "Installing firmware..." || true
fi fi
fi fi
echo -e "${GREEN}Base firmware installed.${NC}" echo -e "${GREEN}Base firmware installed.${NC}"
+1 -1
View File
@@ -172,7 +172,7 @@ offer_generic_tools() {
local tool_pkgs local tool_pkgs
tool_pkgs=$(pkg_versions nvtop vainfo) tool_pkgs=$(pkg_versions nvtop vainfo)
if _confirm "GPU Tools" "Install monitoring and info tools?\n\n${tool_pkgs}"; then if _confirm "GPU Tools" "Install monitoring and info tools?\n\n${tool_pkgs}"; then
_run_cmd "GPU Tools" "sudo apt install -y nvtop vainfo" "Installing GPU tools..." _run_cmd "GPU Tools" "sudo apt install -y nvtop vainfo" "Installing GPU tools..." || true
vainfo vainfo
_pause "vainfo output shown above." _pause "vainfo output shown above."
else else
+2 -2
View File
@@ -135,7 +135,7 @@ _verify_nvidia_dkms_build() {
# Returns: 0 if a version was chosen, 1 if the user cancelled # Returns: 0 if a version was chosen, 1 if the user cancelled
# ------------------------------------------------------------------- # -------------------------------------------------------------------
_is_cuda_repo_ready() { _is_cuda_repo_ready() {
[ -f /etc/apt/sources.list.d/extrepo_nvidia-cuda.sources ] || \ [ -f /etc/apt/sources.list.d/extrepo_nvidia-cuda.sources ] ||
grep -qr 'developer.download.nvidia.com' /etc/apt/sources.list.d/ 2>/dev/null grep -qr 'developer.download.nvidia.com' /etc/apt/sources.list.d/ 2>/dev/null
} }
@@ -206,7 +206,7 @@ _configure_nvidia_wayland() {
[ "$arch" != "kepler" ] && content+="options nvidia-drm fbdev=1"$'\n' [ "$arch" != "kepler" ] && content+="options nvidia-drm fbdev=1"$'\n'
fi fi
printf "%b" "$content" | sudo tee "$conf" >/dev/null printf "%b" "$content" | sudo tee "$conf" >/dev/null || return 1
echo -e "${color}${msg}${NC}" echo -e "${color}${msg}${NC}"
} }
+4 -4
View File
@@ -27,10 +27,10 @@ restore_previous_repos() {
local rel="${f#/etc/apt/}" local rel="${f#/etc/apt/}"
local backup_file="$REPO_BACKUP_DIR/$rel" local backup_file="$REPO_BACKUP_DIR/$rel"
if [ -f "$backup_file" ]; then if [ -f "$backup_file" ]; then
sudo cp "$backup_file" "$f" sudo cp "$backup_file" "$f" || true
found=true found=true
elif [ -f "$f" ]; then elif [ -f "$f" ]; then
sudo rm -f "$f" sudo rm -f "$f" || true
found=true found=true
fi fi
done done
@@ -103,7 +103,7 @@ _write_deb822() {
if content_differs "$main_file" "$main_content"; then if content_differs "$main_file" "$main_content"; then
if _confirm "Deb822 Sources" "Write main deb822 configuration to ${main_file}?"; then if _confirm "Deb822 Sources" "Write main deb822 configuration to ${main_file}?"; then
sudo mkdir -p /etc/apt/sources.list.d sudo mkdir -p /etc/apt/sources.list.d
echo -e "$main_content" | sudo tee "$main_file" >/dev/null echo -e "$main_content" | sudo tee "$main_file" >/dev/null || return 1
echo "Wrote ${main_file}" echo "Wrote ${main_file}"
else else
echo "Main repository configuration skipped." echo "Main repository configuration skipped."
@@ -199,7 +199,7 @@ _write_classic() {
if content_differs "$main_file" "$main_content"; then if content_differs "$main_file" "$main_content"; then
if _confirm "Classic Sources" "Write main classic configuration to ${main_file}?"; then if _confirm "Classic Sources" "Write main classic configuration to ${main_file}?"; then
echo -e "$main_content" | sudo tee "$main_file" >/dev/null echo -e "$main_content" | sudo tee "$main_file" >/dev/null || return 1
echo "Wrote ${main_file}" echo "Wrote ${main_file}"
else else
echo "Main repository configuration skipped." echo "Main repository configuration skipped."
+9 -2
View File
@@ -125,7 +125,10 @@ so you can restore if things go wrong." 16 70
branch=$(_inputbox "Target Branch" \ branch=$(_inputbox "Target Branch" \
"Type exactly TESTING or SID (case-sensitive):" 10 60 "") "Type exactly TESTING or SID (case-sensitive):" 10 60 "")
[ -z "$branch" ] && { echo "Migration cancelled."; return; } [ -z "$branch" ] && {
echo "Migration cancelled."
return
}
if [ "$branch" != "TESTING" ] && [ "$branch" != "SID" ]; then if [ "$branch" != "TESTING" ] && [ "$branch" != "SID" ]; then
_msg "Invalid Branch" "You typed: $branch\n\nExpected: TESTING or SID (exact, case-sensitive).\nAborting." 10 60 _msg "Invalid Branch" "You typed: $branch\n\nExpected: TESTING or SID (exact, case-sensitive).\nAborting." 10 60
@@ -155,7 +158,11 @@ so you can restore if things go wrong." 16 70
[ -f /etc/apt/sources.list ] && sudo rm -f /etc/apt/sources.list [ -f /etc/apt/sources.list ] && sudo rm -f /etc/apt/sources.list
# 4d. Write new sources # 4d. Write new sources
_write_branch_sources "$target" if ! _write_branch_sources "$target"; then
echo -e "${RED}[-]${NC} Failed to write new sources. Restoring backup..."
_restore_backup || true
return 1
fi
# 4e. SID guardrails: install bug alerts before upgrade # 4e. SID guardrails: install bug alerts before upgrade
if [ "$target" = "sid" ]; then if [ "$target" = "sid" ]; then