Created
August 5, 2019 02:41
-
-
Save calvinbui/b07cf6d291d3cd87ecc8d90d32e54dbb to your computer and use it in GitHub Desktop.
Ungoogled Chromium Extension Updater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Downloads Chrome extensions | |
# dependencies: | |
# npm install -g chrome-web-store-item-property-cli | |
# brew install jq | |
# brew install curl | |
set -e | |
while getopts ":f" arg; do | |
case $arg in | |
f) force="true" ;; | |
*) ;; | |
esac | |
done | |
EXTENSIONS_DIR="$HOME/Library/Application Support/Chromium/Default/Extensions" | |
DOWNLOAD_DIR="$HOME/Nextcloud/Backups/Chrome Extensions Backups" | |
CHROMVER=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' /Applications/Chromium.app/Contents/Info.plist) | |
MAJVER=$(awk -F. '{printf "%d.%d",$1,$2}' <<< "$CHROMVER") | |
cd "$DOWNLOAD_DIR" || (echo "Download directory does not exist. Exiting"; exit) | |
NEW_EXTENSIONS=() | |
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%_*}" | |
echo "" | |
echo "$NAME" | |
echo "Newest version available: $VERSION" | |
echo "Existing installed versions: ${EXISTINGVER[*]}" | |
echo "Newest installed version (alphabetically): $NEWESTVERWITHOUTTRAILINGDIGIT" | |
if [[ "$NEWESTVERWITHOUTTRAILINGDIGIT" == "$VERSION" ]] && [[ $force != "true" ]]; then | |
echo "You have version '${EXISTINGVER[-1]}', which is probably the same. Skipping..." | |
continue | |
fi | |
URL="https://clients2.google.com/service/update2/crx?response=redirect&&acceptformat=crx3&prodversion=$MAJVER&x=id%3D$ID%26installsource%3Dondemand%26uc" | |
echo "Downloading $NAME - $VERSION..." | |
curl -s -L "$URL" > "$DOWNLOAD_DIR/$NAME-$VERSION.crx" | |
NEW_EXTENSIONS+=("$NAME-$VERSION.crx") | |
done | |
echo "" | |
echo "" | |
echo "" | |
if [[ "${#NEW_EXTENSIONS[@]}" -gt 1 ]]; then | |
echo "New extensions downloaded:" | |
for extension in "${NEW_EXTENSIONS[@]}" | |
do | |
echo "- $extension" | |
done | |
echo "" | |
echo "Go to chrome://extensions and drag-and-drop in the new extensions." | |
else | |
echo "No new updates." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment