Last active
November 29, 2018 20:04
-
-
Save djm158/94ea0b40b970b37349a6fea6afec08bc to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
if [ $# -le 1 ] | |
then | |
echo "Usage: get-npm-install \$PACKAGE_NAME \$PACKAGE_VERSION" | |
exit 1 | |
fi | |
PKG_NAME=$1 | |
PKG_VERSION=$2 | |
TARBALL_URL="$(npm view $PKG_NAME@$PKG_VERSION dist.tarball)" | |
TEMP_FILE=$(mktemp --quiet /tmp/XXXXXXXX) | |
# download npm tarball to tmp file | |
wget --quiet $TARBALL_URL -O $TEMP_FILE | |
# get sha256 hash | |
# sha256sum output format is $HASH $FILENAME, just get the HASH here | |
HASH=$(sha256sum $TEMP_FILE | cut -d " " -f 1) | |
# cleanup | |
rm $TEMP_FILE | |
echo "npm_install(" | |
echo " name = '${PKG_NAME}'," | |
echo " version = '${PKG_VERSION}'," | |
echo " sha256 = '${HASH}'," | |
echo ")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment