Skip to content

Instantly share code, notes, and snippets.

@henry701
Forked from joaomoreno/README.md
Last active December 1, 2022 19:36
Show Gist options
  • Save henry701/79a872003e3a399c230f4001518d49f0 to your computer and use it in GitHub Desktop.
Save henry701/79a872003e3a399c230f4001518d49f0 to your computer and use it in GitHub Desktop.
VS Code Insiders Updater for Linux

VS Code Insiders Updater

This script will update VSCode with the latest VS Code Insiders version.

Install

  1. Install jq: https://stedolan.github.io/jq/download/
  2. Place update-code somewhere in your PATH
#!/usr/bin/env bash
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ ;)
set -euo pipefail
IFS=$'\n\t'
# Too much output can't hurt, it's Bash.
set -x
CODE_PATH="/c/Raiz/VSCode"
PRODUCT_JSON="${CODE_PATH}/resources/app/product.json"
OS_ARCH="win32-x64"
# Portable? 1 or 0
IS_ARCHIVE="1"
if [[ "${IS_ARCHIVE}" == "1" ]]; then
OS_ARCH="${OS_ARCH}-archive"
fi
[ -f "${PRODUCT_JSON}" ] && VERSION=$(cat "${PRODUCT_JSON}" | jq -r '.commit') || VERSION="latest"
UPDATE_URL="https://update.code.visualstudio.com/api/update/${OS_ARCH}/insider/${VERSION}"
echo "Fetching ${UPDATE_URL}..."
UPDATE_RESPONSE_FILE="$(mktemp)"
UPDATE_RESPONSE_CODE="$(curl --silent --output "${UPDATE_RESPONSE_FILE}" --write-out "%{http_code}" "${UPDATE_URL}")"
if [ "${UPDATE_RESPONSE_CODE}" -ne 200 ]; then
echo "Got ${UPDATE_RESPONSE_CODE} from server, update not available"
read -p "Press any key to resume ..."
exit 0
fi
UPDATE_RESPONSE="$(cat "${UPDATE_RESPONSE_FILE}")"
echo "Update response JSON: ${UPDATE_RESPONSE}"
rm "${UPDATE_RESPONSE_FILE}"
AVAILABLE_PRODUCT_VERSION="$(echo ${UPDATE_RESPONSE} | jq -r '.productVersion')"
HASH="$(echo ${UPDATE_RESPONSE} | jq -r '.sha256hash')"
DOWNLOAD_URL="$(echo ${UPDATE_RESPONSE} | jq -r '.url')"
echo "Found update: ${AVAILABLE_PRODUCT_VERSION}"
echo "Downloading ${DOWNLOAD_URL}..."
DOWNLOAD_PATH="$(mktemp)"
curl "${DOWNLOAD_URL}" --output "${DOWNLOAD_PATH}"
echo "Downloaded to ${DOWNLOAD_PATH}"
echo -n "Hash check: "
echo "${HASH} ${DOWNLOAD_PATH}" | sha256sum -c
echo "Removing old version..."
# Preserve portable "data" subfolder
find "${CODE_PATH}" -mindepth 1 -maxdepth 1 ! -regex "^${CODE_PATH}/data\(/.*\)?" -exec rm -rf {} \;
echo "Extracting to $CODE_PATH..."
mkdir -p "${CODE_PATH}"
FILEINFO="$(file "${DOWNLOAD_PATH}")"
if [[ "${IS_ARCHIVE}" != "1" ]]; then
# Execute setup
"${DOWNLOAD_PATH}"
else
UC_FILEINFO="${FILEINFO^^}"
if [[ "${UC_FILEINFO}" = *"ZIP"* ]]; then
unzip "${DOWNLOAD_PATH}" -d "${CODE_PATH}"
elif [[ "${UC_FILEINFO}" = *"TAR"* ]]; then
tar -xzfv "${DOWNLOAD_PATH}" -C "${CODE_PATH}"
fi
fi
rm "${DOWNLOAD_PATH}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment