1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
7 from mozfile
import which
9 from mozboot
.base
import BaseBootstrapper
10 from mozboot
.linux_common
import LinuxBootstrapper
13 class CentOSFedoraBootstrapper(LinuxBootstrapper
, BaseBootstrapper
):
14 def __init__(self
, distro
, version
, dist_id
, **kwargs
):
15 BaseBootstrapper
.__init
__(self
, **kwargs
)
18 self
.version
= int(version
.split(".")[0])
19 self
.dist_id
= dist_id
21 def install_packages(self
, packages
):
22 if self
.version
>= 33 and "perl" in packages
:
23 packages
.append("perl-FindBin")
24 # watchman is not available on centos/rocky
25 if self
.distro
in ("centos", "rocky", "oracle"):
26 packages
= [p
for p
in packages
if p
!= "watchman"]
27 self
.dnf_install(*packages
)
29 def upgrade_mercurial(self
, current
):
31 self
.dnf_install("mercurial")
33 self
.dnf_update("mercurial")
35 def dnf_install(self
, *packages
):
38 def not_installed(package
):
39 # We could check for "Error: No matching Packages to list", but
40 # checking `dnf`s exit code is sufficent.
41 # Ideally we'd invoke dnf with '--cacheonly', but there's:
42 # https://bugzilla.redhat.com/show_bug.cgi?id=2030255
43 is_installed
= subprocess
.run(
44 ["dnf", "list", "--installed", package
],
45 stdout
=subprocess
.PIPE
,
46 stderr
=subprocess
.STDOUT
,
48 if is_installed
.returncode
not in [0, 1]:
49 stdout
= is_installed
.stdout
51 f
'Failed to determine whether package "{package}" is installed: "{stdout}"'
53 return is_installed
.returncode
!= 0
55 packages
= list(filter(not_installed
, packages
))
56 if len(packages
) == 0:
57 # avoid sudo prompt (support unattended re-bootstrapping)
60 command
= ["dnf", "install"]
62 command
= ["yum", "install"]
64 if self
.no_interactive
:
66 command
.extend(packages
)
68 self
.run_as_root(command
)
70 def dnf_update(self
, *packages
):
72 command
= ["dnf", "update"]
74 command
= ["yum", "update"]
76 if self
.no_interactive
:
78 command
.extend(packages
)
80 self
.run_as_root(command
)