Skip to content

Instantly share code, notes, and snippets.

@aapis
Last active August 27, 2021 09:15
Show Gist options
  • Save aapis/3e17f9c53149ae6679c8d1ab6cc56e74 to your computer and use it in GitHub Desktop.
Save aapis/3e17f9c53149ae6679c8d1ab6cc56e74 to your computer and use it in GitHub Desktop.
Update Visual Studio Code on Ubuntu/Debian
#!/bin/bash
clear
mkdir -p /tmp/vsc-updates
rm -f /tmp/vsc-updates/*.deb
local IFS=$'\n'
local CURRENT_VERSION=($(code -v))
echo "Updating Visual Studio Code"
echo "Current: $CURRENT_VERSION"
echo "Downloading latest..."
wget -q --user-agent Mozilla --content-disposition -E -c https://update.code.visualstudio.com/latest/linux-deb-x64/stable && mv *.deb /tmp/vsc-updates/
local DEB=$(find /tmp/vsc-updates -maxdepth 1 -type f)
local REGEX="code_([0-9.]+)"
if [[ $DEB =~ $REGEX ]]
then
local NEW_VERSION=${BASH_REMATCH[1]}
else
local NEW_VERSION=$CURRENT_VERSION
fi
echo "Latest: $NEW_VERSION"
if test "$CURRENT_VERSION" == "$NEW_VERSION"; then
echo "You're running the latest ($NEW_VERSION), no need to upgrade" && \
rm -f /tmp/vsc-updates/*.deb
else
# install update and restart the app
sudo apt install /tmp/vsc-updates/*.deb && \
killall -9 code && \
code && \
echo "Update complete"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment