111 lines
4 KiB
Bash
Executable file
111 lines
4 KiB
Bash
Executable file
#!/bin/bash
|
|
[ "$1" == "-h" ] && echo "install-crio.sh install|update|remove|restart|scripts|config|reinstall|delete" && exit 1
|
|
|
|
SERVICE_NAME="crio"
|
|
SCRIPTS_DEPLOY_PATH="/etc/crio"
|
|
|
|
[ -r "env-crio" ] && . ./env-crio
|
|
[ -r "common.sh" ] && . ./common.sh
|
|
|
|
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')"
|
|
OS="$(uname | tr '[:upper:]' '[:lower:]')"
|
|
CRIO_VERSION="${CRIO_VERSION:-1.35.2}"
|
|
CRIO_URL="https://storage.googleapis.com/cri-o/artifacts/cri-o.${ARCH}.v${CRIO_VERSION}.tar.gz"
|
|
CRICTL_VERSION="${CRICTL_VERSION:-1.35.0}"
|
|
CRICTL_URL="https://github.com/kubernetes-sigs/cri-tools/releases/download"
|
|
CMD_TSK=${CMD_TSK:-${1:-install}}
|
|
export LC_CTYPE=C.UTF-8 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
|
|
}
|
|
|
|
_update_binary() {
|
|
[ -z "$CRIO_VERSION" ] && return 1
|
|
local curr_vers 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
|
|
# Distinct filename: the orchestrator pushes the taskserv bundle to
|
|
# /tmp/crio.tar.gz, so the binary download must not reuse that name or it
|
|
# clobbers/deletes the bundle and every re-run fails at `tar xzmf`.
|
|
if ! curl -fsSL "$CRIO_URL" -o /tmp/crio-dist.tar.gz; then
|
|
echo "error downloading crio"; return 1
|
|
fi
|
|
tar xzf /tmp/crio-dist.tar.gz
|
|
if [ -r "cri-o/install" ]; then
|
|
cd cri-o || return 1
|
|
[ -n "$has_crio" ] && _common_service_stop
|
|
sudo bash ./install
|
|
cd "$ORG" || return 1
|
|
else
|
|
echo "error installing crio"; return 1
|
|
fi
|
|
rm -fr cri-o /tmp/crio-dist.tar.gz
|
|
fi
|
|
local crictl_vers
|
|
crictl_vers=$(crictl --version 2>/dev/null | awk '{print $3}' | sed 's/v//g')
|
|
if [ "$crictl_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"; return 1
|
|
fi
|
|
tar xzf /tmp/crictl.tar.gz
|
|
[ -r "crictl" ] && chmod +x crictl && sudo mv crictl /usr/local/bin
|
|
rm -f /tmp/crictl.tar.gz
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
_config_crio() {
|
|
[ ! -d "/etc/crio" ] && sudo mkdir -p /etc/crio
|
|
[ ! -d "/etc/crio/crio.conf.d" ] && sudo mkdir -p /etc/crio/crio.conf.d
|
|
if [ -r "crio.conf" ] && [ ! -r "/etc/crio/crio.conf.d/10-crio.conf" ]; then
|
|
sudo cp crio.conf /etc/crio/crio.conf.d/10-crio.conf
|
|
fi
|
|
if [ -r "crictl.yaml" ] && [ ! -r "/etc/crictl.yaml" ]; then
|
|
sudo cp crictl.yaml /etc/crio-crictl.yaml
|
|
sudo cp crictl.yaml /etc/crictl.yaml
|
|
fi
|
|
for mod in overlay br_netfilter; do
|
|
sudo grep -q "^${mod}" /etc/modules-load.d/crio.conf 2>/dev/null \
|
|
|| echo "$mod" | sudo tee -a /etc/modules-load.d/crio.conf
|
|
done
|
|
[ ! -d "/etc/containers" ] && sudo mkdir -p /etc/containers
|
|
sudo timeout -k 10 20 systemctl daemon-reload
|
|
_common_service_start
|
|
}
|
|
|
|
case "$CMD_TSK" in
|
|
reinstall)
|
|
_common_service_stop
|
|
sudo rm -f /usr/local/bin/crio /usr/local/bin/crio-status /usr/local/bin/pinns ;&
|
|
install)
|
|
_update_binary || { echo "error crio install"; exit 1; }
|
|
_config_crio
|
|
;;
|
|
update) _common_update ;;
|
|
scripts) _common_deploy_scripts ;;
|
|
config) _config_crio ;;
|
|
restart) _common_service_restart ;;
|
|
remove) _common_service_stop ;;
|
|
delete)
|
|
sudo systemctl stop crio >/dev/null 2>&1 || true
|
|
sudo systemctl disable crio >/dev/null 2>&1 || true
|
|
sudo rm -f /usr/local/bin/crio /usr/local/bin/crio-status /usr/local/bin/pinns
|
|
sudo rm -f /usr/local/bin/crictl /etc/crictl.yaml /etc/crio-crictl.yaml
|
|
sudo rm -f /etc/modules-load.d/crio.conf
|
|
sudo rm -rf /var/lib/crio /run/crio
|
|
sudo rm -f /usr/local/lib/systemd/system/crio.service
|
|
sudo rm -f /lib/systemd/system/crio.service /etc/systemd/system/crio.service
|
|
sudo systemctl daemon-reload >/dev/null 2>&1
|
|
sudo rm -rf /etc/crio
|
|
;;
|
|
esac
|