Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
Shell
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242#!/bin/bash# patch-usb.sh — Patch a Fedora live USB into a FedAC auto-installer## After flashing a standard Fedora Workstation ISO to USB, run this to:# 1. Mount the EFI partition# 2. Copy the FedAC kickstart onto it# 3. Replace GRUB config with FedAC-branded auto-boot## Usage:# sudo bash fedac/scripts/patch-usb.sh /dev/sdX## The USB must already have a Fedora live ISO written to it (via dd or flash-usb.sh).
set -euo pipefail
RED='\033[0;31m'GREEN='\033[0;32m'YELLOW='\033[1;33m'CYAN='\033[0;36m'PURPLE='\033[0;35m'NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"FEDAC_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
usage() { echo "Usage: sudo $0 <device>" echo "" echo "Example: sudo $0 /dev/sdb" echo "" echo "The device must be a Fedora live USB (already flashed with dd)." exit 1}
DEVICE="${1:-}"[ -n "$DEVICE" ] || usage[ -b "$DEVICE" ] || { echo -e "${RED}Not a block device: $DEVICE${NC}"; exit 1; }
# Must be rootif [ "$(id -u)" -ne 0 ]; then echo -e "${RED}Error: Must run as root (sudo)${NC}" exit 1fi
# Safetycase "$DEVICE" in /dev/sda|/dev/nvme0n1|/dev/vda) echo -e "${RED}REFUSED: $DEVICE looks like a system disk${NC}" exit 1 ;;esac
# Find the EFI partition (usually partition 2 on Fedora live USB, ~30M FAT)EFI_PART=""for part in "${DEVICE}2" "${DEVICE}p2"; do if [ -b "$part" ]; then EFI_PART="$part" break fidone
if [ -z "$EFI_PART" ]; then echo -e "${RED}Could not find EFI partition (tried ${DEVICE}2, ${DEVICE}p2)${NC}" echo "Partitions on $DEVICE:" lsblk "$DEVICE" exit 1fi
echo -e "${CYAN}=== FedAC USB Patcher ===${NC}"echo -e "Device: ${YELLOW}$DEVICE${NC}"echo -e "EFI part: ${YELLOW}$EFI_PART${NC}"echo ""
# Mount EFI partitionMOUNT_DIR=$(mktemp -d /tmp/fedac-efi-XXXX)echo -e "${CYAN}Mounting $EFI_PART...${NC}"mount "$EFI_PART" "$MOUNT_DIR"
# Verify this looks like a Fedora EFI partitionif [ ! -d "$MOUNT_DIR/EFI/BOOT" ]; then echo -e "${RED}No EFI/BOOT directory found — doesn't look like a Fedora live USB${NC}" umount "$MOUNT_DIR" rmdir "$MOUNT_DIR" exit 1fi
echo -e "${GREEN}EFI partition mounted at $MOUNT_DIR${NC}"echo ""
# ── 1. Copy kickstart ──echo -e "${CYAN}[1/3] Copying kickstart...${NC}"KS_SRC="$FEDAC_DIR/kickstart/fedac-thinkpad.ks"if [ ! -f "$KS_SRC" ]; then echo -e "${RED}Kickstart not found: $KS_SRC${NC}" umount "$MOUNT_DIR" rmdir "$MOUNT_DIR" exit 1ficp "$KS_SRC" "$MOUNT_DIR/fedac.ks"echo -e " Copied to ${GREEN}$MOUNT_DIR/fedac.ks${NC}"
# ── 2. Install GRUB theme ──echo -e "${CYAN}[2/4] Installing GRUB theme...${NC}"
THEME_SRC="$FEDAC_DIR/grub-theme"THEME_DST="$MOUNT_DIR/EFI/BOOT/fedac-theme"
mkdir -p "$THEME_DST"
# Copy theme.txt (always from repo)if [ -f "$THEME_SRC/theme.txt" ]; then cp "$THEME_SRC/theme.txt" "$THEME_DST/" echo -e " theme.txt"fi
# Copy generated assets if they exist, otherwise generate on the flyNEED_GENERATE=falsefor asset in background.png DejaVuSansBold36.pf2 DejaVuSans18.pf2 DejaVuSans10.pf2 select_c.png menu_c.png; do if [ -f "$THEME_SRC/$asset" ]; then cp "$THEME_SRC/$asset" "$THEME_DST/" echo -e " $asset" else NEED_GENERATE=true fidone
if [ "$NEED_GENERATE" = true ]; then echo -e " ${YELLOW}Some theme assets missing — generating...${NC}" if [ -x "$THEME_SRC/prepare-theme.sh" ]; then bash "$THEME_SRC/prepare-theme.sh" # Re-copy generated files for asset in background.png DejaVuSansBold36.pf2 DejaVuSans18.pf2 DejaVuSans10.pf2 select_c.png menu_c.png; do if [ -f "$THEME_SRC/$asset" ]; then cp "$THEME_SRC/$asset" "$THEME_DST/" fi done else echo -e " ${YELLOW}Warning: prepare-theme.sh not found, theme may be incomplete${NC}" fifi
echo -e " ${GREEN}Theme installed to EFI${NC}"
# ── 3. Patch GRUB config ──echo -e "${CYAN}[3/4] Patching GRUB config...${NC}"
GRUB_CFG="$MOUNT_DIR/EFI/BOOT/grub.cfg"if [ ! -f "$GRUB_CFG" ]; then echo -e "${RED}No EFI/BOOT/grub.cfg found${NC}" umount "$MOUNT_DIR" rmdir "$MOUNT_DIR" exit 1fi
# Back up originalcp "$GRUB_CFG" "${GRUB_CFG}.orig"echo -e " Backed up original grub.cfg"
CDLABEL="Fedora-WS-Live-43"
echo -e "${CYAN}[4/4] Writing FedAC GRUB config...${NC}"
cat > "$GRUB_CFG" << 'GRUBEOF'# FedAC — Fedora Boot-to-Aesthetic-Computer# Auto-patched by fedac/scripts/patch-usb.sh
set default=0set timeout=5
# ── Graphics modules ──if [ "$grub_platform" == "efi" ]; then insmod efi_gop insmod efi_ugafiinsmod all_videoinsmod gzioinsmod part_gptinsmod ext2insmod pnginsmod font
# ── Save EFI partition root before search changes it ──set efi_root=$root
# ── Load fonts from EFI partition (before $root changes) ──loadfont ($efi_root)/EFI/BOOT/fedac-theme/DejaVuSansBold36.pf2loadfont ($efi_root)/EFI/BOOT/fedac-theme/DejaVuSans18.pf2loadfont ($efi_root)/EFI/BOOT/fedac-theme/DejaVuSans10.pf2
# ── Switch to graphical terminal ──set gfxmode=autoset gfxpayload=keepterminal_input consoleterminal_output gfxterm
# ── Load theme from EFI partition ──if [ -f ($efi_root)/EFI/BOOT/fedac-theme/theme.txt ]; then set theme=($efi_root)/EFI/BOOT/fedac-theme/theme.txtelse set color_normal=magenta/black set color_highlight=white/magentafi
# ── Find Fedora live partition (changes $root) ──search --file --set=root /boot/0x4da30161
menuentry " FedAC — Install Aesthetic Computer" --class fedora { linux ($root)/boot/x86_64/loader/linux quiet rhgb root=live:CDLABEL=FEDAC_CDLABEL rd.live.image inst.ks=https://raw.githubusercontent.com/whistlegraph/aesthetic-computer/main/fedac/kickstart/fedac-thinkpad.ks initrd ($root)/boot/x86_64/loader/initrd}
menuentry " FedAC — Live Desktop (no install)" --class fedora { linux ($root)/boot/x86_64/loader/linux quiet rhgb root=live:CDLABEL=FEDAC_CDLABEL rd.live.image initrd ($root)/boot/x86_64/loader/initrd}
menuentry " Boot from local drive" { exit}GRUBEOF
# Substitute the CDLABEL placeholdersed -i "s/FEDAC_CDLABEL/${CDLABEL}/g" "$GRUB_CFG"
echo -e " ${GREEN}GRUB config written (graphical theme)${NC}"echo ""
# ── Done ──syncumount "$MOUNT_DIR"rmdir "$MOUNT_DIR"
echo -e "${GREEN}=== USB patched ===${NC}"echo ""echo -e "Boot menu will show (with pals logo + large text):"echo -e " ${PURPLE}1. FedAC — Install Aesthetic Computer${NC} (auto-selected after 5s)"echo -e " 2. FedAC — Live Desktop (no install)"echo -e " 3. Boot from local drive"echo ""echo -e "The kickstart at ${GREEN}/fedac.ks${NC} on the EFI partition will automate the install."echo -e "Pull the USB and boot the target machine."