summaryrefslogtreecommitdiffstats
path: root/libexec/container/version
blob: e567f8fe1116c7a1c9f9a62c64abe945c7ba66e4 (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
#!/usr/bin/python3

# Open Infrastructure: compute-tools

# Copyright (C) 2014-2023 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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 <https://www.gnu.org/licenses/>.

from os import access, X_OK
from pathlib import Path
from subprocess import run
from sys import exit, stderr, stdout

import compute_tools.container as container

def main():
    # pre hooks
    pre_hooks = Path('/etc/compute-tools/hooks').glob('pre-version.*')

    if pre_hooks:
        # hooks exist
        for hook in pre_hooks:
            if access(hook, X_OK):
                # hook is executable
                run(str(hook), shell=True, stderr=stderr, stdout=stdout)

    # run
    container.print_version()

    # post hooks
    post_hooks = Path('/etc/compute-tools/hooks').glob('post-version.*')

    if post_hooks:
        # hooks exist
        for hook in post_hooks:
            if access(hook, X_OK):
                # hook is executable
                run(str(hook), shell=True, stderr=stderr, stdout=stdout)

    exit(0)

if __name__ == '__main__':
    main()