|
| 1 | +#!/bin/ksh |
| 2 | +set -eu |
| 3 | +( set -o pipefail ) 2>/dev/null && set -o pipefail |
| 4 | + |
| 5 | +SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)" |
| 6 | +PROJECT_ROOT="$(CDPATH= cd -- "${SCRIPT_DIR}/../.." && pwd -P)" |
| 7 | +COMMON_LIB="${PROJECT_ROOT}/scripts/lib/common.ksh" |
| 8 | + |
| 9 | +[ -f "${COMMON_LIB}" ] || { |
| 10 | + print -- "ERROR missing shared library: ${COMMON_LIB}" >&2 |
| 11 | + exit 1 |
| 12 | +} |
| 13 | + |
| 14 | +. "${COMMON_LIB}" |
| 15 | + |
| 16 | +FAIL=0 |
| 17 | +PASS=0 |
| 18 | +BUILD_ROOT="${OPENBSD_MAILSTACK_AUTOINSTALL_BUILD_ROOT:-${PROJECT_ROOT}/maint/openbsd-autonomous-installer/build}" |
| 19 | + |
| 20 | +pass() { print -- "[$(timestamp)] PASS $*"; PASS=$((PASS + 1)); } |
| 21 | +fail() { print -- "[$(timestamp)] FAIL $*"; FAIL=$((FAIL + 1)); } |
| 22 | + |
| 23 | +check_file() { |
| 24 | + _path="$1" |
| 25 | + _label="$2" |
| 26 | + if [ -f "${_path}" ]; then |
| 27 | + pass "${_label}: ${_path#${PROJECT_ROOT}/}" |
| 28 | + else |
| 29 | + fail "${_label} missing: ${_path#${PROJECT_ROOT}/}" |
| 30 | + fi |
| 31 | +} |
| 32 | + |
| 33 | +check_var_in_example() { |
| 34 | + _var="$1" |
| 35 | + _file="$2" |
| 36 | + if grep -Eq '^'"${_var}"'=' "${_file}"; then |
| 37 | + pass "installer example defines ${_var}" |
| 38 | + else |
| 39 | + fail "installer example missing ${_var}" |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +check_no_placeholders() { |
| 44 | + _file="$1" |
| 45 | + _label="$2" |
| 46 | + if grep -Eq '__[A-Z0-9_][A-Z0-9_]*__' "${_file}"; then |
| 47 | + fail "${_label} still contains unresolved placeholders: ${_file}" |
| 48 | + else |
| 49 | + pass "${_label} free of unresolved placeholders: ${_file}" |
| 50 | + fi |
| 51 | +} |
| 52 | + |
| 53 | +check_build_outputs() { |
| 54 | + [ -d "${BUILD_ROOT}" ] || { |
| 55 | + pass "no rendered autonomous installer build root present, repo asset checks only" |
| 56 | + return 0 |
| 57 | + } |
| 58 | + _found=0 |
| 59 | + for _dir in "${BUILD_ROOT}"/*; do |
| 60 | + [ -d "${_dir}" ] || continue |
| 61 | + _found=1 |
| 62 | + check_file "${_dir}/install.conf.78.lab" "installer build output" |
| 63 | + check_file "${_dir}/install.conf.78.real" "installer build output" |
| 64 | + check_file "${_dir}/disklabel-root-swap.template" "installer build output" |
| 65 | + check_file "${_dir}/site78.tgz" "installer build output" |
| 66 | + check_file "${_dir}/ACCOUNT-READINESS.md" "installer build output" |
| 67 | + [ -f "${_dir}/install.conf.78.lab" ] && check_no_placeholders "${_dir}/install.conf.78.lab" "installer lab config" |
| 68 | + [ -f "${_dir}/install.conf.78.real" ] && check_no_placeholders "${_dir}/install.conf.78.real" "installer real config" |
| 69 | + [ -f "${_dir}/ACCOUNT-READINESS.md" ] && check_no_placeholders "${_dir}/ACCOUNT-READINESS.md" "installer readiness summary" |
| 70 | + done |
| 71 | + [ "${_found}" -eq 1 ] || pass "autonomous installer build root exists but contains no rendered profiles yet" |
| 72 | +} |
| 73 | + |
| 74 | +main() { |
| 75 | + _dir="${PROJECT_ROOT}/maint/openbsd-autonomous-installer" |
| 76 | + _example="${_dir}/installer-profile.example.env" |
| 77 | + |
| 78 | + for _file in "${_dir}/README.md" "${_dir}/installer-profile.example.env" "${_dir}/guided-profile-builder.ksh" "${_dir}/render-installer-pack.ksh" "${_dir}/install.conf.78.lab.template" "${_dir}/install.conf.78.real.template" "${_dir}/disklabel-root-swap.template" "${_dir}/serve-autoinstall.sh" "${_dir}/site78_root/install.site.template" "${_dir}/site78_root/root/phase00-firstboot.sh.template" |
| 79 | + do |
| 80 | + check_file "${_file}" "autonomous installer asset present" |
| 81 | + done |
| 82 | + |
| 83 | + for _var in PROFILE_NAME OPENBSD_VERSION OPENBSD_ARCH SYSTEM_HOSTNAME DNS_DOMAIN TIMEZONE OPERATOR_USER OPERATOR_HOME ROOT_PASSWORD_BCRYPT PARROT_PUBKEY LAN_IF_DEFAULT LAN_NET_DEFAULT HOST_IP_DEFAULT HOST_IP_CIDR_REAL HOST_GATEWAY_DEFAULT NAMESERVER_DEFAULT AUTOINSTALL_HTTP_HOST AUTOINSTALL_HTTP_PORT MAILSTACK_REPO_CLONE_URL; do |
| 84 | + check_var_in_example "${_var}" "${_example}" |
| 85 | + done |
| 86 | + |
| 87 | + if grep -Fq 'installer-profile.local.env' "${PROJECT_ROOT}/docs/install/07-openbsd-autonomous-installer.md" && grep -Eq 'local and untracked|intentionally local and untracked' "${PROJECT_ROOT}/docs/install/07-openbsd-autonomous-installer.md"; then |
| 88 | + pass "autonomous installer doc correctly describes local untracked profile" |
| 89 | + else |
| 90 | + fail "autonomous installer doc does not clearly describe local untracked profile" |
| 91 | + fi |
| 92 | + |
| 93 | + check_build_outputs |
| 94 | + |
| 95 | + print |
| 96 | + print -- "Autonomous installer asset validation summary" |
| 97 | + print -- " PASS count : ${PASS}" |
| 98 | + print -- " FAIL count : ${FAIL}" |
| 99 | + print |
| 100 | + [ "${FAIL}" -eq 0 ] |
| 101 | +} |
| 102 | + |
| 103 | +main "$@" |
0 commit comments