provisioning/taskservs/crio/default/install-crio.sh

141 lines
4.1 KiB
Bash
Raw Normal View History

#!/bin/bash
# Info: Script to install/create/delete/update crio from file settings
# Author: JesusPerezLorenzo
# Release: 1.0
# Date: 12-10-2024
USAGE="install-crio.sh install | update | remvoe"
[ "$1" == "-h" ] && echo "$USAGE" && exit 1
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')"
OS="$(uname | tr '[:upper:]' '[:lower:]')"
[ -r "env-crio" ] && . ./env-crio
CRIO_VERSION="${CRIO_VERSION:-1.28.1}"
#CRIO_URL=https://raw.githubusercontent.com/cri-o/cri-o/master/scripts/get
CRIO_URL=https://storage.googleapis.com/cri-o/artifacts/cri-o.${ARCH}.v$CRIO_VERSION.tar.gz
CRICTL_VERSION="${CRICTL_VERSION:-1.28.0}"
CRICTL_URL="https://github.com/kubernetes-sigs/cri-tools/releases/download/"
CRIO_SYSTEMCTL_MODE=enabled
CMD_TSKSRVC=${1:-install}
export LC_CTYPE=C.UTF-8
export LANG=C.UTF-8
ORG=$(pwd)
_clean_others() {
[ -d "/etc/cni" ] && sudo rm -r /etc/cni
[ -d "/var/lib/containers" ] && sudo rm -r /var/lib/containers
sudo rm -f /etc/systemd/system/podman* 2>/dev/null
}
_init() {
[ -z "$CRIO_VERSION" ] && exit 1 # || [ -z "$CRIO_ARCH" ] || [ -z "$CRIO_URL" ] || [ -z "$CRIO_FILE" ] && exit 1
local curr_vers
local has_crio
has_crio=$(type crio 2>/dev/null)
if [ -n "$has_crio" ] ; then
curr_vers=$(crio --version | grep "^Version" | awk '{print $2}')
else
_clean_others
fi
if [ "$curr_vers" != "$CRIO_VERSION" ] ; then
if ! curl -fsSL "$CRIO_URL" -o /tmp/crio.tar.gz ; then
echo "error downloading crio "
return 1
fi
tar xzf /tmp/crio.tar.gz
if [ -r "cri-o/install" ] ; then
cd cri-o || exit 1
[ -n "$has_crio" ] && sudo timeout -k 10 20 systemctl stop crio
sudo bash ./install
cd "$ORG" || exit 1
else
echo "error installing crio"
ret=1
fi
rm -fr cri-o
rm -f /tmp/crio_installer.sh
[ "$ret" == 1 ] && return 1
fi
curr_vers=$(crictl --version | awk '{print $3}' | sed 's/v//g')
if [ "$curr_vers" != "$CRICTL_VERSION" ] ; then
if ! curl -fsSL "${CRICTL_URL}/v${CRICTL_VERSION}/crictl-v${CRICTL_VERSION}-${OS}-${ARCH}.tar.gz" -o /tmp/crictl.tar.gz ; then
echo "error downloading crictl installer"
return 1
fi
tar xzf /tmp/crictl.tar.gz
if [ -r "crictl" ] ; then
chmod +x crictl
sudo mv crictl /usr/local/bin
fi
rm -f /tmp/crictl.tar.gz
fi
return 0
}
_config_crio() {
[ ! -d "/etc/crio" ] && mkdir -p /etc/crio
if [ -r "crio_config.toml" ] && [ ! -r "/etc/crio/config.toml" ] ; then
sudo cp crio_config.toml /etc/crio/config.toml
fi
if [ -r "crio.conf" ] && [ -d "/etc/crio/crio.conf.d" ] ; then
sudo cp crio.conf /etc/crio/crio.conf.d/10-crio.conf
fi
[ -r "crio" ] && mkdir -p /etc/crio
if [ -r "crictl.yaml" ] && [ ! -r "/etc/crio-crictl.yaml" ] ; then
sudo cp crictl.yaml /etc/crio-crictl.yaml
sudo cp crictl.yaml /etc/crictl.yaml
fi
if [ -r "crio.service" ] && [ ! -r "/lib/systemd/crio.service" ] ; then
sudo cp crio.service /lib/systemd/system
[ ! -L "/etc/systemd/system/crio.service" ] && sudo ln -s /lib/systemd/system/crio.service /etc/systemd/system
sudo timeout -k 10 20 systemctl daemon-reload
fi
TARGET=/etc/modules-load.d/crio.conf
ITEMS="overlay br_netfilter"
for it in $ITEMS
do
has_item=$(sudo grep ^"$it" $TARGET 2>/dev/null)
[ -z "$has_item" ] && echo "$it" | sudo tee -a /etc/modules-load.d/crio.conf
done
_start_crio
}
_remove_crio() {
sudo timeout -k 10 20 systemctl stop crio
sudo timeout -k 10 20 systemctl disable crio
}
_start_crio() {
if [ "$CRIO_SYSTEMCTL_MODE" == "enabled" ] ; then
sudo timeout -k 10 20 systemctl enable crio
else
sudo timeout -k 10 20 systemctl disable crio
fi
sudo timeout -k 10 20 systemctl start crio
}
_restart_crio() {
sudo timeout -k 10 20 systemctl restart crio
}
[ "$CMD_TSKSRVC" == "remove" ] && _remove_crio && exit 0
if ! _init ; then
echo "error crio install"
exit 1
fi
[ "$CMD_TSKSRVC" == "update" ] && _restart_crio && exit 0
if ! _config_crio ; then
echo "error crio config"
exit 1
fi
if ! _start_crio ; then
echo "error crio start"
exit 1
fi