Rework permission handling in scripts

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko
2022-08-05 17:05:36 -07:00
parent 68bae258a3
commit 8add7e5d39
5 changed files with 34 additions and 20 deletions

View File

@@ -22,6 +22,12 @@ set -eu -o pipefail
script_dir="$(cd -- "$(dirname -- "$0")" > /dev/null 2>&1; pwd -P)"
# e2e and Cirrus will fail with "sudo: command not found"
SUDO=''
if (( $EUID != 0 )); then
SUDO='sudo'
fi
function install_runc() {
# When updating runc-version, consider updating the runc module in go.mod as well
: "${RUNC_VERSION:=$(cat "${script_dir}/runc-version")}"
@@ -31,15 +37,15 @@ function install_runc() {
pushd "${TMPROOT}"/runc
git checkout "${RUNC_VERSION}"
make BUILDTAGS='seccomp' runc
make install
$SUDO make install
popd
rm -fR "${TMPROOT}"
}
function install_crun() {
: "${CRUN_VERSION:=$(cat "${script_dir}/crun-version")}"
curl -S -o /usr/local/sbin/runc -L https://github.com/containers/crun/releases/download/"${CRUN_VERSION}"/crun-"${CRUN_VERSION}"-linux-"$(go env GOARCH)"
chmod +x /usr/local/sbin/runc
$SUDO curl -S -o /usr/local/sbin/runc -L https://github.com/containers/crun/releases/download/"${CRUN_VERSION}"/crun-"${CRUN_VERSION}"-linux-"$(go env GOARCH)"
$SUDO chmod +x /usr/local/sbin/runc
}
: "${RUNC_FLAVOR:=runc}"