|
| 1 | +#!/bin/bash |
| 2 | +[[ -d pxe ]] || mkdir -p pxe |
| 3 | +if [[ ! -f pxe/online_boot.ipxe ]]; then |
| 4 | +minimal_latest_json=$(curl -s "https://api.github.com/repos/NiKiZe/Gentoo-iPXE/releases/latest") |
| 5 | +tag_name=$(grep '"tag_name":' <<< "$minimal_latest_json" | head -n 1 | sed -E 's/.*"tag_name":\s*"([^"]+)".*/\1/') |
| 6 | +if [[ -z "$tag_name" ]]; then |
| 7 | + echo "Error: tag not found" |
| 8 | + exit 1 |
| 9 | +fi |
| 10 | +ipxe_url=$(grep "${tag_name}.ipxe" <<< "$minimal_latest_json" | grep '"browser_download_url":' | head -n 1 | sed -E 's/.*"browser_download_url":\s*"([^"]+)".*/\1/') |
| 11 | + |
| 12 | +if [[ -z "$ipxe_url" ]]; then |
| 13 | + echo "Error: ${tag_name}.ipxe asset not found in release" |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +base_url="${ipxe_url%/*}/" |
| 18 | +filtered_ipxe=$(curl -sL "$ipxe_url" | grep -E '^(kernel|initrd)' | sed "s| ${tag_name}-| ${base_url}${tag_name}-|g") |
| 19 | +cat << EOF > pxe/online_boot.ipxe |
| 20 | +#!ipxe |
| 21 | +set keymap keymap=us net.ifnames=0 autoinstall |
| 22 | +${filtered_ipxe} |
| 23 | +initrd ../updates/root/.bashrc /updates/root/.bashrc mkdir=2 mode=644 |
| 24 | +initrd ../updates/etc/motd /updates/etc/motd mkdir=1 mode=644 |
| 25 | +imgstat |
| 26 | +boot |
| 27 | +EOF |
| 28 | + |
| 29 | +fi |
| 30 | + |
| 31 | +# replace if unset oor empty |
| 32 | +: "${LOGPFX:=HAI}" |
| 33 | +# replace if unset |
| 34 | +: "${RUNOPTS="useefi usenvme"}" |
| 35 | + |
| 36 | +rm kvm_lxgentootest.qcow2 || true |
| 37 | + |
| 38 | +cat pxe/online_boot.ipxe |
| 39 | +LOG_FILE=run_full.log |
| 40 | +META_FILE=run_metadata.txt |
| 41 | +ENV_FILE=run_vars.sh |
| 42 | +> $META_FILE |
| 43 | +> $ENV_FILE |
| 44 | +date > $LOG_FILE |
| 45 | + |
| 46 | +FIFO_PIPE=$(mktemp -u) |
| 47 | +mkfifo "$FIFO_PIPE" |
| 48 | +bash test_w_qemu.sh -bootfile pxe/online_boot.ipxe auto ${RUNOPTS} > "$FIFO_PIPE" 2>&1 & |
| 49 | +QEMU_RUN_PID=$! |
| 50 | + |
| 51 | +{ |
| 52 | + buffer="" |
| 53 | + NEED_PREFIX=1 |
| 54 | + MSGQUEUE=() |
| 55 | + while IFS= read -r -d '' -n 1 char; do |
| 56 | + if [ "$NEED_PREFIX" -eq 1 ]; then |
| 57 | + [ ${#MSGQUEUE[@]} -gt 0 ] && printf "%s\n" "${MSGQUEUE[@]}" >&2 && MSGQUEUE=() |
| 58 | + printf "[%s %02d:%02d] " "${LOGPFX}" $((SECONDS / 60)) $((SECONDS % 60)) |
| 59 | + NEED_PREFIX=0 |
| 60 | + fi |
| 61 | + printf "%s" "$char" |
| 62 | + if [[ "$char" == $'\n' ]]; then |
| 63 | + NEED_PREFIX=1 |
| 64 | + fi |
| 65 | + if [[ "$char" != $'\r' && "$char" != $'\n' ]]; then |
| 66 | + buffer+="$char" |
| 67 | + continue |
| 68 | + fi |
| 69 | + line="$buffer" |
| 70 | + buffer="" |
| 71 | + |
| 72 | + line=$(sed 's/\x1b\[[0-9;]*[mKHP]//g' <<< "$line") |
| 73 | + case "$line" in |
| 74 | + *" -- Open Source Network Boot Firmware -- https://ipxe.org"*) |
| 75 | + IPXE=$(grep -o "iPXE [0-9.+ a-fg()]*[^ -]" <<< "$line") |
| 76 | + declare -p IPXE >> $ENV_FILE |
| 77 | + MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x8C\x90 '"$(date) iPXE Version: ${IPXE}")") |
| 78 | + ;; |
| 79 | + *"Welcome to Gentoo-HAI Dracut"*) |
| 80 | + MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x8E\xAF '"$(date) Initial boot OK")") |
| 81 | + ;; |
| 82 | + "+ "[a-z0-9]*"_emerge"*|"+ make_"*) |
| 83 | + CURRENT_TIMER=$(grep -o -E '[a-z0-9_]+' <<< "$line") |
| 84 | + ;; |
| 85 | + real[[:space:]]*) |
| 86 | + ELAPSED=$(grep -o '[0-9][0-9hms.]*' <<< "$line") |
| 87 | + MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xE2\x8F\xB1\xEF\xB8\x8F '"$(date) ${CURRENT_TIMER} Time: ${ELAPSED}")") |
| 88 | + CURRENT_TIMER="" |
| 89 | + ;; |
| 90 | + *"Snapshot"*"gentoo-"*".sqfs "*) |
| 91 | + SNAPSHOT=$(grep -o 'gentoo-[^[:space:]]*sqfs' <<< "$line") |
| 92 | + declare -p SNAPSHOT >> $ENV_FILE |
| 93 | + MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x93\xB8 '"$(date) Snapshot Used: ${SNAPSHOT}")") |
| 94 | + ;; |
| 95 | + *"download latest stage file stage3-"*".tar.xz"*) |
| 96 | + STAGE3=$(grep -o 'stage3-[^[:space:]]*xz' <<< "$line") |
| 97 | + declare -p STAGE3 >> $ENV_FILE |
| 98 | + MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x93\xA6 '"$(date) Stage3 Used: ${STAGE3}")") |
| 99 | + ;; |
| 100 | + *"] "*"sys-kernel/gentoo-sources-"*) |
| 101 | + KERNEL=$(grep -o 'gentoo-sources-[0-9.]*' <<< "$line") |
| 102 | + declare -p KERNEL >> $ENV_FILE |
| 103 | + MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x90\xA7 '"$(date) Kernel: ${KERNEL}")") |
| 104 | + ;; |
| 105 | + "This is gtestinst (Linux"*) |
| 106 | + MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x8E\xAF '"$(date) All good after reboot")") |
| 107 | + pkill -P $QEMU_RUN_PID 2>/dev/null || true |
| 108 | + exit 0 |
| 109 | + ;; |
| 110 | + esac |
| 111 | + done |
| 112 | + exit 1 |
| 113 | +} < "$FIFO_PIPE" | tee -a $LOG_FILE & |
| 114 | +JOB_PID=$! |
| 115 | +
|
| 116 | +(sleep 45m; kill $JOB_PID 2>/dev/null) & |
| 117 | +TIMEOUT_PID=$! |
| 118 | +wait $JOB_PID |
| 119 | +job_rc=$? |
| 120 | +
|
| 121 | +echo |
| 122 | +date >> $LOG_FILE |
| 123 | +kill $TIMEOUT_PID 2>/dev/null || true |
| 124 | +pkill -P $QEMU_RUN_PID 2>/dev/null || true |
| 125 | +pkill -P $JOB_PID 2>/dev/null || true |
| 126 | +rm -f "$FIFO_PIPE" 2>/dev/null || true |
| 127 | +[[ $job_rc -ne 0 ]] && echo "❌ FAIL timeout" || true |
| 128 | +[[ -s "$META_FILE" ]] && cat "$META_FILE" || true |
| 129 | +exit $job_rc |
0 commit comments