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
3# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5from __future__ import absolute_import, print_function, unicode_literals
6
7import sys
8import subprocess
9
10from mozboot.base import BaseBootstrapper
11from mozboot.linux_common import LinuxBootstrapper
12
13# NOTE: This script is intended to be run with a vanilla Python install.  We
14# have to rely on the standard library instead of Python 2+3 helpers like
15# the six module.
16if sys.version_info < (3,):
17    input = raw_input  # noqa
18
19
20class SolusBootstrapper(LinuxBootstrapper, BaseBootstrapper):
21    """Solus experimental bootstrapper."""
22
23    SYSTEM_PACKAGES = [
24        "nodejs",
25        "unzip",
26        "zip",
27    ]
28    SYSTEM_COMPONENTS = [
29        "system.devel",
30    ]
31
32    BROWSER_PACKAGES = [
33        "alsa-lib",
34        "dbus",
35        "libgtk-3",
36        "libevent",
37        "libvpx",
38        "libxt",
39        "nasm",
40        "libstartup-notification",
41        "gst-plugins-base",
42        "gst-plugins-good",
43        "pulseaudio",
44        "xorg-server-xvfb",
45    ]
46
47    MOBILE_ANDROID_COMMON_PACKAGES = [
48        "openjdk-8",
49        # For downloading the Android SDK and NDK.
50        "wget",
51        # See comment about 32 bit binaries and multilib below.
52        "ncurses-32bit",
53        "readline-32bit",
54        "zlib-32bit",
55    ]
56
57    def __init__(self, version, dist_id, **kwargs):
58        print("Using an experimental bootstrapper for Solus.")
59        BaseBootstrapper.__init__(self, **kwargs)
60
61    def install_system_packages(self):
62        self.package_install(*self.SYSTEM_PACKAGES)
63        self.component_install(*self.SYSTEM_COMPONENTS)
64
65    def install_browser_packages(self, mozconfig_builder):
66        self.ensure_browser_packages()
67
68    def install_browser_artifact_mode_packages(self, mozconfig_builder):
69        self.ensure_browser_packages(artifact_mode=True)
70
71    def install_mobile_android_packages(self, mozconfig_builder):
72        self.ensure_mobile_android_packages(mozconfig_builder)
73
74    def install_mobile_android_artifact_mode_packages(self, mozconfig_builder):
75        self.ensure_mobile_android_packages(mozconfig_builder, artifact_mode=True)
76
77    def ensure_browser_packages(self, artifact_mode=False):
78        self.package_install(*self.BROWSER_PACKAGES)
79
80    def ensure_nasm_packages(self, state_dir, checkout_root):
81        # installed via ensure_browser_packages
82        pass
83
84    def ensure_mobile_android_packages(self, mozconfig_builder, artifact_mode=False):
85        try:
86            self.package_install(*self.MOBILE_ANDROID_COMMON_PACKAGES)
87        except Exception as e:
88            print("Failed to install all packages!")
89            raise e
90
91        # 2. Android pieces.
92        self.ensure_java(mozconfig_builder)
93        super().ensure_mobile_android_packages(artifact_mode=artifact_mode)
94
95    def _update_package_manager(self):
96        pass
97
98    def upgrade_mercurial(self, current):
99        self.package_install("mercurial")
100
101    def package_install(self, *packages):
102        command = ["eopkg", "install"]
103        if self.no_interactive:
104            command.append("--yes-all")
105
106        command.extend(packages)
107
108        self.run_as_root(command)
109
110    def component_install(self, *components):
111        command = ["eopkg", "install", "-c"]
112        if self.no_interactive:
113            command.append("--yes-all")
114
115        command.extend(components)
116
117        self.run_as_root(command)
118
119    def run(self, command, env=None):
120        subprocess.check_call(command, stdin=sys.stdin, env=env)
121