aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/obs/lib/metapkg.py
blob: 38ed930ee056821830d148b62449c2aec9e0ecbf (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright 2022 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
import os
import lib
import lib.config
import lib.debian
import lib.rpm_spec


def get_conflicts():
    ret = []
    for f in lib.config.feeds:
        if f == lib.args.feed:
            continue
        ret += [f"osmocom-{f}"]
    return ret


def prepare_source_dir():
    path = f"{lib.config.path_cache}/osmocom-{lib.args.feed}"

    if os.path.exists(path):
        lib.run_cmd(["rm", "-rf", path])

    os.makedirs(f"{path}/debian")
    os.makedirs(f"{path}/contrib")


def generate_debian_pkg(version):
    feed = lib.args.feed
    path = f"{lib.config.path_cache}/osmocom-{feed}"
    conflicts = get_conflicts()

    with open(f"{path}/debian/control", "w") as f:
        f.write(f"Source: osmocom-{feed}\n")
        f.write("Section: unknown\n")
        f.write("Priority: optional\n")
        f.write("Maintainer: Osmocom OBS scripts <info@osmocom.org>\n")
        f.write("Build-Depends: debhelper (>= 10)\n")
        f.write("Standards-Version: 3.9.8\n")
        f.write("\n")
        f.write(f"Package: osmocom-{feed}\n")
        f.write("Depends: ${misc:Depends}\n")
        f.write("Architecture: any\n")
        f.write(f"Conflicts: {', '.join(conflicts)}\n")
        f.write(f"Description: Dummy package, conflicts with {conflicts}\n")

    with open(f"{path}/debian/changelog", "w") as f:
        f.write(f"osmocom-{feed} ({version}) unstable; urgency=medium\n")
        f.write("\n")
        f.write(f"  * Dummy package, which conflicts with: {conflicts}\n")
        f.write("\n")
        f.write(" -- Osmocom OBS scripts <info@osmocom.org>  Tue, 25 Jul 2022"
                " 15:48:00 +0200\n")

    with open(f"{path}/debian/rules", "w") as f:
        f.write("#!/usr/bin/make -f\n")
        f.write("%:\n")
        f.write("\tdh $@\n")

    lib.run_cmd(["chmod", "+x", f"{path}/debian/rules"])

    with open(f"{path}/debian/compat", "w") as f:
        f.write("10\n")


def generate_rpm_spec(version):
    feed = lib.args.feed
    print(f"osmocom-{feed}: generating rpm spec file")
    path = (f"{lib.config.path_cache}/osmocom-{feed}/contrib/osmocom-{feed}"
            ".spec.in")
    conflicts = get_conflicts()

    with open(path, "w") as f:
        f.write(f"Name:    osmocom-{feed}\n")
        f.write(f"Version: {version}\n")
        f.write(f"Summary: Dummy package, conflicts with: {conflicts}\n")
        f.write("Release: 0\n")
        f.write("License: AGPL-3.0-or-later\n")
        f.write("Group:   Hardware/Mobile\n")
        for conflict in conflicts:
            f.write(f"Conflicts: {conflict}\n")
        f.write("%description\n")
        f.write(f"Dummy package, which conflicts with: {conflicts}\n")
        f.write("%files\n")


def build():
    feed = lib.args.feed
    pkgname = lib.args.conflict_pkgname or f"osmocom-{feed}"
    conflict_version = lib.args.conflict_version
    version = conflict_version if conflict_version else "1.0.0"
    print(f"{pkgname}: generating meta package {version}")

    prepare_source_dir()
    generate_debian_pkg(version)

    os.makedirs(lib.get_output_path(pkgname))
    lib.remove_cache_extra_files()

    lib.debian.build_source_package(pkgname)
    lib.debian.move_files_to_output(pkgname)

    generate_rpm_spec(version)
    lib.rpm_spec.copy_to_output(pkgname)

    lib.remove_cache_extra_files()
    return version