diff --git a/.changeset/neat-pumpkins-suffer.md b/.changeset/neat-pumpkins-suffer.md new file mode 100644 index 0000000..4210c8a --- /dev/null +++ b/.changeset/neat-pumpkins-suffer.md @@ -0,0 +1,5 @@ +--- +"create-solana-program": patch +--- + +Add fallback logic for sha checksum diff --git a/template/base/scripts/program/dump.mjs b/template/base/scripts/program/dump.mjs index 94f645c..26c234f 100755 --- a/template/base/scripts/program/dump.mjs +++ b/template/base/scripts/program/dump.mjs @@ -32,25 +32,46 @@ async function dump() { return; } - await copyFromChain(address, `onchain-${binary}`); - const [onChainHash, localHash] = await Promise.all([ - $`sha256sum -b ${outputDir}/onchain-${binary} | cut -d ' ' -f 1`.quiet(), - $`sha256sum -b ${outputDir}/${binary} | cut -d ' ' -f 1`.quiet(), - ]); + let sha = 'sha256sum'; + let options = []; + let hasShaChecksum = await which('sha256sum', { nothrow: true }); - if (onChainHash.toString() !== localHash.toString()) { - echo( - chalk.yellow('[ WARNING ]'), - `on-chain and local binaries are different for '${binary}'` - ); + // We might not have sha256sum on some systems, so we try shasum as well. + if (!hasShaChecksum) { + hasShaChecksum = await which('shasum', { nothrow: true }); + + if (hasShaChecksum) { + sha = 'shasum'; + options = ['-a', '256']; + } + } + + if (hasShaChecksum) { + await copyFromChain(address, `onchain-${binary}`); + const [onChainHash, localHash] = await Promise.all([ + $`${sha} ${options} -b ${outputDir}/onchain-${binary} | cut -d ' ' -f 1`.quiet(), + $`${sha} ${options} -b ${outputDir}/${binary} | cut -d ' ' -f 1`.quiet(), + ]); + + if (onChainHash.toString() !== localHash.toString()) { + echo( + chalk.yellow('[ WARNING ]'), + `on-chain and local binaries are different for '${binary}'` + ); + } else { + echo( + chalk.green('[ SKIPPED ]'), + `on-chain and local binaries are the same for '${binary}'` + ); + } + + await $`rm ${outputDir}/onchain-${binary}`.quiet(); } else { echo( - chalk.green('[ SKIPPED ]'), - `on-chain and local binaries are the same for '${binary}'` + chalk.yellow('[ WARNING ]'), + `skipped check for '${binary}' (missing 'sha256sum' command)` ); } - - await $`rm ${outputDir}/onchain-${binary}`.quiet(); }) ); }