Last active
June 3, 2022 21:25
-
-
Save cyfrost/8a0d18fb9408879dcb90686c12de6c6b to your computer and use it in GitHub Desktop.
[Ubuntu] Simple shell script to install (or update to) latest version of VSCodium
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 | |
# This script will check if VSCodium is installed in your machine, if yes, then tries to update it to the latest version | |
# else, installs whichever the latest version is. | |
# | |
# NOTE: There's already this repo (https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo) that provides | |
# the codium package for APT based distros but for some reason the download was extremely slow. | |
# This script pulls the download from github directly (which is hopefully a tad bit faster). | |
# Thanks to https://stackoverflow.com/a/4024263/2631023 | |
function verlte() { | |
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] | |
} | |
# Thanks to https://stackoverflow.com/a/4024263/2631023 | |
function verlt() { | |
[ "$1" = "$2" ] && return 1 || verlte $1 $2 | |
} | |
# Checks if Codium is installed, if yes, tries to update it to latest version, else installs latest version. | |
function install_or_update_latest_codium() { | |
pkg="codium" | |
if ! dpkg -s $pkg >/dev/null 2>&1; then | |
INSTALLED_VERSION="NOT_INSTALLED" | |
else | |
INSTALLED_VERSION="$(dpkg-query --showformat='${Version}' --show $pkg | egrep -o '^[^-]+')" | |
fi | |
LATEST_VERSION="$(curl -sL https://api.github.com/repos/vscodium/vscodium/releases/latest | grep -Po '"tag_name": "\K.*?(?=")')" && \ | |
verlt "$INSTALLED_VERSION" "$LATEST_VERSION" && IS_UPDATE_AVAILABLE="yes" || IS_UPDATE_AVAILABLE="no" | |
if [ "$IS_UPDATE_AVAILABLE" = "yes" ] || [ "$INSTALLED_VERSION" = "NOT_INSTALLED" ]; then | |
[ "$INSTALLED_VERSION" = "NOT_INSTALLED" ] && MSG="Downloading and installing latest VSCodium v$LATEST_VERSION ..." || MSG="Updating VSCodium from $INSTALLED_VERSION to $LATEST_VERSION..." | |
printf "\n$MSG\n\n" | |
DEB_FILE="$(curl -sL https://api.github.com/repos/vscodium/vscodium/releases/latest | grep "https.*amd64.deb" | head -1 | cut -d '"' -f 4)" | |
FILENAME="/tmp/vscodium.deb" | |
[ -f $FILENAME ] && rm -f $FILENAME | |
wget -O $FILENAME $DEB_FILE -q --show-progress | |
sudo apt install -y "$FILENAME" && cp -f $FILENAME .; printf "\nFinished\n\n" || printf "\nError: failed to install VSCodium version $LATEST_VERSION.\n\n" | |
else | |
printf "\nVSCodium is already up-to-date (Installed: "$INSTALLED_VERSION", Latest: "$LATEST_VERSION").\n\n" | |
fi | |
} | |
install_or_update_latest_codium |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
bash <(curl -s https://gist.githubusercontent.com/cyfrost/8a0d18fb9408879dcb90686c12de6c6b/raw/install-latest-vscodium-ubuntu.sh)