#!/bin/bash
# Step 09: Re-apply Plymouth splash theme after driver install

step_09_reapply_splash() {
  local cfg="/boot/firmware/config.txt"
  [[ -f "$cfg" ]] || cfg="/boot/config.txt"
  if [[ -f "$cfg" ]] && grep -q '^disable_splash=1' "$cfg"; then
    sed -i 's/^disable_splash=1$/disable_splash=0/' "$cfg"
    log "Set disable_splash=0"
  fi

  if [[ -f /etc/plymouth/plymouthd.conf ]]; then
    sed -i '/^Theme=/d; /^\[Daemon\]$/d' /etc/plymouth/plymouthd.conf
    grep -q '^\[Daemon\]' /etc/plymouth/plymouthd.conf || echo '[Daemon]' >> /etc/plymouth/plymouthd.conf
    echo 'Theme=custom' >> /etc/plymouth/plymouthd.conf
  fi

  log "Running update-initramfs ..."
  update-initramfs -u -k all 2>/dev/null || true
}
