Skip to content

Instantly share code, notes, and snippets.

@palto42
Last active July 28, 2021 05:49
Show Gist options
  • Save palto42/bf1b56b9fd2826053f153cb3ad246b56 to your computer and use it in GitHub Desktop.
Save palto42/bf1b56b9fd2826053f153cb3ad246b56 to your computer and use it in GitHub Desktop.
Install and update VS Code from official binary for Linux version which don't support deb, rpm or Snap (tested on Solus)
#!/bin/bash
# VS Code updater
# get installed version
installed=$($HOME/bin/VSCode-linux-x64/bin/code -v 2>/dev/null | head -n 1)
# get latest release from Github
latest=$(curl -s https://github.com/Microsoft/vscode/releases/latest | grep -Po 'tag/\K[0-9\.]*')
if [ "$installed" == "$latest" ]
then
notify-send -i ok "VS Code is up to date" "Current version $installed"
exit
fi
if pidof code
then
if zenity --question --text "Close open VS Code to proceed with the upgrade?"
then
killall -s SIGQUIT code
else
notify-send -i task-attention "New VS Code version $latest" "Please close all instances of VS Code to update."
exit
fi
fi
notify-send -i software-update-available "Updating VS Code" "Will download and install version $latest"
current=$(pwd)
if [ ! -d "$HOME/bin" ]
then
if ! mkdir "$HOME/bin"
then
notify-send -i error "Can't create folder '$HOME/bin'" "Please check path and access rights."
exit
fi
fi
cd "$HOME/bin" || exit 1
# automatically gets the latest version of VS Code
rm "stable" &>/dev/null
if ! wget "https://update.code.visualstudio.com/latest/linux-x64/stable" &>/dev/null
then
notify-send -i error "Download of new VS Code version failed." "Try manual download"
exit 1
fi
# remove currently installed version of VS Code and replace it with the new downloaded one
rm -r VSCode-linux-x64 &>/dev/null
tar -xf "stable" &>/dev/null
rm "stable"
notify-send -i ok "Successfully updated VS Code" "New version $latest installed."
cd "$current" || exit
[Desktop Entry]
Name=Visual Studio Code - URL Handler
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=/home/user/bin/VSCode-linux-x64/code --no-sandbox --open-url %U
Icon=/home/user/bin/VSCode-linux-x64/resources/app/resources/linux/code.png
Type=Application
NoDisplay=true
StartupNotify=true
Categories=Utility;TextEditor;Development;IDE;
MimeType=x-scheme-handler/vscode;
Keywords=vscode;
[Desktop Entry]
Name=Visual Studio Code
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=/home/user/bin/VSCode-linux-x64/code --no-sandbox --unity-launch %F
Icon=/home/user/bin/VSCode-linux-x64/resources/app/resources/linux/code.png
Type=Application
StartupNotify=false
StartupWMClass=Code
Categories=Utility;TextEditor;Development;IDE;
MimeType=text/plain;inode/directory;
Actions=new-empty-window;
Keywords=vscode;
[Desktop Action new-empty-window]
Name=New Empty Window
Exec=/home/user/bin/VSCode-linux-x64/code --no-sandbox --new-window %F
Icon=/home/user/bin/VSCode-linux-x64/resources/app/resources/linux/code.png
@palto42
Copy link
Author

palto42 commented Jul 16, 2020

The script update_vscode.shcan be used to install and update Microsoft VS Code from the official binary. It get's installed/updated under the user home in ~/bin/ folder in some Linux OS.

The .desktop files are used for launching the VS code (if supported by the used Linux OS). They are modifications from the .deskop files contained in the official .debpackages.

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