diff options
Diffstat (limited to 'roles/radicle_node/files')
-rw-r--r-- | roles/radicle_node/files/rad-config-pin | 23 | ||||
-rw-r--r-- | roles/radicle_node/files/rad-config-update | 34 |
2 files changed, 57 insertions, 0 deletions
diff --git a/roles/radicle_node/files/rad-config-pin b/roles/radicle_node/files/rad-config-pin new file mode 100644 index 0000000..0e40f00 --- /dev/null +++ b/roles/radicle_node/files/rad-config-pin @@ -0,0 +1,23 @@ +#!/usr/bin/python3 + +import json, os, subprocess, sys + +rid = sys.argv[1] + +p = subprocess.run(["rad", "config", "show"], check=True, capture_output=True) +if p.returncode != 0: + sys.exit("rad config show failed") +config = json.loads(p.stdout.decode()) + +config["web"]["pinned"]["repositories"].append(rid) + +p = subprocess.run(["rad", "self", "--home"], check=True, capture_output=True) +if p.returncode != 0: + sys.exit("rad self --home failed") + +home = p.stdout.decode().strip() +filename = os.path.join(home, "config.json") +if os.path.exists(filename): + os.rename(filename, filename + ".bak") +with open(filename, "w") as f: + f.write(json.dumps(config, indent=4)) diff --git a/roles/radicle_node/files/rad-config-update b/roles/radicle_node/files/rad-config-update new file mode 100644 index 0000000..40dd1a9 --- /dev/null +++ b/roles/radicle_node/files/rad-config-update @@ -0,0 +1,34 @@ +#!/usr/bin/python3 + +import json, os, subprocess, sys + +alias = sys.argv[1] +ext = sys.argv[2] +policy = sys.argv[3] +scope = sys.argv[4] +peer = sys.argv[5] + +p = subprocess.run(["rad", "config", "show"], capture_output=True) +if p.returncode != 0: + sys.exit("rad config show failed") +config = json.loads(p.stdout.decode()) + +config["node"]["alias"] = alias +config["node"]["externalAddresses"] = [ext] +config["node"]["policy"] = policy +config["node"]["scope"] = scope + +nodes = config["node"]["connect"] +if peer not in nodes: + nodes.append(peer) + +p = subprocess.run(["rad", "self", "--home"], check=True, capture_output=True) +if p.returncode != 0: + sys.exit("rad self --home failed") + +home = p.stdout.decode().strip() +filename = os.path.join(home, "config.json") +if os.path.exists(filename): + os.rename(filename, filename + ".bak") +with open(filename, "w") as f: + f.write(json.dumps(config, indent=4)) |