#!/bin/bash #################################################################### #### Code-Server Update Script #### #### For RHEL/Rocky/Alma, Oracle Linux, Debian & Ubuntu #### #### #### #### Author: Phil Connor #### #### Contact: contact@mylinux.work #### #### License: MIT #### #### Version: 1.2 #### #### #### #### Usage: sudo ./update-code-server.sh #### #################################################################### ############################# #### User Configurations #### ############################# SERVDIR=/usr/local/code-server # where you want the code-server installed ######################## #### System Configs #### ######################## OS=$(grep PRETTY_NAME /etc/os-release | sed 's/PRETTY_NAME=//g' | tr -d '="' | awk '{print $1}' | tr '[:upper:]' '[:lower:]') OSVER=$(grep VERSION_ID /etc/os-release | sed 's/VERSION_ID=//g' | tr -d '="' | awk -F. '{print $1}') CSVER=$(code-server --version | awk '{print $1}') ########################################################### #### Detect Package Manger from OS and OSVer Variables #### ########################################################### if [ "${OS}" = ubuntu ]; then PAKMGR="apt-get -y" elif [[ ${OS} = centos || ${OS} = red || ${OS} = oracle || ${OS} = rocky || ${OS} = alma ]]; then if [ "${OSVER}" = 7 ]; then PAKMGR="yum -y" fi if [ "${OSVER}" = 8 ] || [ "${OSVER}" = 9 ]; then PAKMGR="dnf -y" fi fi ################### #### Update OS #### ################### function update_os() { { if [ "${OS}" = ubuntu ]; then ${PAKMGR} update ${PAKMGR} upgrade else ${PAKMGR} update fi } } ############################################### #### Get the latest version of Code Server #### ############################################### get_latest_version() { { version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/coder/code-server/releases/latest)" version="${version#https://github.com/coder/code-server/releases/tag/}" version="${version#v}" echo "$version" #### Compare Code-Server versions #### if [[ "$version" != "$CSVER" ]] && [[ "$(printf '%s\n' "$CSVER" "$version" | sort -V | tail -1)" == "$version" ]]; then compare=1 else compare=0 fi } } ######################################### #### Download and Update Codeserver #### ######################################### install_codeserver() { { if [ $compare = 1 ]; then systemctl stop code-server # check if command wget exists if ! command -v wget >/dev/null 2>&1; then ${PAKMGR} install wget fi cd ~/ || exit wget "https://github.com/coder/code-server/releases/download/v$version/code-server-$version-linux-amd64.tar.gz" tar xvf "code-server-$version-linux-amd64.tar.gz" cp -r ~/code-server-"$version"-linux-amd64/* ${SERVDIR} rm -f ~/code-server-"$version"-linux-amd64.tar.gz rm -rf ~/code-server-"$version"-linux-amd64 systemctl start code-server fi } } #update_os get_latest_version install_codeserver