Skip to content

Instantly share code, notes, and snippets.

@mklooss
Last active November 4, 2025 12:02
Show Gist options
  • Select an option

  • Save mklooss/730008dbd6325688f570b4cf04783727 to your computer and use it in GitHub Desktop.

Select an option

Save mklooss/730008dbd6325688f570b4cf04783727 to your computer and use it in GitHub Desktop.
sri_regenerate.sh
<?php
$file = file_get_contents('sri-hashes.json');
$json = json_decode($file, true);
$output = [];
foreach ($json as $key => $value)
{
$filename = '../'.$key;
if (!file_exists($filename))
{
$output[$key] = $value;
}
$content = file_get_contents($filename);
$hash = base64_encode(hash('sha256', $content, true));
$integrity = "sha256" . "-{$hash}";
$output[$key] = $integrity;
}
if (file_exists('sri-hashes.json.tmp'))
{
@unlink('sri-hashes.json.tmp');
}
file_put_contents('sri-hashes.json.tmp', json_encode($output));
if (file_exists('sri-hashes.json'))
{
@unlink('sri-hashes.json');
rename('sri-hashes.json.tmp', 'sri-hashes.json');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment