Skip to content

Commit

Permalink
drive the disk image creation from amt-setupbin
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Jan 7, 2024
1 parent 80c9bc5 commit b3e4954
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
7 changes: 7 additions & 0 deletions amt-setupbin-img/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 1 addition & 11 deletions create-provisioning-certificate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)" \
Expand All @@ -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
23 changes: 23 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b3e4954

Please sign in to comment.