Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Downloads a chrome extension matching ExtensionID to ~/src/chrome-webstore-{ExtensionID}
#!/usr/bin/env bash
#
# Quinn Comendant <quinn@strangecode.com>
# 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