Skip to content

Instantly share code, notes, and snippets.

@tored
Last active July 26, 2023 13:09
Show Gist options
  • Save tored/29d781b84920f3e50dea to your computer and use it in GitHub Desktop.
Save tored/29d781b84920f3e50dea to your computer and use it in GitHub Desktop.
Installer for Visual Studio Code for Linux (Ubuntu)
#!/usr/bin/env bash
# Taken and modified from
# http://www.thepowerbase.com/2015/04/install-visual-studio-code-ubuntu-14-04-14-10-15-04/
DOWNLOAD_URL=https://az764295.vo.msecnd.net/public/0.10.2/VSCode-linux64.zip
VSCODE_DIR=/opt/VSCode
DESKTOP_FILE_PATH=/usr/share/applications/visualstudiocode.desktop
ICON_FILE_PATH=$VSCODE_DIR/resources/app/resources/linux/vscode.png
TMP_DIR=/tmp/VSCode
TMP_FILE=$TMP_DIR/VSCode-linux-x64.zip
function desktop_file {
cat <<-EOT > "$DESKTOP_FILE_PATH"
[Desktop Entry]
Name=Visual Studio Code
Comment=Multi-platform code editor for Linux
Exec=$VSCODE_DIR/Code
Icon=$ICON_FILE_PATH
Type=Application
StartupNotify=true
Categories=TextEditor;Development;Utility;
MimeType=text/plain;
EOT
}
function install {
mkdir "$TMP_DIR"
# Get the app and put it someplace.
wget -O "$TMP_FILE" "$DOWNLOAD_URL"
# Extract to install dir
unzip "$TMP_FILE" -d "$VSCODE_DIR/"
# hack to remove any unnecessary sub directory
if [ $(ls $VSCODE_DIR | wc -l) == 1 ]; then
subdir=$(ls "$VSCODE_DIR")
mv "$VSCODE_DIR/$subdir/"* "$VSCODE_DIR/"
rmdir "$VSCODE_DIR/$subdir"
fi
# create the desktop file
desktop_file
# clean up
rm -r $TMP_DIR
}
function uninstall {
rm -rv "$VSCODE_DIR"
rm -v "$DESKTOP_FILE_PATH"
}
if [ $# -gt 0 ]; then
uninstall
else
install
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment