#!/bin/bash #################################################################### #### Code-Server update script for Oracle Linux, Centos/Redhat #### #### and Ubuntu Servers. #### #### Author: Phil Connor 02/10/2020 #### #### Contact: contact@mylinux.work #### #### Version 1.24.031824 #### #### #### #### To use this script chmod it to 755 ./UpDateCodeSVR.sh #### #### or simply type bash UpDateCodeSVR.sh #### #################################################################### ############################# #### User Configurations #### ############################# SERVDIR=/usr/local/code-server # where you want the code-server installed ######################## #### System Configs #### ######################## if [ "$(command -v lsb_release)" ]; then OS=$(lsb_release -i | awk '{print $3}' | tr '[:upper:]' '[:lower:]') OSVER=$(lsb_release -r | awk '{print $2}' | awk -F. '{print $1}') else 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}') fi CSVER=$(code-server --version | awk '{print $1}') ########################################################### #### Detect Package Manger from OS and OSVer Variables #### ########################################################### if [[ ${OS} = alma || ${OS} = amazon || ${OS} = centos || ${OS} = red || ${OS} = rocky || ${OS} = oracle ]]; then if [ "${OSVER}" = 7 ]; then PAKMGR="yum -y" else PAKMGR="dnf -y" fi elif [ "${OS}" = ubuntu ]; then PAKMGR="apt -y" 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" ]; 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 -rf ~/code-server-"$version"-linux-* systemctl start code-server fi } } update_os get_latest_version install_codeserver