| 
          #!/usr/bin/python3 | 
        
        
           | 
          import sys | 
        
        
           | 
          import subprocess | 
        
        
           | 
          from ruamel.yaml import YAML | 
        
        
           | 
          
 | 
        
        
           | 
          # 1. read file with 'origin binary' to figure out what binary packages | 
        
        
           | 
          #    to update. | 
        
        
           | 
          # 2. edit yaml to | 
        
        
           | 
          #    a. insert usrmerge repo from https://github.com/wolfi-dev/os/pull/40273 | 
        
        
           | 
          #    b. insert merged-sbin dependency | 
        
        
           | 
          #    c. bump epoch | 
        
        
           | 
          
 | 
        
        
           | 
          # https://github.com/wolfi-dev/os/pull/42522 | 
        
        
           | 
          add_repo = "https://apk.cgr.dev/wolfi-presubmit/4325ca278487afbfe85a38c1d32d81bb2d3de208" | 
        
        
           | 
          add_dep = "merged-sbin" | 
        
        
           | 
          epoch_bump = 1 | 
        
        
           | 
          
 | 
        
        
           | 
          # https://docs.google.com/spreadsheets/d/1lupbYGYLL3KKQJPORgXtJQCvV3uAWKGh40_8aV764L0/edit?gid=826790128#gid=826790128&fvid=19945842 | 
        
        
           | 
          # I just picked origin and binary-pkg column from a 'wolfi sbin' view. | 
        
        
           | 
          # copy and pasted here. | 
        
        
           | 
          pkgdata = """\ | 
        
        
           | 
          apk-tools	apk-tools | 
        
        
           | 
          cifs-utils	cifs-utils | 
        
        
           | 
          cilium-1.16	cilium-1.16-iptables | 
        
        
           | 
          cryptsetup	cryptsetup | 
        
        
           | 
          dhclient	dhclient | 
        
        
           | 
          e2fsprogs	e2fsprogs | 
        
        
           | 
          efs-utils	efs-utils | 
        
        
           | 
          fuse2	fuse2 | 
        
        
           | 
          glibc	glibc | 
        
        
           | 
          glibc	sln | 
        
        
           | 
          iproute2	iproute2 | 
        
        
           | 
          iptables	ip6tables | 
        
        
           | 
          iptables	iptables | 
        
        
           | 
          iptables	iptables-xtables-privileged | 
        
        
           | 
          keyutils	keyutils | 
        
        
           | 
          lvm2	device-mapper | 
        
        
           | 
          lvm2	lvm2 | 
        
        
           | 
          net-tools	mii-tool | 
        
        
           | 
          net-tools	net-tools | 
        
        
           | 
          nfs-utils	nfs-utils | 
        
        
           | 
          ntfs-3g	ntfs-3g | 
        
        
           | 
          openrc	openrc | 
        
        
           | 
          runit	runit | 
        
        
           | 
          shadow	shadow-login | 
        
        
           | 
          su-exec	su-exec | 
        
        
           | 
          systemd	systemd-init | 
        
        
           | 
          tini	tini | 
        
        
           | 
          tini	tini-static | 
        
        
           | 
          util-linux	agetty | 
        
        
           | 
          util-linux	blkid | 
        
        
           | 
          util-linux	blockdev | 
        
        
           | 
          util-linux	cfdisk | 
        
        
           | 
          util-linux	fstrim | 
        
        
           | 
          util-linux	losetup | 
        
        
           | 
          util-linux	runuser | 
        
        
           | 
          util-linux	sfdisk | 
        
        
           | 
          util-linux	util-linux-login | 
        
        
           | 
          util-linux	util-linux-misc | 
        
        
           | 
          util-linux	wipefs | 
        
        
           | 
          utmps	utmps | 
        
        
           | 
          zfs	zfs | 
        
        
           | 
          """ | 
        
        
           | 
          
 | 
        
        
           | 
          # util-linux has a vars/data/range packages that mess this up | 
        
        
           | 
          # so I did that one manually | 
        
        
           | 
          skips = ["glibc", "util-linux"] | 
        
        
           | 
          
 | 
        
        
           | 
          def add_test_repos(meldata, repos, binpkgs): | 
        
        
           | 
              found = [] | 
        
        
           | 
              rkeyname = "repositories" | 
        
        
           | 
              def _add_test_repos(t, repos): | 
        
        
           | 
                  if "environment" not in t: | 
        
        
           | 
                      t["environment"] = {} | 
        
        
           | 
                  if "contents" not in t["environment"]: | 
        
        
           | 
                      t["environment"]["contents"] = {} | 
        
        
           | 
                  if rkeyname not in t["environment"]["contents"]: | 
        
        
           | 
                      t["environment"]["contents"][rkeyname] = [] | 
        
        
           | 
          
 | 
        
        
           | 
                  t["environment"]["contents"][rkeyname].extend(repos) | 
        
        
           | 
          
 | 
        
        
           | 
              mainpkg = meldata["package"]["name"] | 
        
        
           | 
              if "test" in meldata and mainpkg in binpkgs: | 
        
        
           | 
                  _add_test_repos(meldata["test"], repos) | 
        
        
           | 
                  found.append(mainpkg) | 
        
        
           | 
          
 | 
        
        
           | 
              if "subpackages" in meldata: | 
        
        
           | 
                  for subp in meldata["subpackages"]: | 
        
        
           | 
                      subpname = subp["name"].replace("${{package.name}}", mainpkg) | 
        
        
           | 
                      if subpname not in binpkgs: | 
        
        
           | 
                          continue | 
        
        
           | 
                      if "test" not in subp: | 
        
        
           | 
                          continue | 
        
        
           | 
                      print("adding repos for %s (%s)" % (mainpkg, subpname)) | 
        
        
           | 
                      _add_test_repos(subp["test"], repos) | 
        
        
           | 
                      found.append(subpname) | 
        
        
           | 
          
 | 
        
        
           | 
              return found | 
        
        
           | 
          
 | 
        
        
           | 
          
 | 
        
        
           | 
          def add_pkg_runtime_deps(meldata, newdeps, binpkgs): | 
        
        
           | 
              mainpkg = meldata["package"]["name"] | 
        
        
           | 
              found = [] | 
        
        
           | 
              def adddeps(p, deps): | 
        
        
           | 
                  if "dependencies" not in p: | 
        
        
           | 
                      p["dependencies"] = {} | 
        
        
           | 
                  if "runtime" not in p["dependencies"]: | 
        
        
           | 
                      p["dependencies"]["runtime"] = [] | 
        
        
           | 
                  d = list(p["dependencies"]["runtime"]) | 
        
        
           | 
                  d.extend(newdeps) | 
        
        
           | 
                  p["dependencies"]["runtime"] = [k for k in sorted(set(d))] | 
        
        
           | 
                  return | 
        
        
           | 
          
 | 
        
        
           | 
              if mainpkg in binpkgs: | 
        
        
           | 
                  adddeps(meldata["package"], newdeps) | 
        
        
           | 
                  found.append(mainpkg) | 
        
        
           | 
          
 | 
        
        
           | 
              if "subpackages" in meldata: | 
        
        
           | 
                  for subp in meldata["subpackages"]: | 
        
        
           | 
                      subpname = subp["name"].replace("${{package.name}}", mainpkg) | 
        
        
           | 
                      if subpname not in binpkgs: | 
        
        
           | 
                          continue | 
        
        
           | 
                      adddeps(subp, newdeps) | 
        
        
           | 
                      found.append(subpname) | 
        
        
           | 
          
 | 
        
        
           | 
              if set(found) != set(binpkgs): | 
        
        
           | 
                  print("[%s] found=%s" % (mainpkg, set(found))) | 
        
        
           | 
                  print("[%s] binpkgs=%s" % (mainpkg, binpkgs)) | 
        
        
           | 
                  raise RuntimeError("%s did not find packages %s" % | 
        
        
           | 
                                     (mainpkg, set(found).difference(set(binpkgs)))) | 
        
        
           | 
          
 | 
        
        
           | 
          
 | 
        
        
           | 
          def bump_epoch(meldata, count): | 
        
        
           | 
              meldata["package"]["epoch"] += count | 
        
        
           | 
          
 | 
        
        
           | 
          pkgs = {} | 
        
        
           | 
          for line in pkgdata.splitlines(): | 
        
        
           | 
              if not line: | 
        
        
           | 
                  continue | 
        
        
           | 
              origin, binpkg = line.split() | 
        
        
           | 
              if origin not in pkgs: | 
        
        
           | 
                  pkgs[origin] = [] | 
        
        
           | 
              pkgs[origin].append(binpkg) | 
        
        
           | 
          
 | 
        
        
           | 
          for origin, binpkgs in pkgs.items(): | 
        
        
           | 
              if origin in skips: | 
        
        
           | 
                  print(f"skipping {origin}") | 
        
        
           | 
                  continue | 
        
        
           | 
              yaml2 = YAML() | 
        
        
           | 
              yaml2.preserve_quotes = True | 
        
        
           | 
              fname = origin + ".yaml" | 
        
        
           | 
              with open(fname, "rb") as fp: | 
        
        
           | 
                  content = fp.read() | 
        
        
           | 
              y = yaml2.load(content) | 
        
        
           | 
          
 | 
        
        
           | 
              print(f"opened {fname} . bins: {binpkgs}") | 
        
        
           | 
          
 | 
        
        
           | 
              add_pkg_runtime_deps(y, [add_dep], binpkgs) | 
        
        
           | 
              with open(fname, "w") as fp: | 
        
        
           | 
                  yaml2.dump(y, fp) | 
        
        
           | 
              subprocess.check_output(["yam", fname]) | 
        
        
           | 
              subprocess.check_output( | 
        
        
           | 
                  ["git", "commit", "-m", f"{origin} - add dep on {add_dep}", fname]) | 
        
        
           | 
          
 | 
        
        
           | 
              #subpkgs_updated = add_test_repos(y, [add_repo], binpkgs) | 
        
        
           | 
              #if len(subpkgs_updated) == 0: | 
        
        
           | 
              #    print("%s did not have tests in any of %s" % (fname, binpkgs)) | 
        
        
           | 
              #else: | 
        
        
           | 
              #    with open(fname, "w") as fp: | 
        
        
           | 
              #        yaml2.dump(y, fp) | 
        
        
           | 
              #    subprocess.check_output(["yam", fname]) | 
        
        
           | 
              #    x = subprocess.check_output( | 
        
        
           | 
              #        ["git", "commit", "-m", f"{origin} add build_dep repo", fname]) | 
        
        
           | 
          
 | 
        
        
           | 
              bump_epoch(y, epoch_bump) | 
        
        
           | 
              with open(fname, "w") as fp: | 
        
        
           | 
                  yaml2.dump(y, fp) | 
        
        
           | 
              subprocess.check_output(["yam", fname]) | 
        
        
           | 
              subprocess.check_output( | 
        
        
           | 
                  ["git", "commit", "-m", f"{origin} - bump epoch by {epoch_bump}", fname]) | 
        
  
Here's a simple class I use https://github.com/dannf/py-melange-yaml