Skip to content

Commit 11d3f1a

Browse files
pks-tgitster
authored andcommitted
ci: skip sudo when we are already root
Our "install-dependencies.sh" script is executed by non-dockerized jobs to install dependencies. These jobs don't run with "root" permissions, but with a separate user. Consequently, we need to use sudo(8) there to elevate permissions when installing packages. We're about to merge "install-docker-dependencies.sh" into that script though, and our Docker containers do run as "root". Using sudo(8) is thus unnecessary there, even though it would be harmless. On some images like Alpine Linux though there is no sudo(8) available by default, which would consequently break the build. Adapt the script to make "sudo" a no-op when running as "root" user. This allows us to easily reuse the script for our dockerized jobs. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab2b3aa commit 11d3f1a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ci/install-dependencies.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ UBUNTU_COMMON_PKGS="make libssl-dev libcurl4-openssl-dev libexpat-dev
1111
tcl tk gettext zlib1g-dev perl-modules liberror-perl libauthen-sasl-perl
1212
libemail-valid-perl libio-socket-ssl-perl libnet-smtp-ssl-perl"
1313

14+
# Make sudo a no-op and execute the command directly when running as root.
15+
# While using sudo would be fine on most platforms when we are root already,
16+
# some platforms like e.g. Alpine Linux do not have sudo available by default
17+
# and would thus break.
18+
if test "$(id -u)" -eq 0
19+
then
20+
sudo () {
21+
"$@"
22+
}
23+
fi
24+
1425
case "$distro" in
1526
ubuntu-*)
1627
sudo apt-get -q update

0 commit comments

Comments
 (0)