Last active
November 4, 2025 12:02
-
-
Save mklooss/730008dbd6325688f570b4cf04783727 to your computer and use it in GitHub Desktop.
sri_regenerate.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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