|
| 1 | +#!/bin/bash |
| 2 | +set -euox pipefail |
| 3 | + |
| 4 | +# Import util functions |
| 5 | +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)/utils.sh" |
| 6 | + |
| 7 | +# Configuration |
| 8 | +ssh_options=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5) |
| 9 | +ssh_key="id_rsa" |
| 10 | +sudo ssh-keygen -f id_rsa -N "" -q -t rsa-sha2-256 -b 2048 <<< y |
| 11 | +ssh_key_pub=$(cat "${ssh_key}.pub") |
| 12 | +manufacturer_ip="192.168.100.1" |
| 13 | +rendezvous_ip="192.168.100.1" |
| 14 | +owner_ip="192.168.100.1" |
| 15 | + |
| 16 | +source /etc/os-release |
| 17 | +log_info "Detected OS: ${ID} ${VERSION_ID}" |
| 18 | + |
| 19 | +case "${ID}-${VERSION_ID}" in |
| 20 | + "fedora-43") |
| 21 | + os_variant="fedora-unknown" |
| 22 | + base_image_url="quay.io/fedora/fedora-bootc:43" |
| 23 | + bib_url="quay.io/centos-bootc/bootc-image-builder:latest" |
| 24 | + boot_args="uefi" |
| 25 | + ;; |
| 26 | + "fedora-44") |
| 27 | + os_variant="fedora-rawhide" |
| 28 | + base_image_url="quay.io/fedora/fedora-bootc:44" |
| 29 | + bib_url="quay.io/centos-bootc/bootc-image-builder:latest" |
| 30 | + boot_args="uefi" |
| 31 | + ;; |
| 32 | + "centos-9") |
| 33 | + os_variant="centos-stream9" |
| 34 | + base_image_url="quay.io/centos-bootc/centos-bootc:stream9" |
| 35 | + bib_url="quay.io/centos-bootc/bootc-image-builder:latest" |
| 36 | + boot_args="uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no" |
| 37 | + ;; |
| 38 | + "centos-10") |
| 39 | + os_variant="centos-stream9" |
| 40 | + base_image_url="quay.io/centos-bootc/centos-bootc:stream10" |
| 41 | + bib_url="quay.io/centos-bootc/bootc-image-builder:latest" |
| 42 | + boot_args="uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no" |
| 43 | + ;; |
| 44 | + *) |
| 45 | + log_error "Unsupported distro: ${ID}-${VERSION_ID}" |
| 46 | + exit 1 |
| 47 | + ;; |
| 48 | +esac |
| 49 | + |
| 50 | +run_test() { |
| 51 | + |
| 52 | + log_info "Setting the error trap handler" |
| 53 | + trap on_failure ERR |
| 54 | + |
| 55 | + log_info "Environment variables" |
| 56 | + show_env |
| 57 | + |
| 58 | + log_info "Creating directories" |
| 59 | + create_directories |
| 60 | + |
| 61 | + log_info "Generating service certificates" |
| 62 | + generate_service_certs |
| 63 | + |
| 64 | + log_info "Adding host entries for FDO services in host machine" |
| 65 | + echo -e "${manufacturer_ip} manufacturer\n${rendezvous_ip} rendezvous\n${owner_ip} owner" | sudo tee -a /etc/hosts > /dev/null |
| 66 | + |
| 67 | + log_info "Build and install 'go-fdo-server' binary" |
| 68 | + install_server |
| 69 | + |
| 70 | + log_info "Configuring services" |
| 71 | + configure_services |
| 72 | + |
| 73 | + log_info "Start services" |
| 74 | + start_services |
| 75 | + |
| 76 | + log_info "Wait for the services to be ready" |
| 77 | + wait_for_services_ready |
| 78 | + |
| 79 | + log_info "Setting or updating Rendezvous Info (RendezvousInfo)" |
| 80 | + set_or_update_rendezvous_info "${manufacturer_url}" "${rendezvous_service_name}" "${rendezvous_dns}" "${rendezvous_port}" |
| 81 | + |
| 82 | + log_info "Build bootc container from bootc base image" |
| 83 | + install_client $base_image_url $bib_url |
| 84 | + |
| 85 | + log_info "Run Device Initialization" |
| 86 | + run_device_initialization $os_variant $boot_args |
| 87 | + |
| 88 | + log_info "Get device initialization voucher guid" |
| 89 | + guid=$(get_voucher_guid) |
| 90 | + log_info "Device initialized with GUID: ${guid}" |
| 91 | + |
| 92 | + log_info "Sending Ownership Voucher to the Owner" |
| 93 | + send_manufacturer_ov_to_owner "${manufacturer_url}" "${guid}" "${owner_url}" |
| 94 | + |
| 95 | + log_info "Setting or updating Owner Redirect Info (RVTO2Addr)" |
| 96 | + set_or_update_owner_redirect_info "${owner_url}" "${owner_service_name}" "${owner_dns}" "${owner_port}" |
| 97 | + |
| 98 | + sleep 60 |
| 99 | + |
| 100 | + log_info "Running FIDO Device Onboard" |
| 101 | + run_fido_device_onboard || log_error "Onboarding failed!" |
| 102 | + |
| 103 | + log_info "Unsetting the error trap handler" |
| 104 | + trap - ERR |
| 105 | + test_pass |
| 106 | + |
| 107 | +} |
| 108 | + |
| 109 | +# Allow running directly |
| 110 | +[[ "${BASH_SOURCE[0]}" != "$0" ]] || { run_test; cleanup; } |
0 commit comments