Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Add k3s upgrade script #248

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions overlay/sbin/k3s-upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

if [ $(whoami) != "root" ]
then
echo "This script must be run as root."
exit 1
fi

PROC=$(uname -m)

# Take a parameter of the version number (i.e. v0.4.0) if it is given, otherwise use latest
if [ -z $K3S_VERSION ]
then
K3S_VERSION=$(curl -sL api.github.com/repos/rancher/k3s/releases/latest | jq .tag_name -r)
fi

if [ $PROC == "x86_64" ]
then
ARCH=""
elif [ $PROC == "aarch64" ]
then
ARCH="-arm64"
elif [ $PROC == "armv7l" ]
then
ARCH="-armhf"
else
echo "Unsupported CPU architecture."
exit 1
fi

K3S_URL="https://github.com/rancher/k3s/releases/download/${K3S_VERSION}/k3s${ARCH}"

cd /k3os/system/k3s
mount -o remount,rw ..
echo "Upgrading k3s to ${K3S_VERSION}"
mkdir -p "${K3S_VERSION}"
curl -fsSL -o "${K3S_VERSION}/k3s" "${K3S_URL}"
chmod +x "${K3S_VERSION}/k3s"
ln -sfn "${K3S_VERSION}" current
sync

echo "Upgrade complete! Please reboot."