diff --git a/install.sh b/install.sh index 9820742ef707..623bd766aeea 100755 --- a/install.sh +++ b/install.sh @@ -962,19 +962,51 @@ rm -rf /var/lib/kubelet rm -f ${BIN_DIR}/k3s rm -f ${KILLALL_K3S_SH} -if type yum >/dev/null 2>&1; then - yum remove -y k3s-selinux - rm -f /etc/yum.repos.d/rancher-k3s-common*.repo -elif type rpm-ostree >/dev/null 2>&1; then - rpm-ostree uninstall k3s-selinux - rm -f /etc/yum.repos.d/rancher-k3s-common*.repo -elif type zypper >/dev/null 2>&1; then +# uninstall k3s-selinux package if a compatible package manager is found +zypper_remove_selinux_rpm() { uninstall_cmd="zypper remove -y k3s-selinux" if [ "\${TRANSACTIONAL_UPDATE=false}" != "true" ] && [ -x /usr/sbin/transactional-update ]; then uninstall_cmd="transactional-update --no-selfupdate -d run \$uninstall_cmd" fi - $SUDO \$uninstall_cmd + \$uninstall_cmd +} +dnf_remove_selinux_rpm() { + package_manager=dnf + # yum is only needed for rhel 7, which is EOM since 2024 anyway + if ! type dnf >/dev/null 2>&1; then + package_manager=yum + fi + \$package_manager remove -y k3s-selinux +} +rpm_ostree_uninstall_cmd="rpm-ostree uninstall --idempotent k3s-selinux" + +# shellcheck source=/dev/null +[ -r /etc/os-release ] && . /etc/os-release + +if [ "\$(expr "\${ID_LIKE}" : ".*suse.*")" != 0 ]; then + zypper_remove_selinux_rpm +# cover any standard & atomic rhel/centos/fedora + derivatives like amazon linux +elif [ "\${ID:-}" = fedora ] || [ "\$(expr "\${ID_LIKE}" : ".*fedora.*\|.*rhel.*\|.*centos.*")" != 0 ]; then + if [ -n "\${OSTREE_VERSION:-}" ]; then + \$rpm_ostree_uninstall_cmd + else + dnf_remove_selinux_rpm + fi +# if we did not match yet just check for package managers commonly found on selinux-enabled distributions +elif type rpm-ostree >/dev/null 2>&1; then + \$rpm_ostree_uninstall_cmd +elif type zypper >/dev/null 2>&1; then + zypper_remove_selinux_rpm +elif type yum >/dev/null 2>&1; then + dnf_remove_selinux_rpm +elif [ -d /usr/share/selinux ]; then + echo '[WARN] Automatic removal of "k3s-selinux" package not possible, please remove it manually.' >&2 +fi + +if [ -d /etc/zypp/repos.d ]; then rm -f /etc/zypp/repos.d/rancher-k3s-common*.repo +elif [ -d /etc/yum.repos.d ]; then + rm -f /etc/yum.repos.d/rancher-k3s-common*.repo fi EOF $SUDO chmod 755 ${UNINSTALL_K3S_SH} diff --git a/install.sh.sha256sum b/install.sh.sha256sum index 9fe5f4319dbe..e956592ad444 100644 --- a/install.sh.sha256sum +++ b/install.sh.sha256sum @@ -1 +1 @@ -46177d4c99440b4c0311b67233823a8e8a2fc09693f6c89af1a7161e152fbfad install.sh +0068b53a147d93bc66039b86d2834f2dce3d530f11ea5b803a158d8fda2030bc install.sh