Skip to content

Commit

Permalink
ci: handle sudo in actions-install.sh
Browse files Browse the repository at this point in the history
We run our tests as root in containers and VMs. Those platforms do not
have sudo when running Debian-based Linux distributions. Use a small
bash function to eliminate the need to install sudo when we are running
as root.

This function just checks for the existence of sudo and uses it when
installed but does nothing when it is not installed. Using this function
eliminates the need to install sudo before we start installing all the
other packages.

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
  • Loading branch information
vincentkfu committed Sep 23, 2024
1 parent 171bbb7 commit d5f2789
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions ci/actions-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ SCRIPT_DIR=$(dirname "$0")
# shellcheck disable=SC1091
. "${SCRIPT_DIR}/common.sh"

_sudo() {
if type -P sudo >/dev/null; then
sudo "$@"
else
"$@"
fi
}

install_ubuntu() {
local pkgs

if [ "${GITHUB_JOB}" == "build-containers" ] || [ "${GITHUB_JOB}" == "qemu-guest" ]; then
# containers and guest VMs run as root and do not have sudo
apt update
apt -y install sudo
fi

cat <<DPKGCFG | sudo tee /etc/dpkg/dpkg.cfg.d/dpkg-speedup > /dev/null
cat <<DPKGCFG | _sudo tee /etc/dpkg/dpkg.cfg.d/dpkg-speedup > /dev/null
# Skip fsync
force-unsafe-io
# Don't install documentation
Expand All @@ -36,7 +38,7 @@ DPKGCFG
)
case "${CI_TARGET_ARCH}" in
"i686")
sudo dpkg --add-architecture i386
_sudo dpkg --add-architecture i386
pkgs=("${pkgs[@]/%/:i386}")
pkgs+=(
gcc-multilib
Expand All @@ -62,7 +64,7 @@ DPKGCFG
)
if apt list --installed | grep -c "libunwind-14-dev"; then
echo "Removing libunwind-14-dev because of conflicts with libunwind-dev"
sudo apt remove -y libunwind-14-dev
_sudo apt remove -y libunwind-14-dev
fi
if [ "${CI_TARGET_OS}" == "linux" ] || [ "${CI_TARGET_OS}" == "ubuntu" ]; then
# Only for Ubuntu
Expand Down Expand Up @@ -90,9 +92,9 @@ DPKGCFG
fi

echo "Updating APT..."
sudo apt-get -qq update
_sudo apt-get -qq update
echo "Installing packages... ${pkgs[@]}"
sudo apt-get install -o APT::Immediate-Configure=false --no-install-recommends -qq -y "${pkgs[@]}"
_sudo apt-get install -o APT::Immediate-Configure=false --no-install-recommends -qq -y "${pkgs[@]}"
}

# Fedora and related distributions
Expand All @@ -116,7 +118,6 @@ install_fedora() {
protobuf-c-devel
python3-scipy
python3-sphinx
sudo
valgrind-devel
)

Expand Down

0 comments on commit d5f2789

Please sign in to comment.