Code Server Update Script
I use this script to Update the code-servers that I use regularly, the updates come out fairly regular, so you can setup a cron job to run every 15 to 30 days to automatically update it, or manually when you get a popup in the code-server software letting you know that there is an update available
You can download it here or from the bottom of the page
I copy this script to the /usr/local/bin/ dir and chmod it to 700 and run it from the terminal window in code-server when I want to manually check for updates and also have a cron configured for it that runs every 25 days
Here's my cron for this script
* * 25 * * /usr/local/bin/UpdateCodeSVR.sh
User Variable - Set this to your installed dir, so the script knows where to copy the new version of code-server
#############################
#### User Configurations ####
#############################
SERVDIR=/usr/local/code-server # where your code-server is installed
Getting OS and OS Version info
#########################
#### 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}')
If you are running an auto package updater, or manually update your OS after testing the packages you can safely remove or comment out these 2 lines
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}')
Setting package manager based on OS and Version variables - again you can safely remove or comment out this section
###########################################################
#### Detect Package Manger from OS and OSVer Variables ####
###########################################################
if [ "${OS}" = ubuntu ]; then
PAKMGR="apt-get -y"
elif [[ ${OS} = centos || ${OS} = redhat || ${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
Checking to see if there are any updates to install - and yet again you can safely remove or comment out this section
###################
#### Update OS ####
###################
${PAKMGR} update
if [ "${OS}" = ubuntu ]; then
${PAKMGR} update
${PAKMGR} upgrade
fi
Getting the code-server version
###############################################
#### 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 install the new version of code-server if newer version is detected
#########################################
#### 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}
systemctl restart code-server
fi
}
}
Function calls
get_latest_version
install_codeserver
You can download this script here
Comments