Created
February 13, 2021 00:16
-
-
Save quinncomendant/5a370311619d79df25612c3874f05f46 to your computer and use it in GitHub Desktop.
Downloads a chrome extension matching ExtensionID to ~/src/chrome-webstore-{ExtensionID}
This file contains 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 | |
# | |
# Quinn Comendant <[email protected]> | |
# 29 Sep 2017 16:09:21 | |
# | |
# Functions | |
# | |
function usage() { | |
echo "Usage: $(basename "$0") ExtensionID | |
Downloads a chrome extension matching ExtensionID | |
"; | |
exit 1; | |
} | |
function err { | |
MSG="$1"; | |
IFS=''; | |
echo "$MSG" 1>&2 | |
exit 1; | |
} | |
function debug { | |
MSG=$1; | |
[[ -n $VERBOSE ]] && echo "$MSG" 1>&2 | |
} | |
function prompt { | |
MSG=$1; | |
if [[ -n $ALWAYSYES ]]; then | |
echo "$MSG (auto-continuing…)"; | |
else | |
read -rp "$MSG [y/N]: " YN; | |
case $YN in | |
(y|Y);; | |
(*) err "Nokay, exiting.";; | |
esac | |
fi | |
} | |
# | |
# Main | |
# | |
# Display help if run without arguments. | |
[[ $# == 0 ]] && usage && exit 0; | |
[[ $# != 1 ]] && echo "Invalid arguments. Run with no args for help." && exit 1; | |
extensionid=$1; | |
prodversion=$("$HOME/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --version | f3); | |
[[ -z $prodversion ]] && err "Failed to get Chrome version"; | |
# Make dir in ~/src | |
tmpdir="$(mktemp -d "$HOME/src/chrome-webstore-${extensionid}")" || err "Download folder already exists"; | |
trap 'rm -rf "$tmpdir"' INT HUP TERM; | |
cd "$tmpdir" || err "Failed to cd to $tmpdir"; | |
# curl -Lo "${extensionid}.zip" "https://clients2.google.com/service/update2/crx?response=redirect&prodversion=60.0.3112.113&x=id%3D${extensionid}%26uc"; | |
curl -Lo "${extensionid}.zip" "https://clients2.google.com/service/update2/crx?response=redirect&prodversion=${prodversion}&acceptformat=crx2,crx3&x=id%3D${extensionid}%26uc"; | |
if [[ 0 != $? || ! -s "${extensionid}.zip" ]]; then | |
err "Failed to download"; | |
fi | |
unzip "${extensionid}.zip"; | |
rm "${extensionid}.zip"; | |
echo "Download complete: ~/src/chrome-webstore-${extensionid}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment