From dde2fef0c52096d845fc44e253d06b0612355828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20N=C3=A4gele?= Date: Fri, 10 Jan 2025 19:07:58 +0100 Subject: [PATCH] Fix K3S_DATA_DIR when running as non-root user (#11378) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running the generated kill and uninstall scripts, the environment variable `K3S_DATA_DIR` got lost, because `sudo` by default doesn't preserve the environment. This is fixed by adding the `--preserve-env` flag. Signed-off-by: Reinhard Nägele --- install.sh | 10 +++++----- install.sh.sha256sum | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index a6a7fd201f..438ec661e4 100755 --- a/install.sh +++ b/install.sh @@ -510,7 +510,7 @@ get_pr_artifact_url() { if [ -z "${commit_id}" ]; then fatal "Installing PR builds requires GITHUB_TOKEN with k3s-io/k3s repo permissions" fi - + # GET request to the GitHub API to retrieve the Build workflow associated with the commit run_id=$(curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" "${github_api_url}/commits/${commit_id}/check-runs?check_name=build%20%2F%20Build" | jq -r '[.check_runs | sort_by(.id) | .[].details_url | split("/")[7]] | last') @@ -626,7 +626,7 @@ setup_selinux() { install_selinux_rpm ${rpm_site} ${rpm_channel} ${rpm_target} ${rpm_site_infix} policy_error=fatal - if [ "$INSTALL_K3S_SELINUX_WARN" = true ] || [ "${ID_LIKE:-}" = coreos ] || + if [ "$INSTALL_K3S_SELINUX_WARN" = true ] || [ "${ID_LIKE:-}" = coreos ] || [ "${VARIANT_ID:-}" = coreos ] || [ "${VARIANT_ID:-}" = iot ]; then policy_error=warn fi @@ -646,7 +646,7 @@ setup_selinux() { } install_selinux_rpm() { - if [ -r /etc/redhat-release ] || [ -r /etc/centos-release ] || [ -r /etc/oracle-release ] || + if [ -r /etc/redhat-release ] || [ -r /etc/centos-release ] || [ -r /etc/oracle-release ] || [ -r /etc/fedora-release ] || [ -r /etc/system-release ] || [ "${ID_LIKE%%[ ]*}" = "suse" ]; then repodir=/etc/yum.repos.d if [ -d /etc/zypp/repos.d ]; then @@ -775,7 +775,7 @@ create_killall() { info "Creating killall script ${KILLALL_K3S_SH}" $SUDO tee ${KILLALL_K3S_SH} >/dev/null << \EOF #!/bin/sh -[ $(id -u) -eq 0 ] || exec sudo $0 $@ +[ $(id -u) -eq 0 ] || exec sudo --preserve-env=K3S_DATA_DIR $0 $@ K3S_DATA_DIR=${K3S_DATA_DIR:-/var/lib/rancher/k3s} @@ -877,7 +877,7 @@ create_uninstall() { $SUDO tee ${UNINSTALL_K3S_SH} >/dev/null << EOF #!/bin/sh set -x -[ \$(id -u) -eq 0 ] || exec sudo \$0 \$@ +[ \$(id -u) -eq 0 ] || exec sudo --preserve-env=K3S_DATA_DIR \$0 \$@ K3S_DATA_DIR=\${K3S_DATA_DIR:-/var/lib/rancher/k3s} diff --git a/install.sh.sha256sum b/install.sh.sha256sum index a559371018..27dbba21e9 100644 --- a/install.sh.sha256sum +++ b/install.sh.sha256sum @@ -1 +1 @@ -d75e014f2d2ab5d30a318efa5c326f3b0b7596f194afcff90fa7a7a91166d5f7 install.sh +73ca045f12174c87138d59dd14b23b8ab70d96c9eaead63104109d330daa8a6a install.sh