Skip to content

Commit 5a7ff73

Browse files
authored
Add fallback logic for sha checksum (#17)
* Add fallback logic for sha checksum * Add changeset
1 parent e6420d1 commit 5a7ff73

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

.changeset/neat-pumpkins-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-solana-program": patch
3+
---
4+
5+
Add fallback logic for sha checksum

template/base/scripts/program/dump.mjs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,46 @@ async function dump() {
3232
return;
3333
}
3434

35-
await copyFromChain(address, `onchain-${binary}`);
36-
const [onChainHash, localHash] = await Promise.all([
37-
$`sha256sum -b ${outputDir}/onchain-${binary} | cut -d ' ' -f 1`.quiet(),
38-
$`sha256sum -b ${outputDir}/${binary} | cut -d ' ' -f 1`.quiet(),
39-
]);
35+
let sha = 'sha256sum';
36+
let options = [];
37+
let hasShaChecksum = await which('sha256sum', { nothrow: true });
4038

41-
if (onChainHash.toString() !== localHash.toString()) {
42-
echo(
43-
chalk.yellow('[ WARNING ]'),
44-
`on-chain and local binaries are different for '${binary}'`
45-
);
39+
// We might not have sha256sum on some systems, so we try shasum as well.
40+
if (!hasShaChecksum) {
41+
hasShaChecksum = await which('shasum', { nothrow: true });
42+
43+
if (hasShaChecksum) {
44+
sha = 'shasum';
45+
options = ['-a', '256'];
46+
}
47+
}
48+
49+
if (hasShaChecksum) {
50+
await copyFromChain(address, `onchain-${binary}`);
51+
const [onChainHash, localHash] = await Promise.all([
52+
$`${sha} ${options} -b ${outputDir}/onchain-${binary} | cut -d ' ' -f 1`.quiet(),
53+
$`${sha} ${options} -b ${outputDir}/${binary} | cut -d ' ' -f 1`.quiet(),
54+
]);
55+
56+
if (onChainHash.toString() !== localHash.toString()) {
57+
echo(
58+
chalk.yellow('[ WARNING ]'),
59+
`on-chain and local binaries are different for '${binary}'`
60+
);
61+
} else {
62+
echo(
63+
chalk.green('[ SKIPPED ]'),
64+
`on-chain and local binaries are the same for '${binary}'`
65+
);
66+
}
67+
68+
await $`rm ${outputDir}/onchain-${binary}`.quiet();
4669
} else {
4770
echo(
48-
chalk.green('[ SKIPPED ]'),
49-
`on-chain and local binaries are the same for '${binary}'`
71+
chalk.yellow('[ WARNING ]'),
72+
`skipped check for '${binary}' (missing 'sha256sum' command)`
5073
);
5174
}
52-
53-
await $`rm ${outputDir}/onchain-${binary}`.quiet();
5475
})
5576
);
5677
}

0 commit comments

Comments
 (0)