Skip to content

Instantly share code, notes, and snippets.

@ekohl
Created June 29, 2022 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekohl/ce876b9fcc4ec29a27983291658ec64e to your computer and use it in GitHub Desktop.
Save ekohl/ce876b9fcc4ec29a27983291658ec64e to your computer and use it in GitHub Desktop.
#!/bin/bash -e
# Intended as a proof of concept to see if we can purge the NPM cache in npm2rpm
cd "$1"
package="$(basename $(realpath .))"
spectool --get-files "${package}.spec"
cachedir=$(mktemp -d)
trap "rm -rf '${cachedir}'" EXIT
echo "Cache size before (compressed)"
ls -sh "${package}"-[0-9]*-registry.npmjs.org.tgz
tar xaf "${package}"-[0-9]*-registry.npmjs.org.tgz -C "$cachedir"
echo "Cache size before (uncompressed)"
du -sh "$cachedir"
for filename in *.tgz ; do
checksum=$(sha512sum "$filename" | cut -d' ' -f1)
echo "Handling ${filename} (${checksum})"
cache_filename="${cachedir}/_cacache/content-v2/sha512/${checksum:0:2}/${checksum:2:2}/${checksum:4}"
rm -fv $cache_filename
done
echo "Cache size after (uncompressed)"
du -sh "$cachedir"
tar caf "${package}-new-registry.npmjs.org.tgz" -C "$cachedir" .
echo "Cache size after (compressed)"
ls -sh "${package}-new-registry.npmjs.org.tgz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment