Skip to content

Instantly share code, notes, and snippets.

@nicoandmee
Forked from bitst0rm/getcrx.sh
Last active July 23, 2022 22:10
Show Gist options
  • Save nicoandmee/682941fa0132da0141eea9934bf212df to your computer and use it in GitHub Desktop.
Save nicoandmee/682941fa0132da0141eea9934bf212df to your computer and use it in GitHub Desktop.
A bash script to download chrome extension files from Chrome Web Store
#!/usr/bin/env bash
# A bash script to download chrome extension files from Chrome Web Store
# 30.12.2018, https://github.com/bitst0rm
# 23.07.2022 https://github.com/nicoandmee
# extensions.zip contains URLs to download
if [ ! -f ./extensions.txt ]; then
echo "Missing extensions.txt file."
echo "extensions.txt should contain newline delimited list of webstore links."
exit 1
fi
# Pretty print
print () {
if [ "$2" == "error" ] ; then
COLOR="7;91m" # light red
elif [ "$2" == "success" ] ; then
COLOR="7;92m" # light green
elif [ "$2" == "warning" ] ; then
COLOR="7;33m" # yellow
elif [ "$2" == "info" ] ; then
COLOR="7;94m" # light blue
else
COLOR="0m" # colorless
fi
STARTCOLOR="\\e[$COLOR"
ENDCOLOR="\\e[0m"
printf "$STARTCOLOR%b$ENDCOLOR" "$1\\n"
}
case "$(uname -s)" in
Linux*) os=linux;;
Darwin*) os=mac;;
*) os=win;;
esac
case "$(uname -m)" in
armv*) arch=arm
os_arch=arm
nacl_arch=arm;;
*64) arch=x64
os_arch=x86_64
nacl_arch=x86-64;;
*) arch=x32
os_arch=x86_32
nacl_arch=x86-32;;
esac
c=0
while IFS='' read -r target || [ -n "${target}" ]; do
# Check if it's a valid Chrome Web Store URL
if [[ "$target" =~ ^https?://chrome\.google\.com/webstore/detail/ ]]; then
# Check if the given URL exists
if curl -sfI "$target" -o /dev/null; then
((c++))
# Parse the extension ID of the given URL
id=${target##*/}
id=${id%\?*}
# Parse the name of the extension from Chrome Web Store
name=$(curl -s "$target" | sed -n 's/.*<meta property="og:title" content="\([^"]*\).*/\1/p')
# Parse the version of the extension from HTTP headers
# Tip: Use "chrome://net-internals/" to sniff the download url
url='https://clients2.google.com/service/update2/crx?response=redirect'
url+="&os=${os}"
url+="&arch=${arch}"
url+="&os_arch=${os_arch}"
url+="&nacl_arch=${nacl_arch}"
url+="&prod=chromiumcrx"
url+="&prodchannel="
url+="&prodversion=103.0.5060.114"
url+="&lang=en"
url+="&acceptformat=crx2,crx3"
url+="&x=id%3D${id}%26installsource%3Dondemand%26uc"
version=$(curl -sIL "$url" | sed -n 's/location:*//p' | sed -e 's/.*extension_\(.*\).crx/\1/')
# Clean up filename
file=$(echo "${name}_${version}.crx" | tr -s ' ' '-' | tr -d '\r\n' | sed -e 's/&amp;/\&/g' -e 's/[\/:*?"<>|]/_/g')
# Download the extension file with corrected filename
print "[${c}] Downloading ${file} ..." "success"
curl -L "${url}" -o "${file}"
# Unzip it for convenience
print "[${c}] Unpacking ${file} ..." "info"
dir="${file%.*}"
unzip -o -q "${file}" -d "$dir"
rm -f "${file}"
# Beautify any html|css|js files
print "[${c}] Beautifying source ..." "info"
fd . "$dir" -e js -e json -e html -x js-beautify -r
else
print "[WARNING] URL does not exist: $target" "warning"
fi
else
print "[WARNING] invalid URL: $target" "warning"
fi
print "\n"
done < ./extensions.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment