Skip to content

Instantly share code, notes, and snippets.

@chittti
Created April 2, 2017 03:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chittti/6f59b53053c44954414ff15d58265606 to your computer and use it in GitHub Desktop.
Save chittti/6f59b53053c44954414ff15d58265606 to your computer and use it in GitHub Desktop.
Bash script to get chrome extension
#!/bin/bash
# Created by Likhith Chitneni (chittti)
# Thanks to Rob Wu for crxviewer (https://github.com/Rob--W/crxviewer)
# This bash script takes in command line arguments too!
# Arguments can be passed in as
# ./crx-getter.sh <extension-ID> <chrome-version> <OS(1-6)> <arch(1-3)> <chrome(1)/chromium(2)> <stable(1)/unknown(2)>
# Only <extension-id> and <chrome-version> are mandatory, the rest default to linux, x86-64, chrome, stable respectively
if [[ $# -eq 0 ]]; then
echo "Enter extension ID:"
read EXTENSION_ID
if [[ ${#EXTENSION_ID} -ne 32 ]]; then
echo "Invalid extension ID"
exit 1
fi
echo "Enter chrome version:"
read PRODVERSION
VERSION_DOTS="${PRODVERSION//[^.]}"
if [[ ${#VERSION_DOTS} -ne 3 ]]; then
echo "Invalid version number"
exit 1
fi
# More details about OS, arch, and Nacl arch can be found at:
# https://developer.chrome.com/extensions/runtime
echo "What OS do you want the extension for? (Defaults to linux)"
echo "(1) Linux"
echo "(2) Windows"
echo "(3) macOS"
echo "(4) ChromeOS"
echo "(5) Android"
echo "(6) OpenBSD"
read OS_CODE
case $OS_CODE in
2)
OS="win"
;;
3)
OS="mac"
;;
4)
OS="cros"
;;
5)
OS="android"
;;
6)
OS="openbsd"
;;
*)
OS="linux"
;;
esac
# Prompts only once for system arch and Nacl arch
echo "What arch do you want the extension for? (Defaults to x86-64)"
echo "(1) x86-64"
echo "(2) x86-32"
echo "(3) arm"
read ARCH_CODE
case $ARCH_CODE in
2)
ARCH="x86-32"
NACL_ARCH="x86-32"
;;
3)
ARCH="arm"
NACL_ARCH="arm"
;;
*)
ARCH="x86-64"
NACL_ARCH="x86-64"
;;
esac
# @NOTE: PROD can be altogether omitted, but lets not do that
echo "Chrome or Chromium? (Defaults to chrome)"
echo "(1) Chrome"
echo "(2) Chromium"
read CHROME_CODE
case $CHROME_CODE in
2)
PROD="chromiumcrx"
;;
*)
PROD="chromecrx"
;;
esac
# @NOTE: Can also use "unknown" for PRODCHANNEL
echo "Channel: Stable or unknown? (Defaults to stable)"
echo "(1) Stable"
echo "(2) Unknown"
read PRODCHANNEL_CODE
case $CHROME_CODE in
2)
PRODCHANNEL="unknown"
;;
*)
PRODCHANNEL="stable"
;;
esac
else
if [[ ${#1} -ne 32 ]]; then
echo "Invalid extension ID"
exit 1
fi
EXTENSION_ID=$1
VERSION_DOTS="${2//[^.]}"
if [[ ${#VERSION_DOTS} -ne 3 ]]; then
echo "Invalid version number"
exit 1
fi
PRODVERSION=$2
case $OS_CODE in
2)
OS="win"
;;
3)
OS="mac"
;;
4)
OS="cros"
;;
5)
OS="android"
;;
6)
OS="openbsd"
;;
*)
OS="linux"
;;
esac
case $4 in
2)
ARCH="x86-32"
NACL_ARCH="x86-32"
;;
3)
ARCH="arm"
NACL_ARCH="arm"
;;
*)
ARCH="x86-64"
NACL_ARCH="x86-64"
;;
esac
case $5 in
2)
PROD="chromiumcrx"
;;
*)
PROD="chromecrx"
;;
esac
case $6 in
2)
PRODCHANNEL="unknown"
;;
*)
PRODCHANNEL="stable"
;;
esac
fi
URL='https://clients2.google.com/service/update2/crx?response=redirect'
URL+='&os='
URL+=$OS
URL+='&arch='
URL+=$ARCH
URL+='&nacl_arch='
URL+=$NACL_ARCH
URL+='&prod='
URL+=$PROD
URL+='&prodchannel='
URL+=$PRODCHANNEL
URL+='&prodversion='
URL+=$PRODVERSION
URL+='&x=id%3D'
URL+=$EXTENSION_ID
URL+='%26uc'
wget -O ${EXTENSION_ID}-${PRODVERSION}-${PRODCHANNEL}-${PROD::${#PROD}-3}-${OS}-${ARCH}.zip $URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment