From b3e4954ebdf48964875aaf2bc9fffad85de58e1e Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Sun, 7 Jan 2024 17:50:16 +0000 Subject: [PATCH] drive the disk image creation from amt-setupbin --- amt-setupbin-img/main.go | 7 +++++++ create-provisioning-certificate.sh | 12 +----------- main.js | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/amt-setupbin-img/main.go b/amt-setupbin-img/main.go index f264f39..7d0cd63 100644 --- a/amt-setupbin-img/main.go +++ b/amt-setupbin-img/main.go @@ -43,6 +43,13 @@ func main() { }, } + err = os.Remove(*setupBinImgPath) + if err != nil { + if !os.IsNotExist(err) { + log.Panic(err) + } + } + disk, err := diskfs.Create(*setupBinImgPath, int64(diskSize), diskfs.Raw, diskfs.SectorSize(sectorSize)) if err != nil { log.Panic(err) diff --git a/create-provisioning-certificate.sh b/create-provisioning-certificate.sh index a541523..981ef78 100755 --- a/create-provisioning-certificate.sh +++ b/create-provisioning-certificate.sh @@ -83,7 +83,7 @@ popd >/dev/null # build the binaries. docker build -t amt-setupbin . -# Create the AMT configuration file. +# Create the Setup.bin AMT configuration file and the Setup.bin.img disk image. docker run --rm \ -i \ -u "$(id -u):$(id -g)" \ @@ -95,13 +95,3 @@ docker run --rm \ --new-password "$amt_device_new_password" \ --pki-dns-suffix "$amt_domain" \ --certificate "$amt_ca_certificate_hash AMT CA" - -# create a disk image with the AMT configuration file. -rm -f amt-ca/Setup.bin.img -docker run --rm \ - -i \ - -u "$(id -u):$(id -g)" \ - -v "$PWD/amt-ca:/host:rw" \ - -w /host \ - --entrypoint amt-setupbin-img \ - amt-setupbin diff --git a/main.js b/main.js index 6420520..0a3e0cc 100644 --- a/main.js +++ b/main.js @@ -49,6 +49,26 @@ function writeAmtSetupBin(setupBinPath, variables) { fs.writeFileSync(setupBinPath, data, "binary"); } +async function writeAmtSetupBinImg(setupBinPath, setupBinImgPath) { + const p = Bun.spawn([ + "amt-setupbin-img", + `-path=${setupBinPath}`, + `-img-path=${setupBinImgPath}` + ], { + stdin: null, + stdout: "inherit", + stderr: "inherit", + }); + try { + const exitCode = await p.exited; + if (exitCode !== 0) { + throw Error(`amt-setupbin-img failed with exit code ${exitCode}`); + } + } finally { + p.unref(); + } +} + function readAmtSetupBin(data) { const decoded = AmtSetupBinDecode(data); if (!decoded) { @@ -138,6 +158,9 @@ async function main(options) { log(`Dumping the created AMT Setup.bin...`); console.log(setup); } + + log(`Creating the AMT Setup.bin.img disk image file at ${options.path}.img...`); + await writeAmtSetupBinImg(options.path, `${options.path}.img`); } program