summaryrefslogtreecommitdiff
path: root/build-tools/macos-build/check-macos-build-env
blob: 3cf2d2b487b1e0937d2298a0ec54b1320c6a6be7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
#
# Copyright (C) 2016 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# File: check-macos-build-env
# Purpose:
#   Checks if binaries for macOS image building are installed.


import os
import sys
from distutils.spawn import find_executable

import platform

class DependencyChecker(object):
    def __init__(self, spec):
        missing_binaries = self._get_missing_binaries(spec['binaries'])
        self.__missing = {'binaries': missing_binaries}

    def _get_missing_binaries(self, binaries):
        missing_binaries = []
        for b in binaries:
            if not find_executable(b):
                missing_binaries.append(b)
        return missing_binaries

    def get_missing_dependencies(self):
        if self.__missing['binaries']:
            return self.__missing
        return None

    def print_missing_deps(self):
        print("Missing binaries: " + " ".join(self.__missing['binaries']))

platform = platform.system()
if platform != 'Darwin':
    print("Your system is not macOS.")
    sys.exit(1)

deps = {
    'binaries': [
       'vagrant',
       'virtualbox',
       'rsync'
    ]
}

print("Checking if packages required for VyOS image build are installed")

checker = DependencyChecker(deps)

missing = checker.get_missing_dependencies()
print(missing)
if not missing:
    print("All dependencies are installed")
    sys.exit(0)
else:
    checker.print_missing_deps()
    if 'vagrant' in missing['binaries']:
        print("Your system does not have Vagrant.")
        print("Please install Vagrant from https://www.vagrantup.com/downloads.")
        sys.exit(1)
    elif 'virtualbox' in missing['binaries']:
        print("Your system does not have Virtualbox.")
        print("Please install Virtualbox from https://www.virtualbox.org/wiki/Downloads.")
        sys.exit(1)
    elif 'rsync' in missing['binaries']:
        print("Your system does not have Rsync.")
        print("Please install Rsync from https://formulae.brew.sh/formula/rsync.")
        sys.exit(1)
sys.exit(0)