Skip to content

Instantly share code, notes, and snippets.

@jpitts
Last active December 15, 2020 08:55
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 jpitts/1607fa891d621c164b0a1c40b0f7aceb to your computer and use it in GitHub Desktop.
Save jpitts/1607fa891d621c164b0a1c40b0f7aceb to your computer and use it in GitHub Desktop.
checksum-local-metamask.sh
#!/bin/bash
# Please see recent, related work:
# Overview: https://jpitts.medium.com/how-to-checksum-a-dapp-e865d952310c
# Checksum the Launchpad: https://gist.github.com/jpitts/73acca4969fcb3ddd8a62d2666d116ed
DATE=`date +%FT%H:%M:%S`
CURRENT_DIR=`pwd`
# MetaMask https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en
DAPP_VERSION="8.1.8_0"
DAPP_ID="nkbihfbeogaeaoehlefnkodbefgpgknn"
# local directories and files
LOCAL_EXTENSIONS_DIR='~/Library/Application Support/Google/Chrome/Default/Extensions'
EXTENSION_SYMLINK='extension'
SYNC_DIR=$(echo "metamask__${DATE}" | sed -e "s/\:\/\//-/g" -e "s/\//-/g" -e "s/\./-/g" -e "s/\:/-/g")
CSV_FILE="${SYNC_DIR}__checksums.csv"
# On OSX it was necessary to manually create a symlink to the chrome extension
# (encountered headaches due to escaping which should have been solved with double quotes)
if [[ ! -L ${EXTENSION_SYMLINK} ]] ; then
echo "NOTE: If you're on OSX you will need to manually run a properly-excaped...
ln -s ${LOCAL_EXTENSIONS_DIR}/${DAPP_ID}/${DAPP_VERSON} ${EXTENSION_SYMLINK}
...or you're gonna have a hard time!"
exit
else
echo "Ready to proceed; the symlink ${EXTENSION_SYMLINK} is in place."
fi
mkdir $SYNC_DIR && cd ${EXTENSION_SYMLINK} && cp -R ./* "${CURRENT_DIR}/${SYNC_DIR}/" && cd ..
# OK, back to the normal business of checksumming dapps
# the core of it
find $SYNC_DIR -type f -print0 | xargs -0 -n1 shasum -a 384 \
| sort -k2 | sed -e "s/$SYNC_DIR//" \
| awk '{print "\"" $2 "\"" "," "\"" $1 "\"";}' > $CSV_FILE \
&& shasum -a 384 $CSV_FILE | echo $(awk 'NR==1{print $1}')
# for quick sanity checks by the operator
ln -fs $SYNC_DIR latest-download-dir
ln -fs $CSV_FILE latest-checksums.csv
exit
@jpitts
Copy link
Author

jpitts commented Dec 15, 2020

Make sure to check out some earlier, related work: "How To Checksum A Dapp" which applies the same principle to live web content.

https://jpitts.medium.com/how-to-checksum-a-dapp-e865d952310c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment