Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get latest version of installed ungoogled chromium extensions
#!/usr/bin/env bash
# dependencies:
# https://www.npmjs.com/package/chrome-web-store-item-property-cli
# https://stedolan.github.io/jq/
# curl
# Ascertain directory in which script lives; compatible with all UNIX
# Thanks to kenorb
# http://stackoverflow.com/a/17744637/5257399
MYDIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
# configure these:
EXTENSIONS_DIR=~/"Library/Application Support/Chromium/Default/Extensions" ## e.g. on macos ~/Library/Application Support/Chromium/Profile 1/Extensions
DOWNLOAD_DIR="$MYDIR"
######################################################################################
CHROMVER=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' /Applications/Chromium.app/Contents/Info.plist)
MAJVER=$(awk -F. '{printf "%d.%d",$1,$2}' <<< "$CHROMVER")
for f in "$EXTENSIONS_DIR"/*; do
ID="${f##*/}"
if [[ "$ID" == "Temp" ]]; then
continue
fi
JSON=$(chrome-web-store-item-property "$ID")
NAME=$(jq -r '.name' <<< "$JSON")
VERSION=$(jq -r '.version' <<< "$JSON")
EXISTINGVERPATH=( "$f"/* )
EXISTINGVER=("${EXISTINGVERPATH[@]##*/}")
NEWESTPATH="${EXISTINGVERPATH[@]: -1}"
NEWESTVER="${NEWESTPATH##*/}"
NEWESTVERWITHOUTTRAILINGDIGIT="${NEWESTVER%_*}"
# WITHOUTTRAILINGDIGIT=("${EXISTINGVER[@]/%_*}")
# WITHOUTTRAILINGDIGIT
echo "
$NAME
newest version available:
$VERSION
existing installed versions:
${EXISTINGVER[@]}
newest installed version (alphabetically):
$NEWESTVERWITHOUTTRAILINGDIGIT
"
if [[ "$NEWESTVERWITHOUTTRAILINGDIGIT" == "$VERSION" ]]; then
echo "Skipping download of $NAME; you already have version '$EXISTINGVER', which is probably the same."
continue
fi
URL="https://clients2.google.com/service/update2/crx?response=redirect&prodversion=$MAJVER&x=id%3D$ID%26installsource%3Dondemand%26uc"
curl -s -L "$URL" > "$DOWNLOAD_DIR/$NAME-$VERSION.crx"
done
echo 'now go to:
chrome://extensions
and drag-and-drop in the downloaded extensions.
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.