summaryrefslogtreecommitdiff
path: root/install-for
diff options
context:
space:
mode:
authorMatthew Fennell <matthew@fennell.dev>2024-05-29 18:16:11 +0100
committerMatthew Fennell <matthew@fennell.dev>2024-05-29 18:16:11 +0100
commita960b23caebd5362b5f292f73c6e41ebee2ad98c (patch)
tree3943738dd0407dc3ed766cddc737825805a6aea5 /install-for
parentd7e965843eb32fc2e459a15fe70251964ff40394 (diff)
Generalise prosody-specific install script
This project's initial purpose was to automatically renew certiricates across multiple prosody servers. However, over time, it has been used with more services, each with their own ad-hoc and custom installation scripts. This commit replaces the install-for-prosody script with a more general script that can handle multiple different kinds of services in the future.
Diffstat (limited to 'install-for')
-rwxr-xr-xinstall-for53
1 files changed, 53 insertions, 0 deletions
diff --git a/install-for b/install-for
new file mode 100755
index 0000000..9487273
--- /dev/null
+++ b/install-for
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+# SPDX-FileCopyrightText: 2024 Matthew Fennell <matthew@fennell.dev>
+#
+# SPDX-License-Identifier: AGPL-3.0-only
+
+import argparse
+import itertools
+import os
+import subprocess
+
+parser = argparse.ArgumentParser()
+parser.add_argument("identity_file")
+parser.add_argument("--prosody", nargs=1, default = [])
+parser.add_argument("--forgejo", nargs=1, default = [])
+args = parser.parse_args()
+
+ssh_args = f"-o IdentitiesOnly=yes -F /dev/null -i {args.identity_file}"
+
+commands = {
+ "prosody": [
+ "sudo chmod 640 ~/*.crt ~/*.key",
+ "sudo mv ~/*.crt ~/*.key /etc/prosody/certs",
+ "sudo chown -R root:prosody /etc/prosody/certs",
+ "sudo service nginx restart",
+ "sudo service prosody restart",
+ ],
+ "forgejo": [
+ "sudo chown root:root ~/*.crt ~/*.key",
+ "sudo mv ~/*.crt ~/*.key /etc/nginx/ssl/",
+ "sudo service forgejo restart",
+ "sudo service nginx restart",
+ ],
+}
+
+possible_services = {
+ "prosody": next(iter(args.prosody), None),
+ "forgejo": next(iter(args.forgejo), None),
+}
+services = dict(filter(lambda service: service[1] is not None, possible_services.items()))
+files_to_copy = {os.environ["LEGO_CERT_PATH"], os.environ["LEGO_CERT_KEY_PATH"]}
+
+def scp_commands(files: set[str], host:str) -> list[str]:
+ return [f"scp {ssh_args} {' '.join(files)} {host}:~"]
+
+def ssh_commands(service: str, host: str) -> list[str]:
+ return list(map(lambda command: f"ssh {ssh_args} -tt {host} '{command}'", commands[service]))
+
+for service, host in services.items():
+ commands_to_run = itertools.chain(scp_commands(files_to_copy, host), ssh_commands(service, host))
+
+ for command in commands_to_run:
+ print(command)
+ subprocess.run(command, shell=True)