Skip to content

Instantly share code, notes, and snippets.

@arieljannai
Last active August 29, 2015 14:10
Show Gist options
  • Save arieljannai/2bf954d51c57cc413f00 to your computer and use it in GitHub Desktop.
Save arieljannai/2bf954d51c57cc413f00 to your computer and use it in GitHub Desktop.
Download chrome extension
#!/bin/bash
# work in progress
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} [-h] <-a APP_ID>...
Do stuff with FILE and write the result to standard output. With no FILE
or when FILE is -, read standard input.
-h display this help and exit
-a APP_ID downloading the crx file for the specified app id
EOF
}
OPTIND=1
while getopts "h?a:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
a) app_id=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
if [ "$app_id" ]
then
base_download_url="https://clients2.google.com/service/update2/crx?response=redirect&prodversion=38.0&x=id%3DPUT_HERE_APP_ID%26installsource%3Dondemand%26uc"
#app_id=mnieoidhfojjegnlioncpneloopflfde
app_url=$(curl -s "https://chrome.google.com/webstore/detail/$app_id" |
sed -e 's/<a /\n<a /gI' |
grep -i '<a .*href=.*>' |
sed -e 's/<a .*href=['"'"'"]//I' -e 's/["'"'"'].*$//I' -e '/chrome/ !d')
app_details=$(curl -s $app_url |
sed -e 's/<meta /\n<meta /gI' -e 's/\/>/\/>\n/ gI' |
grep -Ei '<meta itemprop=\"name|version\".*>' |
sed -e 's/<meta.*content=\"//g' -e 's/\" \/>//g')
app_name=$(echo "$app_details" | sed -n '1 p' | sed -e 's/ /-/g')
app_version=$(echo "$app_details" | sed -n '2 p')
crx_download_url=$(sed "s/PUT_HERE_APP_ID/$app_id/g" <<< $base_download_url)
echo app_id: $app_id
echo app_url: $app_url
echo app_name: $app_name
echo app_version: $app_version
echo base_download_url: $base_download_url
echo crx_download_url: $crx_download_url
crx_filename=$(echo "$app_name"_"$app_version".crx)
curl_result=$(curl -s $crx_download_url)
if (echo "$curl_result" | grep -qi "Moved")
then
crx_download_url=$(echo "$curl_result" | sed -e 's/<a /\n<a /gI' | grep -i '<a .*href=.*>' | sed -e 's/<a .*href=['"'"'"]//I' -e 's/["'"'"'].*$//I' -e '/google/ !d')
fi
curl -s -o "$crx_filename" $crx_download_url
else
show_help
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment