Skip to content

Instantly share code, notes, and snippets.

@bskiefer
Last active June 10, 2024 14:50
Show Gist options
  • Save bskiefer/9aa823a39f3edbeb7bf1f59294ac11cc to your computer and use it in GitHub Desktop.
Save bskiefer/9aa823a39f3edbeb7bf1f59294ac11cc to your computer and use it in GitHub Desktop.
VSCodium Update Extensions from VS Marketplace

This script will gather the extensions currently installed for VSCodium and update them from marketplace.visualstudio.com automatically.

  • Packages defined under $SKIP are ignored.
  • Old extension folders are removed before the update is installed.

Why?

  • open-vsx.org doesn't get updated very quickly, if at all
  • it's "illegal" to use the VS Marketplace as the extension source in non-M$ products
#!/bin/bash
SKIP=("devsense.phptools-vscode" "bmewburn.vscode-intelephense-client")
install_extension() {
VERS="${3// /.}"
echo Downloading $1 $2 "$VERS"
mkdir -p workspace
pushd workspace
URL="https://marketplace.visualstudio.com/_apis/public/gallery/publishers/$1/vsextensions/$2/${VERS}/vspackage"
curl "$URL" \
-H 'authority: marketplace.visualstudio.com' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'cache-control: no-cache' \
-H 'cookie: Gallery-Service-UserIdentifier=739351fc-f6de-4297-b8b4-447cd46196ab; VSCodeOneClickInstallMessageOptOut=true; Market_SelectedTab=vscode; VstsSession=%7B%22PersistentSessionId%22%3A%224877797f-2d67-4b17-8cc5-98338babf116%22%2C%22PendingAuthenticationSessionId%22%3A%22b4543624-f0e4-4aa0-ad2f-6bd9607302c1%22%2C%22CurrentAuthenticationSessionId%22%3A%22a3723ade-6504-4605-b494-d595e3bd40f2%22%2C%22SignInState%22%3A%7B%22app.vssps.visualstudio.com%22%3A%7B%22LastSignInTick%22%3A637806295323748473%2C%22SignInCount%22%3A1%7D%2C%22spsprodweu4.vssps.visualstudio.com%22%3A%7B%22LastSignInTick%22%3A637843343999849099%2C%22SignInCount%22%3A2%7D%7D%7D; MSCC=NR; at_check=true' \
-H 'dnt: 1' \
-H 'pragma: no-cache' \
-H "referer: https://marketplace.visualstudio.com/items?itemName=${1}.${2}" \
-H 'sec-ch-ua: "Chromium";v="102", " Not A;Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'sec-fetch-dest: document' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-site: same-origin' \
-H 'sec-fetch-user: ?1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.125 Safari/537.36' \
--compressed \
-o vsix.zip
unzip -qq vsix.zip
PUBLISHER=$(grep Identity extension.vsixmanifest | sed -r 's/.*Publisher="([A-Z0-9a-z\.-]+)".*/\1/g')
ID=$(grep Identity extension.vsixmanifest | sed -r 's/.*Id="([A-Z0-9a-z\.-]+)".*/\1/g')
VERSION=$(grep Identity extension.vsixmanifest | sed -r 's/.*Version="([A-Z0-9a-z\.-]+)".*/\1/g')
OLD_DEST="$PUBLISHER.$ID-$4"
rm -rf $HOME/.vscode-oss/extensions/"$OLD_DEST"
DEST="$PUBLISHER.$ID-$VERSION"
mv extension $HOME/.vscode-oss/extensions/"$DEST"
popd
rm -rf workspace
}
get_version() {
DATA=$(curl -s -XPOST 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' \
--header 'Accept: application/json;api-version=6.1-preview.1' \
--header 'Content-Type: application/json' \
--data-binary "{\"assetTypes\": [\"Microsoft.VisualStudio.Services.VSIXPackage\"],\"filters\": [{\"criteria\": [{\"filterType\": 7,\"value\": \"${1}.${2}\"}]}],\"flags\": 3}")
EXTNAME=$(echo $DATA | jq -r '.results[0].extensions[0].displayName')
URL=$(echo $DATA | jq -r '.results[0].extensions[0].versions[0].files[0].source')
VERSION=$(echo $DATA | jq -r '.results[0].extensions[0].versions[0].version')
}
containsElement() {
local e match="$1"
# local -n ref=$1
shift
for e; do [[ "$e" == "$match" ]] && echo 1 && return; done
echo 0
}
run() {
exts=$(codium --list-extensions --show-versions)
for line in $exts; do
set -- "$line"
IFS="@"
declare -a Array=($*)
set -- "${Array[0]}"
IFS="."
declare -a ID=($*)
local VERSION="abc"
get_version "${ID[0]}" "${ID[1]}"
VERS="${VERSION// /.}"
ISD="${ID[0]}.${ID[1]}"
PREV=$(find $HOME/.vscode-oss/extensions -type d -maxdepth 1 -iname "${ISD}-${Array[1]}"*)
if [ "${Array[1]}" != "$VERS" ]; then
if [ "$VERS" != null ]; then
echo "${ID[0]}.${ID[1]}: ${Array[1]} >>> $VERS"
skippable=$(containsElement "${ID[0]}.${ID[1]}" "${SKIP[@]}")
if [ "$skippable" != 1 ]; then
echo "Updating ${ISD}..."
if [ "$PREV" != null ]; then
echo "Removing ${PREV}..."
rm -rf "$PREV"
fi
install_extension "${ID[0]}" "${ID[1]}" "${VERS}" "${Array[0]}"
else
echo "Skipping ${ISD}..."
fi
fi
fi
done
}
run
@RolfNoot
Copy link

RolfNoot commented Mar 1, 2023

Hi,

What about extensions using Telemetry? For example the C/C++ extension by Microsoft. Is it safe to use these extensions within VSCodium?

image

@RolfNoot
Copy link

RolfNoot commented Mar 1, 2023

Works perfect, one suggestion: check if jq works. It wasn't installed on my mac and I had to reinstall all extensions.
brew install jq

@shinya17
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment