Last active
July 9, 2023 15:03
-
-
Save jinliming2/4340eb117c5d2d17463ceb355ec4167f to your computer and use it in GitHub Desktop.
Updater for VSCode on Linux. Check and Update VSCode for Linux. Support Visual Studio Code Stable and Visual Studio Code Insiders.
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
#!/bin/bash | |
# set -x | |
set -euo pipefail | |
# Required: curl and rsync | |
# Config | |
INSTALL_DIR=VSCode-linux-x64 | |
INSTALL_PATH=/opt/${INSTALL_DIR} | |
# VERSION can be "stable" or "insider" | |
INSTALL_VERSION=stable | |
function log() { | |
echo `date` [`basename $0`] [I] $@ | |
} | |
function err() { | |
echo `date` [`basename $0`] [E] $@ >&2 | |
} | |
CURRENT_HASH=`cat ${INSTALL_PATH}/resources/app/product.json | grep '"commit":\s*"[A-Fa-f0-9]\{40\}"' | grep -o '[A-Fa-f0-9]\{40\}'` | |
if [ -z ${CURRENT_HASH} ]; then | |
err Cannot get current hash. | |
exit 1 | |
fi | |
log Current hash: ${CURRENT_HASH} | |
URL=`curl -fsSI https://update.code.visualstudio.com/latest/linux-x64/${INSTALL_VERSION} | grep -i Location | awk -v RS='\r\n' '{print $2}'` | |
if [ -z ${URL} ]; then | |
err Cannot get correct download URL. | |
exit 1 | |
fi | |
HASH=`echo ${URL} | grep -o '[A-Fa-f0-9]\{40\}'` | |
log Newest hash: ${HASH} | |
if [ ${CURRENT_HASH} == ${HASH} ]; then | |
log No Update Found. You are using the latest version. | |
exit 0 | |
fi | |
FILENAME=`echo ${URL} | grep -o '[^/]\+$'` | |
WORKING_DIRECTORY=`mktemp -d` | |
function cleanup { | |
if [ -d ${WORKING_DIRECTORY} ]; then | |
echo | |
log Cleanning...... | |
rm -r ${WORKING_DIRECTORY} | |
fi | |
} | |
trap cleanup EXIT | |
log Downloading update...... | |
curl -fSL -o ${WORKING_DIRECTORY}/${FILENAME} ${URL} | |
log Extracting...... | |
tar -xf ${WORKING_DIRECTORY}/${FILENAME} -C ${WORKING_DIRECTORY} | |
log Applying update...... | |
rsync -rlpvc --delete ${WORKING_DIRECTORY}/${INSTALL_DIR}/ ${INSTALL_PATH} | |
log Cleanning...... | |
rm -r ${WORKING_DIRECTORY} | |
log Update successful, Please restart VSCode! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment